Skip to content

Commit

Permalink
Remove need for try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthurvdv committed Jan 12, 2024
1 parent 1f9165a commit fdcc76f
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions Design/Rule0003DoNotUseObjectIDsInVariablesOrProperties.cs
Original file line number Diff line number Diff line change
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 fdcc76f

Please sign in to comment.