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

Update configure severity code fix for IDE code style diagnostics to use dotnet_diagnostic entries #47052

Merged
merged 3 commits into from
Aug 24, 2020

Conversation

mavasani
Copy link
Contributor

Implements changes to configure severity code fix as per #44201. The code fix now does the following for IDE code style diagnostics:

  1. Updates the last applicable existing code style option value based entries, i.e. "%option_name% = %option_value%:%severity%, to use the new severity. If no such entries are found, we do not add new code style option value based entries.
  2. Updates the last applicable existing severity based entries, i.e. dotnet_diagnostic.<%DiagnosticId%>.severity = %severity%, to use the new severity. If no such entries are found, we add a new dotnet_diagnostic based entry with new severity.

This ensures couple of things:

  1. Allow build enforcement of code style diagnostics as compiler only understands dotnet_diagnostic entries. In absence of these entries, compiler will not even execute the code style analyzers on build as these are hidden diagnostics by default.
  2. Consistency in severity configuration entries with third party analyzer diagnostics, which can only use dotnet_diagnostic entries.

Before
image

After (no existing entry)
image

After (with existing entry)
image

We have follow-up work planned to have some UX to allow viewing and configuring code style option values and severities, so the additional dotnet_diagnostic severity entries in the editorconfig file themselves will not be bothersome for majority of the users.

…use dotnet_diagnostic entries

Implements changes to configure severity code fix as per dotnet#44201. The code fix now does the following for IDE code style diagnostics:
1. Updates the last applicable existing code style option value based entries, i.e. `"%option_name% = %option_value%:%severity%`, to use the new severity. If no such entries are found, we do not add new code style option value based entries.
2. Updates the last applicable existing severity based entries, i.e. `dotnet_diagnostic.<%DiagnosticId%>.severity = %severity%`, to use the new severity. If no such entries are found, we add a new dotnet_diagnostic based entry with new severity.

This ensures couple of things:
1. Allow build enforcement of code style diagnostics as compiler only understands dotnet_diagnostic entries. In absence of these entries, compiler will not even execute the code style analyzers on build as these are hidden diagnostics by default.
2. Consistency in severity configuration entries with third party analyzer diagnostics, which can only use dotnet_diagnostic entries.

**Before**
![image](https://user-images.githubusercontent.com/10605811/90942638-72ac9280-e3cb-11ea-9abe-301de0d1dfa8.png)

**After**
![image](https://user-images.githubusercontent.com/10605811/90942562-26615280-e3cb-11ea-85d8-202bb7c0d01e.png)

**Existing entry**
![image](https://user-images.githubusercontent.com/10605811/90942745-f5355200-e3cb-11ea-9c1f-2e06956a05e7.png)

We have follow-up work planned to have some UX to allow viewing and configuring code style option values and severities, so the additional dotnet_diagnostic severity entries in the editorconfig file themselves will not be bothersome for majority of the users.
@mavasani mavasani added this to the 16.8.P3 milestone Aug 21, 2020
@@ -355,1652 +358,17 @@ public Customer()
}
}
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.cs]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There were quite a few redundant tests in this file as @jasonmalinowski has observed the last time he touched this file. I deleted some of these duplicates but github diff seems to have royally messed it up and shows me adding large number of new tests and deleting much larger set then were actually deleted. Maybe codeflow has a better diff here?

}
}

public class SilentConfigurationTests : CodeStyleOptionBasedSeverityConfigurationTests
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This class was not deleted, I just trimmed the number tests inside this class to a much smaller number :-(

@@ -68,6 +68,7 @@ private enum ConfigurationKind
private readonly bool _isPerLanguage;
private readonly Project _project;
private readonly CancellationToken _cancellationToken;
private readonly bool _addNewEntryIfNoExistingEntryFound;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only product file changed in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@allisonchou I would really appreciate your review on this file. Thanks.

Copy link
Contributor

@allisonchou allisonchou left a comment

Choose a reason for hiding this comment

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

The ConfigurationUpdater changes LGTM 💯

@mavasani
Copy link
Contributor Author

Thank you @allisonchou!

@mavasani mavasani merged commit d58b06b into dotnet:master Aug 24, 2020
@mavasani mavasani deleted the FixConfigureSeverityForIDEDiags branch August 24, 2020 23:18
@ghost ghost modified the milestones: 16.8.P3, Next Aug 24, 2020
@allisonchou allisonchou modified the milestones: Next, 16.8.P3 Aug 31, 2020
mavasani added a commit to mavasani/roslyn that referenced this pull request Oct 14, 2020
Contributes towards dotnet#44201

- All code style option editorconfig entries can now be specified as `option_name = option_value` without `:severity` suffix
- `Configure code style option` code fix will no longer add add `:severity` suffix for new entries. For fix that changes existing entries which have `:severity` suffix, it will retain the existing severity suffix. Note that `Configure severity` code fix was already switched to use `dotnet_diagnostic.RuleID.severity` entries for code style diagnostics in dotnet#47052.

Once we have the editorconfig UX to change code style option value and severity, we can safely deprecate the `:severity` suffix in option value syntax. All our UI gestures will use the `option_name = option_value` syntax for code style value changes and `dotnet_diagnostic.RuleID.severity = severity` syntax for severity changes and users do not need to deal with these manually editing or understanind these different syntaxes or mapping rule IDs to option names and vice versa for code styles.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants