Skip to content

Commit

Permalink
Migrate S5773: Implement ShouldExecute (#7628)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Pohlmann authored Jul 20, 2023
1 parent 0b7202c commit 287465d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,31 @@ public sealed class RestrictDeserializedTypes : RestrictDeserializedTypesBase

protected override DiagnosticDescriptor Rule => S5773;

public override bool ShouldExecute() => true;
public override bool ShouldExecute()
{
var walker = new Walker();
walker.SafeVisit(Node);
return walker.Result;
}

private sealed class Walker : SafeCSharpSyntaxWalker
{
public bool Result { get; private set; }

public override void Visit(SyntaxNode node)
{
if (!Result)
{
base.Visit(node);
}
}

public override void VisitInvocationExpression(InvocationExpressionSyntax node) =>
Result = node.NameIs(nameof(IFormatter.Deserialize));

public override void VisitObjectCreationExpression(ObjectCreationExpressionSyntax node) =>
Result = node.Type.NameIs("LosFormatter");
}

protected override bool IsBindToTypeMethod(SyntaxNode methodDeclaration) =>
methodDeclaration is MethodDeclarationSyntax { Identifier.Text: nameof(SerializationBinder.BindToType), ParameterList.Parameters.Count: 2 } syntax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public abstract class RestrictDeserializedTypesBase : SymbolicRuleCheck
protected abstract bool ThrowsOrReturnsNull(SyntaxNode methodDeclaration);
protected abstract SyntaxToken GetIdentifier(SyntaxNode methodDeclaration);

protected override ProgramState PostProcessSimple(SymbolicContext context)
protected override ProgramState PreProcessSimple(SymbolicContext context)
{
var state = context.State;
var operation = context.Operation.Instance;
Expand Down

0 comments on commit 287465d

Please sign in to comment.