From a6b9d540148b2e3b4a7e224ad59b7ffceceee837 Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Mon, 26 Jan 2026 15:16:34 +0000 Subject: [PATCH 1/4] fix: tool crashes due to AD0001 --- .gitignore | 4 ++++ src/Analyzer/CodeAnalyzer.cs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fc347f42..4f6ae903 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,7 @@ x86/ *.class *.log .vscode/ + + +#Ignore vscode AI rules +.github/instructions/codacy.instructions.md diff --git a/src/Analyzer/CodeAnalyzer.cs b/src/Analyzer/CodeAnalyzer.cs index 97ed4184..a158439a 100644 --- a/src/Analyzer/CodeAnalyzer.cs +++ b/src/Analyzer/CodeAnalyzer.cs @@ -26,7 +26,7 @@ public class CodeAnalyzer : Codacy.Engine.Seed.CodeAnalyzer, IDisposable private readonly ImmutableArray availableAnalyzers; private readonly DiagnosticsRunner diagnosticsRunner; private readonly string tmpSonarLintFolder; - private static HashSet blacklist = new HashSet { "S1144", "S2325", "S2077" }; + private static HashSet blacklist = new HashSet { "S1144", "S2325", "S2077","AD0001" }; public static bool IsInBlacklist(string id) { From d97462fee074b0b1661a8a1375c5c339b8d831da Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Mon, 26 Jan 2026 17:03:21 +0000 Subject: [PATCH 2/4] add nowarn flag --- src/Analyzer/Analyzer.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Analyzer/Analyzer.csproj b/src/Analyzer/Analyzer.csproj index 63b98b28..74b53c4c 100644 --- a/src/Analyzer/Analyzer.csproj +++ b/src/Analyzer/Analyzer.csproj @@ -3,6 +3,7 @@ Exe net6 CodacyCSharp.Analyzer + $(NoWarn);AD0001 From b387bea5ee1114ea05cb5fd6cc2006a99a90ca6c Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Fri, 8 May 2026 14:42:17 +0100 Subject: [PATCH 3/4] improve NullReferenceException issues --- src/Analyzer/Analyzer.csproj | 1 - src/Analyzer/CodeAnalyzer.cs | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Analyzer/Analyzer.csproj b/src/Analyzer/Analyzer.csproj index 74b53c4c..63b98b28 100644 --- a/src/Analyzer/Analyzer.csproj +++ b/src/Analyzer/Analyzer.csproj @@ -3,7 +3,6 @@ Exe net6 CodacyCSharp.Analyzer - $(NoWarn);AD0001 diff --git a/src/Analyzer/CodeAnalyzer.cs b/src/Analyzer/CodeAnalyzer.cs index a158439a..8bf9c57d 100644 --- a/src/Analyzer/CodeAnalyzer.cs +++ b/src/Analyzer/CodeAnalyzer.cs @@ -26,7 +26,7 @@ public class CodeAnalyzer : Codacy.Engine.Seed.CodeAnalyzer, IDisposable private readonly ImmutableArray availableAnalyzers; private readonly DiagnosticsRunner diagnosticsRunner; private readonly string tmpSonarLintFolder; - private static HashSet blacklist = new HashSet { "S1144", "S2325", "S2077","AD0001" }; + private static HashSet blacklist = new HashSet { "S1144", "S2325", "S2077" }; public static bool IsInBlacklist(string id) { @@ -123,7 +123,15 @@ public async Task Analyze(string file, CancellationToken cancellationToken) try { var solution = CompilationHelper.GetSolutionFromFile(DefaultSourceFolder + file); - var compilation = await solution.Projects.First().GetCompilationAsync(); + var project = solution.Projects.First(); + + // FIX: Prevent SonarAnalyzer NullReferenceException + project = project.AddAnalyzerConfigDocument( + ".editorconfig", + Microsoft.CodeAnalysis.Text.SourceText.From("is_global = true\n"), + filePath: "/.editorconfig"); + + var compilation = await project.GetCompilationAsync(cancellationToken); // Parallelize diagnostics fetching var diagnostics = await diagnosticsRunner.GetDiagnostics(compilation, cancellationToken); From a50862345bfeaddef1ec2128199fe2bb22f742ad Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Fri, 8 May 2026 14:54:23 +0100 Subject: [PATCH 4/4] fix some code issues --- src/Analyzer/CodeAnalyzer.cs | 2 +- src/Analyzer/Runner/DiagnosticsRunner.cs | 3 +-- src/Analyzer/Utilities/RuleFinder.cs | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Analyzer/CodeAnalyzer.cs b/src/Analyzer/CodeAnalyzer.cs index 8bf9c57d..596048f4 100644 --- a/src/Analyzer/CodeAnalyzer.cs +++ b/src/Analyzer/CodeAnalyzer.cs @@ -129,7 +129,7 @@ public async Task Analyze(string file, CancellationToken cancellationToken) project = project.AddAnalyzerConfigDocument( ".editorconfig", Microsoft.CodeAnalysis.Text.SourceText.From("is_global = true\n"), - filePath: "/.editorconfig"); + filePath: "/.editorconfig").Project; var compilation = await project.GetCompilationAsync(cancellationToken); diff --git a/src/Analyzer/Runner/DiagnosticsRunner.cs b/src/Analyzer/Runner/DiagnosticsRunner.cs index 3b7488ea..477bb724 100644 --- a/src/Analyzer/Runner/DiagnosticsRunner.cs +++ b/src/Analyzer/Runner/DiagnosticsRunner.cs @@ -53,8 +53,7 @@ public Task> GetDiagnostics(Compilation compilation, var modifiedCompilation = compilation.WithOptions(compilationOptions); var compilationWithAnalyzer = modifiedCompilation.WithAnalyzers( diagnosticsAnalyzers, - options, - cancellationToken); + options); return compilationWithAnalyzer.GetAnalyzerDiagnosticsAsync(cancellationToken); } diff --git a/src/Analyzer/Utilities/RuleFinder.cs b/src/Analyzer/Utilities/RuleFinder.cs index d7545dec..46d254cf 100644 --- a/src/Analyzer/Utilities/RuleFinder.cs +++ b/src/Analyzer/Utilities/RuleFinder.cs @@ -40,8 +40,8 @@ public IEnumerable GetParameterlessAnalyzerTypes() public static bool IsParameterized(Type analyzerType) { - return analyzerType.GetProperties() - .Any(p => p.GetCustomAttributes().Any()); + return Array.Exists(analyzerType.GetProperties(), + p => p.GetCustomAttributes().Any()); } public IEnumerable GetAnalyzerTypes()