Skip to content

Commit

Permalink
Merge pull request #508 from StefanMaron/development
Browse files Browse the repository at this point in the history
Remove need for try/catch for LC0003
  • Loading branch information
Arthurvdv authored Jan 12, 2024
2 parents 6edac70 + 423d69b commit b9fe905
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions Design/Rule0003DoNotUseObjectIDsInVariablesOrProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BusinessCentral.LinterCop.Design
[DiagnosticAnalyzer]
public class Rule0003DoNotUseObjectIDsInVariablesOrProperties : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0003DoNotUseObjectIDsInVariablesOrProperties, DiagnosticDescriptors.Rule0005VariableCasingShouldNotDifferFromDeclaration, DiagnosticDescriptors.Rule0000ErrorInRule);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0003DoNotUseObjectIDsInVariablesOrProperties, DiagnosticDescriptors.Rule0005VariableCasingShouldNotDifferFromDeclaration);

public override void Initialize(AnalysisContext context)
{
Expand Down Expand Up @@ -80,7 +80,7 @@ private void CheckForObjectIDsInVariablesOrProperties(SyntaxNodeAnalysisContext
{
if (parameter.ParameterType.GetNavTypeKindSafe() == NavTypeKind.DotNet) continue;

if (ctx.Node.GetLocation().SourceSpan.End == parameter.DeclaringSyntaxReference.GetSyntax(CancellationToken.None).Span.End)
if (ctx.Node.GetLocation().SourceSpan.End == parameter.DeclaringSyntaxReference.GetSyntax(ctx.CancellationToken).Span.End)
{
if (parameter.ParameterType.GetNavTypeKindSafe() == NavTypeKind.Array)
correctName = ((IArrayTypeSymbol)parameter.ParameterType).ElementType.Name.ToString();
Expand All @@ -94,25 +94,18 @@ private void CheckForObjectIDsInVariablesOrProperties(SyntaxNodeAnalysisContext
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0005VariableCasingShouldNotDifferFromDeclaration, ctx.Node.GetLocation(), new object[] { correctName, "" }));
}
}
try
{
IReturnValueSymbol returnValue = method.ReturnValueSymbol;
if (returnValue == null || returnValue.ReturnType.GetNavTypeKindSafe() == NavTypeKind.DotNet) return;
IReturnValueSymbol returnValue = method.ReturnValueSymbol;
if (returnValue?.DeclaringSyntaxReference == null || returnValue.ReturnType.GetNavTypeKindSafe() == NavTypeKind.DotNet) return;

if (ctx.Node.GetLocation().SourceSpan.End == returnValue.DeclaringSyntaxReference.GetSyntax(CancellationToken.None).Span.End)
{
correctName = returnValue.ReturnType.Name;
if (ctx.Node.GetLocation().SourceSpan.End == returnValue.DeclaringSyntaxReference.GetSyntax(ctx.CancellationToken).Span.End)
{
correctName = returnValue.ReturnType.Name;

if (ctx.Node.GetLastToken().ToString().Trim('"').ToUpper() != correctName.ToUpper())
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0003DoNotUseObjectIDsInVariablesOrProperties, ctx.Node.GetLocation(), new object[] { ctx.Node.ToString().Trim('"'), correctName }));
if (ctx.Node.GetLastToken().ToString().Trim('"').ToUpper() != correctName.ToUpper())
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0003DoNotUseObjectIDsInVariablesOrProperties, ctx.Node.GetLocation(), new object[] { ctx.Node.ToString().Trim('"'), correctName }));

if (ctx.Node.GetLastToken().ToString().Trim('"') != correctName)
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0005VariableCasingShouldNotDifferFromDeclaration, ctx.Node.GetLocation(), new object[] { correctName, "" }));
}
}
catch (NullReferenceException)
{
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0000ErrorInRule, ctx.Node.GetLocation(), new Object[] { "Rule0003/Rule0005", "NullReferenceException", "" }));
if (ctx.Node.GetLastToken().ToString().Trim('"') != correctName)
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0005VariableCasingShouldNotDifferFromDeclaration, ctx.Node.GetLocation(), new object[] { correctName, "" }));
}
}
}
Expand Down

0 comments on commit b9fe905

Please sign in to comment.