Skip to content

Add documentation to all rules supporting a custom suppression target - #2225

Open
Samuel D. Leslie (ralish) wants to merge 1 commit into
PowerShell:mainfrom
ralish:update-rule-doc-suppressions
Open

Samuel D. Leslie (ralish) wants to merge 1 commit into
PowerShell:mainfrom
ralish:update-rule-doc-suppressions

Conversation

@ralish

Copy link
Copy Markdown

PR Summary

A subset of PSScriptAnalyzer rules support customising a suppression so that it only applies to a specific target. This is performed through the second argument to the SuppressMessageAttribute constructor, which is otherwise an empty string to apply the rule globally within its scope.

This PR adds documentation to all rules which support customising the target of the suppression, which until now was largely undocumented.

PR Checklist

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The compatible-types guidance omits suppressible static fields and events.

1 open finding
What changed in this PR

Adds rule-specific documentation for custom SuppressMessageAttribute targets.

Changes:

  • Documents global and targeted suppression syntax.
  • Updates examples and suppression-guide links.
File Description
docs/​Rules/​UseSingularNouns.md Documents function-targeted suppression.
docs/​Rules/​UseSingleValueFromPipelineParameter.md Documents parameter-set suppression.
docs/​Rules/​UseProcessBlockForPipelineCommand.md Documents parameter-targeted suppression.
docs/​Rules/​UseDeclaredVarsMoreThanAssignments.md Documents variable-targeted suppression.
docs/​Rules/​UseCorrectCasing.md Documents casing-diagnostic targets.
docs/​Rules/​UseCompatibleTypes.md Documents type-member suppression.
docs/​Rules/​ReviewUnusedParameter.md Documents parameter-targeted suppression.
docs/​Rules/​MissingTryBlock.md Documents keyword-targeted suppression.
docs/​Rules/​InvalidMultiDotValue.md Documents value-targeted suppression.
docs/​Rules/​AvoidUsingPositionalParameters.md Documents command-targeted suppression.
docs/​Rules/​AvoidUsingPlainTextForPassword.md Documents parameter-targeted suppression.
docs/​Rules/​AvoidUsingConvertToSecureStringWithPlainText.md Documents command-targeted suppression.
docs/​Rules/​AvoidUsingComputerNameHardcoded.md Documents command-targeted suppression.
docs/​Rules/​AvoidUsingCmdletAliases.md Documents alias-targeted suppression.
docs/​Rules/​AvoidUsingBrokenHashAlgorithms.md Documents command-targeted suppression.
docs/​Rules/​AvoidUsingAllowUnencryptedAuthentication.md Documents command-targeted suppression.
docs/​Rules/​AvoidNullOrEmptyHelpMessageAttribute.md Documents parameter-targeted suppression.
docs/​Rules/​AvoidGlobalVars.md Documents scoped-variable suppression.
docs/​Rules/​AvoidGlobalFunctions.md Documents scoped-function suppression.
docs/​Rules/​AvoidDynamicallyCreatingVariableNames.md Documents dynamic-name suppression.
docs/​Rules/​AvoidDefaultValueForMandatoryParameter.md Documents parameter-targeted suppression.
docs/​Rules/​AvoidAssignmentToAutomaticVariable.md Documents variable-targeted suppression.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/Rules/UseCompatibleTypes.md Outdated
A subset of PSScriptAnalyzer rules support customising a suppression so
that it only applies to a specific target. This is performed through the
second argument to the `SuppressMessageAttribute` constructor, which is
otherwise an empty string to apply the rule globally within its scope.

This commit adds documentation to all rules which support customising
the target of the suppression, which until now was largely undocumented.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The documentation matches existing suppression behavior, resolves the prior feedback, and has no identified blocking issues.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for trying to improve it but I don't like the duplication. I think there is a general suppression section here that we could maybe improve and optionally reference

@ralish

Copy link
Copy Markdown
Author

Christoph Bergmeister (@bergmeister) Perhaps the leading content under each suppression section should be removed?

As with other rules, you can suppress this rule by adding a suppression attribute to the param block of a function or script. An empty string as the second argument suppresses every violation of the rule in that scope.

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('<RuleName>', '')]

Removing that would condense each added suppression Markdown section to only the information unique to that rule, omitting the general "how to suppress a rule" information.

The intent of the PR is to document the rules which have support for additional granularity in their suppression, as right now that's not documented anywhere. Do you have any suggestion on how best to document the information?

Thanks!

@bergmeister

Copy link
Copy Markdown
Collaborator

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants