Improved style checker

This commit is contained in:
Simon Lübeß
2025-08-08 19:03:31 +02:00
parent d156618453
commit bf03e99e4a
2 changed files with 9 additions and 10 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ using Microsoft.CodeAnalysis.Diagnostics;
namespace GlitchyEngine.StyleChecker;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
//[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class StyleChecker : DiagnosticAnalyzer
{
public const string DiagnosticId = "MakeConst2";
@@ -66,14 +66,7 @@ public class CatchUnmanagedCallersOnlyAnalyzer : DiagnosticAnalyzer
if (method.Body is not null)
{
// Check if the outer most statement is a try-catch block.
var tryStatement = method.Body.Statements.FirstOrDefault(s => s is TryStatementSyntax) as TryStatementSyntax;
if (tryStatement is null)
{
// If there is no try-catch block, report a diagnostic.
ReportDiagnostic();
return;
}
else
if (method.Body.Statements.FirstOrDefault() is TryStatementSyntax tryStatement)
{
// Check if the try block has a catch clause.
if (tryStatement.Catches.Count == 0)
@@ -81,7 +74,7 @@ public class CatchUnmanagedCallersOnlyAnalyzer : DiagnosticAnalyzer
ReportDiagnostic();
return;
}
// Report a diagnostic if there is no catch block that catches System.Exception.
if (tryStatement.Catches.All(c =>
{
@@ -98,6 +91,12 @@ public class CatchUnmanagedCallersOnlyAnalyzer : DiagnosticAnalyzer
return;
}
}
else
{
// If there is no try-catch block, report a diagnostic.
ReportDiagnostic();
return;
}
}
else if (method.ExpressionBody is not null)
{