GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix SuppressMessage CustomRule by HeyItsGilbert · Pull Request #2142 · PowerShell/PSScriptAnalyzer

Conversation

@HeyItsGilbert

@HeyItsGilbert Gilbert Sanchez (HeyItsGilbert) commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

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

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .cs, .ps1 and .psm1 files have the correct copyright header
  • Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Gilbert Sanchez (HeyItsGilbert) added 2 commits November 26, 2025 14:12
@HeyItsGilbert
Fix RuleSuppressionID not working with named arguments
b80a609
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")]
@HeyItsGilbert
test: ✨ Add test for custom rule suppression with RuleSuppressionID
8d33bf4
* 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
@HeyItsGilbert
Gilbert Sanchez (HeyItsGilbert) requested review from Andy Jordan (andyleejordan) and Christoph Bergmeister (bergmeister) as code owners November 26, 2025 14:38
Copilot started reviewing on behalf of Gilbert Sanchez (HeyItsGilbert) November 26, 2025 14:39
View session
Copilot finished reviewing on behalf of Gilbert Sanchez (HeyItsGilbert) November 26, 2025 14:41
Copilot AI reviewed Nov 26, 2025
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
bergmeister
Christoph Bergmeister (bergmeister) approved these changes Dec 2, 2025
View reviewed changes

@bergmeister Christoph Bergmeister (bergmeister) left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for taking the time for such a detailed fix and also adding tests to it. Basic code like this is unfortunately from initial days where the tool was just quickly coded up.
Happy as well Andy Jordan (@andyleejordan) ?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

HeyItsGilbert reacted with heart emoji
All reactions
  • ❤️ 1 reaction
andyleejordan
Andy Jordan (andyleejordan) approved these changes Dec 3, 2025
View reviewed changes

@andyleejordan Andy Jordan (andyleejordan) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Good fix! My guess is, if it ever worked in the first place, a refactor is probably what broke it given it was the wrong argument being checked. But who knows.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

HeyItsGilbert reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@andyleejordan
Andy Jordan (andyleejordan) merged commit 67ffb24 into PowerShell:main Dec 3, 2025
10 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@iRon7

iRon7 commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@bergmeister Christoph Bergmeister (bergmeister) bergmeister approved these changes
+1 more reviewer
@andyleejordan Andy Jordan (andyleejordan) andyleejordan approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

RuleSuppressionId is not being honored for custom rule suppression

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@HeyItsGilbert @iRon7 @andyleejordan @bergmeister
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.