diff --git a/ScriptCore/StyleChecker/StyleChecker.cs b/ScriptCore/StyleChecker/StyleChecker.cs index 70a41a6..d9f884f 100644 --- a/ScriptCore/StyleChecker/StyleChecker.cs +++ b/ScriptCore/StyleChecker/StyleChecker.cs @@ -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"; diff --git a/ScriptCoreGenerator/StyleCheckers/CatchUnmanagedCallersOnlyAnalyzer.cs b/ScriptCoreGenerator/StyleCheckers/CatchUnmanagedCallersOnlyAnalyzer.cs index 606d1fb..69f67fa 100644 --- a/ScriptCoreGenerator/StyleCheckers/CatchUnmanagedCallersOnlyAnalyzer.cs +++ b/ScriptCoreGenerator/StyleCheckers/CatchUnmanagedCallersOnlyAnalyzer.cs @@ -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) {