Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ x86/
*.class
*.log
.vscode/


#Ignore vscode AI rules
.github/instructions/codacy.instructions.md
10 changes: 9 additions & 1 deletion src/Analyzer/CodeAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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").Project;

var compilation = await project.GetCompilationAsync(cancellationToken);

// Parallelize diagnostics fetching
var diagnostics = await diagnosticsRunner.GetDiagnostics(compilation, cancellationToken);
Expand Down
3 changes: 1 addition & 2 deletions src/Analyzer/Runner/DiagnosticsRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public Task<ImmutableArray<Diagnostic>> GetDiagnostics(Compilation compilation,
var modifiedCompilation = compilation.WithOptions(compilationOptions);
var compilationWithAnalyzer = modifiedCompilation.WithAnalyzers(
diagnosticsAnalyzers,
options,
cancellationToken);
options);

return compilationWithAnalyzer.GetAnalyzerDiagnosticsAsync(cancellationToken);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Analyzer/Utilities/RuleFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public IEnumerable<Type> GetParameterlessAnalyzerTypes()

public static bool IsParameterized(Type analyzerType)
{
return analyzerType.GetProperties()
.Any(p => p.GetCustomAttributes<RuleParameterAttribute>().Any());
return Array.Exists(analyzerType.GetProperties(),
p => p.GetCustomAttributes<RuleParameterAttribute>().Any());
}

public IEnumerable<Type> GetAnalyzerTypes()
Expand Down