-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix-all to remove warning suppressions that have become unnecessary (nullability and pragma) #41574
Comments
Yes, i would far prefer this. I think it would make a ton of sense for roslyn to let you know when a suppression was no longer necessary. |
This was originally filed as #4262. We should write this an analyzer/code fix in the shared analyzers/code fixes layer: https://github.com/dotnet/roslyn/tree/master/src/Analyzers/Core, so that it light ups in the IDE as well as in our CodeStyle NuGet package, which allows users to reference the analyzer NuGet package and bump up the unnecessary suppressions to warning/error to break build. |
There was internal feature request for unused suppressions being implemented as an analyzer, that they can be configured to break build. Additionally, a FixAll operation to remove all of these would be super helpful. Marking for design review for next IDE meeting to get traction on this. |
@mavasani, don't forget the |
I have put more thought on this, and I think we can divide this into few separate feature requests:
(1) is pretty easy to implement as an analyzer in the IDE CodeStyle NuGet package, so it can be strongly enforced in the build, if desired. This also serves the internal feature request that we received. (2) can also be pretty easily implemented as an analyzer in the IDE CodeStyle NuGet package, so it can be strongly enforced in the build. (3) is actually pretty hard to implement as an analyzer, if at all possible. By definition, this feature depends on knowing all the analyzer diagnostics reported in a file/compilation, and our analyzer ecosystem does not permit any analyzer to depend on output of another analyzer. I think we should take the approach @jnm2 has taken and implement this as a command line tool, and try to get his work merged into Roslyn (can it be possibly merged in as an additional functionality for AnalyzerRunner?) Thoughts? |
@paulomorgado Any changes to SARIF error log would be an orthogonal feature request, that would need compiler changes and a compiler feature request. Possibly add this to #42489 or file a separate issue? |
@mavasani, this wouldn't be a change to the SARIF error log if this is a normal warning with an ID. Would it? |
I'm lost... what's SARIF? |
@jnm2 SARIF is an open source file format for code analysis/diagnostics issue log: https://sarifweb.azurewebsites.net/ roslyn/src/Compilers/Core/Portable/CommandLine/ErrorLogOptions.cs Lines 11 to 14 in e704ca6
By default, compiler generates SARIF error log file using v1 format, but there is a command line switch to use v2 format: roslyn/src/Compilers/CSharp/Portable/CSharpResources.resx Lines 4625 to 4629 in 45d9c60
|
The Roslyn compilers have a The implementation is here: https://github.com/dotnet/roslyn/blob/master/src/Compilers/Core/Portable/CommandLine/SarifErrorLogger.cs |
The CLI tool was motivated by the high number of suppressions of things that are not third-party analyzers. For third-party analyzers, what would be the prompt to tell you to dig out and run the CLI tool? All the value of (3) that I can see is in detecting and notifying that action may be desired. Couldn't (3) be implemented by having the analyzer driver report which suppressions have been unused at the time that all analyzers stop running? It doesn't need to be an analyzer to be a useful IDE experience. |
Yes, we can implement this as an IDE feature. We can create a special IDE diagnostic source that takes all third party analyzer diagnostics as input, and reports these special unnecessary suppression diagnostics which grey out suppressions. |
Please, don't make it just an IDE feature. That'd be very useful for other tooling (like code review tooling). |
We can possibly expose this as a public API from Workspaces/Features layer for other tools. |
As long as it's on the SARIF file, I'm fine with it. 😄 |
I don't know enough about what I'm saying, but both csc.exe and the IDE run analyzers. If the tracking of used and unused suppressions was done at the level of the analyzer driver/runner, wouldn't the analyzer driver be reporting the unused suppressions to both csc.exe and the IDE? |
@paulomorgado @jnm2 - both your suggestions are validate and independent suggestions for changes to core compiler (even the analyzer driver that runs in build is part of core compiler). Given there is a separate team who owns that feature space, I think we should move the feature (3) for unused suppressions of analyzer diagnostics + SARIF change requests to separate issues which can be triaged and implemented independently. Lets keep this issue for features that can be implemented in IDE layer + IDE team's CodeStyle NuGet package (using existing analyzer driver support) - which would be (1) and (2) from my comment above, and yes both of these will be supported in csc.exe and IDE |
We took this to a design review today.
|
Filed #44176
I put some more thought into this and I don't think this is possible to write as an IDE analyzer/fixer that can be enforced on build. Even if the core analyzer driver reports a hidden diagnostic for unnecessary suppression, this diagnostic cannot be consumed by any analyzer. Analyzers can only invoke core compiler APIs or hidden diagnostics reported by core compiler layer (such as unnecessary usings), but cannot rely on any other analyzer or output from analyzer driver. I believe this feature can only be implemented as a post-build tool OR an IDE-only feature.
|
UpdateWe added support for the following features in 16.7/16.8:
Pending features:
At this point, I am not sure if there is anything actionable work remaining in this issue. We can track any additional work/features with separate issues. I propose we close this issue now. |
This is exciting! Thanks for working on this! Closing sounds good to me. I'm interested in #25372 and can follow it there, and if someone is interested in build-time warnings they can open a new issue. |
Over time the codebases I've worked in have accumulated pragmas and now nullability warning suppressions as workarounds for limitations or bugs in Visual Studio's analyzers and third-party analyzers. There's no mechanism on the other side to bring it to my attention when the suppressions are no longer relevant because the analysis has been improved.
I knew that VS 16.5 was fixing several of things that I had added pragmas for years ago and improving nullability analysis, so I wrote https://github.com/jnm2/SuppressionCleanupTool. It initially served as means of querying where the suppressions were actually located, because it's not like I could simply search for the text
!
and find only the instances where it represented the nullability operator. Once it located each suppression, it became obvious that the tool could use Roslyn as the source of truth about whether each!
,= default!
, and#pragma
could be removed.It's currently a console app. I was considering making this a VSIX, maybe a dotnet global tool, maybe an analyzer + code fix. The problem with the tool not running in the context of VS is that it isn't referencing the same versions of Microsoft.CodeAnalysis.Features, so even as a console app it may need to let you dynamically resolve all Roslyn dependencies from vswhere or NuGet.
@jmarolf suggested that I request this tool to be part of Roslyn itself. Having it be built in would be preferable from my vantage point:
The only concern I have about running inside VS is that it might remove suppressions from a codebase that has users with older or newer versions of VS with a bug or analysis limitation that is not present in the version you used to remove the suppressions.
The text was updated successfully, but these errors were encountered: