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

Disable PSSA or supress all rules for **one** file without excluding path in settings.psd1? #2067

Open
o-l-a-v opened this issue Feb 28, 2025 · 2 comments

Comments

@o-l-a-v
Copy link

o-l-a-v commented Feb 28, 2025

^ These links either isn't relevant anymore (first one, it's moved to Discord, right?), or does not work (the two others)


Say I have a script I'm just using for inspiration, I have no plans of iterating and improving it.

We can use [Diagnostics.CodeAnalysis.SuppressMessageAttribute()] to supress one rule. We can not use wildcard ( [Diagnostics.CodeAnalysis.SuppressMessageAttribute('*','')] ) to suppress all rules, I've tried.

Is it possible to disable PSSA or suppress all rules for one script/file, from inside that file? I don't want to hardcode paths in global PSSA settings.

To get PSSA and VSCode "Problems" tab to stay quiet I now have all these in top of the script:

[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText','')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingInvokeExpression','')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Used to output text with color')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter','')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseApprovedVerbs','')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseLiteralInitializerForHashtable','')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions','')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]

This is with the following Microsoft maintained script btw.:

@o-l-a-v o-l-a-v changed the title Disable PSSA or supress all rules for **one** file Disable PSSA or supress all rules for **one** file without excluding path in settings.psd1? Feb 28, 2025
@bergmeister
Copy link
Collaborator

bergmeister commented Mar 12, 2025

Currently not possible but if we tweaked implementation to allow either of the two to just ignore all rules, this would be neat:

  • [Diagnostics.CodeAnalysis.SuppressMessageAttribute('', '')]
  • [Diagnostics.CodeAnalysis.SuppressMessageAttribute('*', '')]

Code for it is here, PRs are welcome :-)
https://github.com/PowerShell/PSScriptAnalyzer/blob/main/Engine/Generic/RuleSuppression.cs

@kilasuit
Copy link
Contributor

^ These links either isn't relevant anymore (first one, it's moved to Discord, right?), or does not work (the two others)

@o-l-a-v incase you didn't know

There is an active bridging system for most channels between both Slack & Discord that you can get an invite to either (or both) on https://poshcode.org or direct links
Slack -> https://aka.ms/psslack
Discord -> https://aka.ms/psdiscord

Also the Rule Docs link is now https://github.com/PowerShell/PSScriptAnalyzer/tree/main/docs/Rules

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