Skip to content

Conversation

@HeyItsGilbert
Copy link

PR Summary

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
  • Added tests based on repro case.
  • Minor formatting improvements

Now both syntaxes work correctly:
[SuppressMessage("Rule", RuleSuppressionId="Id", Scope="Function")]
[SuppressMessage("Rule", "Id", Scope="Function")]

Fixes #1686

PR Checklist

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 November 26, 2025 14:38
Copilot finished reviewing on behalf of HeyItsGilbert November 26, 2025 14:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug in the RuleSuppression attribute parser that prevented the use of named argument syntax for RuleSuppressionId. The bug caused [SuppressMessage("Rule", RuleSuppressionId="Id")] to fail, particularly affecting custom rules that use targeted suppression via RuleSuppressionID.

Key Changes:

  • Fixed the named argument parser to check and assign RuleSuppressionID instead of incorrectly checking/assigning RuleName
  • Added comprehensive test coverage for named argument syntax, mixed positional/named arguments, and custom rule scenarios
  • Minor formatting improvements to test file (consistent whitespace in script blocks and preprocessor directives)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Engine/Generic/RuleSuppression.cs Fixed two bugs in the named argument parser for RuleSuppressionID (lines 196, 201) and minor preprocessor directive formatting
Tests/Engine/RuleSuppression.tests.ps1 Added 3 new comprehensive tests for named argument syntax including custom rule scenario, plus consistent whitespace formatting improvements

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

RuleSuppressionId is not being honored for custom rule suppression

1 participant