New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run all analyzers even when a fixer isn't present #723
Conversation
|
||
# IDE0073: File header | ||
dotnet_diagnostic.IDE0073.severity = warning | ||
file_header_template = Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some of the goodness from Roslyn's .editorconfig
// For example, 'dotnet_diagnostic.CA1000.severity = error' | ||
if (compilation.Options.SpecificDiagnosticOptions.ContainsKey(descriptor.Id) || | ||
tree.DiagnosticOptions.ContainsKey(descriptor.Id)) | ||
if (tree.DiagnosticOptions.TryGetValue(descriptor.Id, out severity)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were not returning the severity from DiagnosticOptions causing some analyzers to not be run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this is why we need a test for this :(
|
||
public AnalyzerRunner(bool includeCompilerDiagnostics) | ||
{ | ||
_includeComplilerDiagnostics = includeCompilerDiagnostics; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should open up the possibility of running fixers that have no analyzer because they work against compiler diagnostics.
src/CodeFormatter.cs
Outdated
new AnalyzerFormatter(Resources.Code_Style, new RoslynCodeStyleAnalyzerFinder(), new AnalyzerRunner(), new SolutionCodeFixApplier()), | ||
new AnalyzerFormatter(Resources.Analyzer_Reference, new AnalyzerReferenceAnalyzerFinder(), new AnalyzerRunner(), new SolutionCodeFixApplier()), | ||
new AnalyzerFormatter(Resources.Code_Style, new CodeStyleInformationProvider(), new AnalyzerRunner(includeCompilerDiagnostics: true), new SolutionCodeFixApplier()), | ||
new AnalyzerFormatter(Resources.Analyzer_Reference, new AnalyzerReferenceInformationProvider(), new AnalyzerRunner(includeCompilerDiagnostics: false), new SolutionCodeFixApplier()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly we should always be including compiler diagnostics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I think we should play it safe and always generate compiler diagnostics.
|
||
static ImmutableDictionary<string, ImmutableArray<DiagnosticAnalyzer>> CreateAnalyzerMap( | ||
ImmutableArray<string> diagnosticIds, | ||
ImmutableArray<DiagnosticAnalyzer> analyzers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like we use an inconsistent wrapping style. Which one do we prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this one because it doesn't change when things are renamed/refactored.
{ | ||
var analyzers = analyzersById[diagnosticId]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we should try to get the value from the dictionary? Isn't it expected that we would not find entries for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, the ToImmutableArray
on an empty enumerable will mean that we should always have an empty immutable array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run all analyzers even when a fixer isn't present
This builds on the work and refactoring done in #720