Skip to content
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

Merged
merged 8 commits into from Jul 6, 2020

Conversation

JoeRobich
Copy link
Member

This builds on the work and refactoring done in #720


# 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.
Copy link
Member Author

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))
Copy link
Member Author

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.

Copy link
Contributor

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;
Copy link
Member Author

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.

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()),
Copy link
Member Author

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.

Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Member Author

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];
Copy link
Contributor

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?

Copy link
Contributor

@jmarolf jmarolf Jul 6, 2020

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

Copy link
Contributor

@jmarolf jmarolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@JoeRobich JoeRobich added the auto-merge bot-command label Jul 6, 2020
@JoeRobich JoeRobich merged commit ddcce23 into dotnet:master Jul 6, 2020
@JoeRobich JoeRobich deleted the run-all-analyzers branch March 5, 2021 21:02
vdurante pushed a commit to vdurante/format that referenced this pull request Feb 29, 2024
Run all analyzers even when a fixer isn't present
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge bot-command
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants