Skip to content

Filter Invoke-ScriptAnalyzer results by diagnostic severity - #2268

Open
Christoph Bergmeister (bergmeister) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-severity-filtering-issue
Open

Christoph Bergmeister (bergmeister) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-severity-filtering-issue

Conversation

Copilot AI commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Invoke-ScriptAnalyzer -Severity filtered rules by their configured severity instead of filtering the diagnostics those rules emitted. This could hide diagnostics whose severity differed from the rule’s severity, including errors from custom rules.

  • Filter diagnostics: Apply -Severity to emitted diagnostic records, including parse errors and suppressed records.
  • Run rules independently: Severity no longer determines which rules execute.

For example, -Severity Error now includes an Error diagnostic emitted by a custom rule configured as Warning:

Invoke-ScriptAnalyzer -ScriptDefinition 'Invoke-Something' `
    -CustomRulePath ./CustomRule.psm1 `
    -Severity Error

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix -Severity parameter to filter diagnostics correctly Filter Invoke-ScriptAnalyzer results by diagnostic severity Oct 27, 2026

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 severity-filter change lacks regression tests confirming correct filtering and suppression metadata preservation under both -SuppressedOnly and -IncludeSuppressed.

1 open issue
What changed in this PR

Updates Invoke-ScriptAnalyzer -Severity to filter emitted diagnostics rather than select which rules execute, aligning behavior with the documented contract and addressing #2156.

Changes:

  • Filters diagnostics by severity, including parse errors and suppressed records.
  • Adds a regression test for a custom rule whose diagnostic severity differs from its configured severity.
  • Clarifies the severity parameter’s source-code documentation.
File Description
Tests/​Engine/​CustomizedRule.tests.ps1 Tests custom-rule diagnostic severity filtering.
Engine/​ScriptAnalyzer.cs Moves severity filtering from rule selection to diagnostic output.
Engine/​Commands/​InvokeScriptAnalyzerCommand.cs Corrects the severity property’s documentation comment.

Review effort: Balanced

Comment thread Engine/ScriptAnalyzer.cs
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

Copilot AI commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

🟡 Changes recommended...

Added coverage for both suppression modes, severity filtering, and suppression metadata in 28e40a1.

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

No active review issues were identified for the change aligning severity filtering with its documented behavior.

1 open issue

Review effort: Balanced

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

No active review issues are recorded for the diagnostic-severity filtering change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

Invoke-ScriptAnalyzer -Severity filters rules rather than diagnostics

3 participants