Skip to content

Commit

Permalink
Merge pull request #624 from StefanMaron/InvalidCastException
Browse files Browse the repository at this point in the history
Resolve InvalidCastException on rule0043
  • Loading branch information
Arthurvdv authored May 23, 2024
2 parents 250567a + 79c59d6 commit a7f1c56
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions Design/Rule0043SecretText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace BusinessCentral.LinterCop.Design
[DiagnosticAnalyzer]
public class Rule0043SecretText : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0043SecretText, DiagnosticDescriptors.Rule0000ErrorInRule);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0043SecretText);

private static readonly string authorization = "Authorization";

Expand Down Expand Up @@ -90,14 +90,7 @@ private void AnalyzeHttpObjects(OperationAnalysisContext ctx)
return;
}

try
{
if (!IsAuthorizationArgument(operation.Arguments[0])) return;
}
catch (InvalidCastException)
{
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0000ErrorInRule, ctx.Operation.Syntax.GetLocation(), new Object[] { "Rule0043", "InvalidCastException", "at Line 63" }));
}
if (!IsAuthorizationArgument(operation.Arguments[0])) return;

if (!IsArgumentOfTypeSecretText(operation.Arguments[1]))
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0043SecretText, ctx.Operation.Syntax.GetLocation()));
Expand All @@ -115,6 +108,7 @@ private static bool IsAuthorizationArgument(IArgument argument)
case SyntaxKind.LiteralExpression:
return SemanticFacts.IsSameName(argument.Value.ConstantValue.Value.ToString(), authorization);
case SyntaxKind.IdentifierName:
if (argument.Value.Kind != OperationKind.ConversionExpression) return false;
IOperation operand = ((IConversionExpression)argument.Value).Operand;
if (operand.GetSymbol().OriginalDefinition.GetTypeSymbol().GetNavTypeKindSafe() != NavTypeKind.Label) return false;
ILabelTypeSymbol label = (ILabelTypeSymbol)operand.GetSymbol().OriginalDefinition.GetTypeSymbol();
Expand Down

0 comments on commit a7f1c56

Please sign in to comment.