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

Rule for unused rule suppressions #1894

Open
iRon7 opened this issue Feb 21, 2023 · 1 comment
Open

Rule for unused rule suppressions #1894

iRon7 opened this issue Feb 21, 2023 · 1 comment

Comments

@iRon7
Copy link

iRon7 commented Feb 21, 2023

Currently there are quiet some reason to suppress a certain rule as e.g.:

  • Not be able to (easily) work around an issue
  • False positives

There are also a few reasons a rule suppression might get obsolete, e.g.:

  • The script issue gets resolved
    e.g. all the Write-Host cmdlet are been replaced which a different cmdlet
  • The script issue doesn't anymore apply
    e.g. a PSReviewUnusedParameter parameter get completely depreciated or a variable gets (also) used in scope
  • PSScriptAnalyzer update
    e.g. a false positive might get fixed in a newer version of PSScriptAnalyzer

In all the situations I would like to be warned that there is a Diagnostics.CodeAnalysis.SuppressMessageAttribute that is no longer required.

This will avoid a scenario were:

  • Someone resolves an analyzer issue (e.g. PSAvoidUsingWriteHost ) in a particular script but forgets to remove the SuppressMessageAttribute from the annotations
  • Someone else updates the same script but unseen reintroduces the analyzer issue (e.g. Write-Host ) again.
@ghost ghost added the Needs: Triage 🔍 label Feb 21, 2023
@iRon7 iRon7 changed the title Rule for useless rule suppressions Rule for unused rule suppressions Feb 21, 2023
@bergmeister
Copy link
Collaborator

Good idea, I wonder if this can be part of the command log in general because in theory it should be possible to annotate whether a suppression entry caused a suppression and if not call that out. A rule would need to make assumptions or reverse engineer the suppression logic, therefore I'd rather do this as part of the suppression logic itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants