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

IDE0058 should offer excluded_symbol_names configuration #57297

Open
shuebner opened this issue Oct 21, 2021 · 7 comments
Open

IDE0058 should offer excluded_symbol_names configuration #57297

shuebner opened this issue Oct 21, 2021 · 7 comments

Comments

@shuebner
Copy link

Analyzer

Diagnostic ID: IDE0058

Describe the improvement

I would like to enable IDE0058 with warning severity.
However, that leads to a lot of useless warnings for any kind of builder, e. g. StringBuilder.
I would like to be able to exclude types like StringBuilder from IDE0058.

Describe suggestions on how to achieve the rule

Offer excluded_symbol_names configuration for IDE0058

Additional context

@mavasani
Copy link
Contributor

IDExxxx code style rules are implemented in Roslyn repo, moving..

@mavasani mavasani transferred this issue from dotnet/roslyn-analyzers Oct 21, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 21, 2021
@jinujoseph jinujoseph added Concept-Continuous Improvement Need Design Review The end user experience design needs to be reviewed and approved. and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 27, 2021
@sharwell
Copy link
Member

I'm a bit concerned that the option presented might not be sufficient to support enabling IDE0058 at warning severity. I'd be very interested in seeing a test performed (e.g. via a diagnostic suppressor) to try and validate how many false positives remain in real-world code bases after implementing this exclusion.

@jinujoseph jinujoseph added this to the Backlog milestone Oct 27, 2021
@sharwell
Copy link
Member

@shuebner Here's an example of a diagnostic suppressor we created to allow a rule (VSTHRD200) to be used in a context where it wasn't originally intended (microsoft/vs-threading#670):

https://github.com/dotnet/roslyn-analyzers/blob/d5f910ba4c4aa62a3e9017aba3e5e745c905f865/src/Roslyn.Diagnostics.Analyzers/Core/RelaxTestNamingSuppressor.cs

@shuebner
Copy link
Author

I'm a bit concerned that the option presented might not be sufficient to support enabling IDE0058 at warning severity. I'd be very interested in seeing a test performed (e.g. via a diagnostic suppressor) to try and validate how many false positives remain in real-world code bases after implementing this exclusion.

I am not following. At the extreme you would list all types on which IDE0058 reports in the current solution. No false positives remain. Then, when you ignore a return value from a new type, that is a new warning, i. e. we err on the safe side. If it is another false positive from a builder or fluent api, you add the type to excluded_symbol_names. I do not see the problem here.

I assume the suppressor was for scenarios where test classes are not in their own file system folder and can thus not have their own .editorconfig?
At first, I was thinking about writing a suppressor that would read a special IDE0058 setting from the .editorconfig, allowing me to specify types on which to suppress warnings. But then I saw that excluded_symbol_names existed and already does exactly that. Why introduce another independent mechanism like a suppressor when there is already an established, consistent mechanism for the use-case? excluded_symbol_names is already available for a plethora of rules. With documentation ID format it even uses a well-defined format that enables exclusion of types or even single methods on types. The only thing that may be missing (at least I did not see it documented) is the usage of wildcards in the documentation ID to e. g. exclude whole namespaces. So, why make up anything new?

@ggirard07
Copy link

@shuebner Here's an example of a diagnostic suppressor we created

Can you provide a bit more information about how this could be reused in any project to disable this rule (VSTHRD200) in this specific test context?
Are we supposed to copy/paste code directly in test assembly?
Or are we supposed to find which NuGet package this suppressor and enable it through editorconfig?

@shuebner
Copy link
Author

@ggirard07 before going down the diagnostic suppressor road, please be aware that diagnostic suppressors pretty much only work with the dotnet CLI and VS for Windows.
They are not supported by e. g. Rider, VS for Mac or VS Code, i. e. you will still get the warnings there.

@glen-84
Copy link

glen-84 commented Dec 12, 2023

Duplicate of #47832.

@CyrusNajmabadi CyrusNajmabadi removed the Need Design Review The end user experience design needs to be reviewed and approved. label Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Complete
Development

No branches or pull requests

7 participants