Fix SuppressMessage CustomRule by HeyItsGilbert · Pull Request #2142 · PowerShell/PSScriptAnalyzer
added 2 commits
Problem: SuppressMessageAttribute failed when using named arguments for
RuleSuppressionID. Users could not use syntax like:
[SuppressMessage("RuleName", RuleSuppressionId="MyId")]
Root Cause: In RuleSuppression.cs, the named argument parser had two bugs:
1. Checked if RuleName was set instead of RuleSuppressionID
2. Assigned the value to RuleName instead of RuleSuppressionID
This broke selective rule suppression for custom rules.
Solution:
- Fixed conflict check to validate RuleSuppressionID instead of RuleName
- Fixed assignment to set RuleSuppressionID instead of RuleName
- Added comprehensive tests for named argument syntax
- Minor formatting improvements
Now both syntaxes work correctly:
[SuppressMessage("Rule", RuleSuppressionId="Id", Scope="Function")]
[SuppressMessage("Rule", "Id", Scope="Function")]
* Implemented a test case to validate the functionality of custom rules with targeted suppression. * The test recreates the scenario from GitHub issue PowerShell#1686, ensuring that `RuleSuppressionID` works correctly with named arguments. * Verified that violations are suppressed as expected based on the defined rules.
Copilot AI review requested due to automatic review settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters