| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…r unapplied suppression errors
There was a problem hiding this comment.
Thanks for picking this up — the repro in #2177 was solid and this fix matches it cleanly.
For the -Fix case, threading emitSuppressionErrors: false through the Fix() loop's AnalyzeSyntaxTree / AnalyzeScriptDefinition calls is the right shape: every iteration inside the loop suppresses, the post-loop AnalyzeFile emits once, no duplicates. For the DSC case, swapping the second if to else if so the class-DSC and module-DSC handler branches are mutually exclusive is exactly the right minimal fix. Both regression tests pass locally for me.
LGTM — approving pending CI passing.
— Drafted by Copilot (Claude Opus 4.7)
Sorry, something went wrong.
The `Library Usage` describe block in `LibraryUsage.tests.ps1` (only
active on Windows PowerShell 5.1, since it's gated `-Skip:$IsCoreCLR`)
re-runs `RuleSuppression.tests.ps1` against a hand-rolled
`Invoke-ScriptAnalyzer` wrapper that drives the analyzer as a .NET
library. That wrapper plugs in `PesterTestOutputWriter`, whose
`WriteError` is intentionally a no-op:
public void WriteError(ErrorRecord error)
{
// We don't write errors to avoid misleading
// error messages in test output
}
So the unapplied-suppression `ErrorRecord` we now emit during the final
`-Fix` pass never reaches `-ErrorVariable`, and `$fixErr | Should
-HaveCount 1` fails with "Expected a collection with size 1, but got an
empty collection". The behaviour itself is correct - the assertion is
just unobservable through this test harness.
Mark the new `It` block `-Skip:$testingLibraryUsage`, matching the
existing pattern already used by the `Bad Rule Suppression` and
`External Rule Suppression` contexts in the same file for the same
reason. The regular pwsh and WinPS runs of `RuleSuppression.tests.ps1`
(which `[+]` in the failing CI log) continue to exercise the assertion.
The new `UseDSCResourceFunctions.tests.ps1` test isn't dot-sourced by
`LibraryUsage.tests.ps1`, so it doesn't need the same guard.
Drafted by Copilot (Claude Opus 4.7).
|
Christoph Bergmeister (@bergmeister) I'll need your review since the super stringent code review requirements now bar me from merging after having Claude fix the failing test in CI. |
Sorry, something went wrong.
Sure. Will look at this and others tomorrow |
Sorry, something went wrong.
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
This PR prevents duplicate “unapplied suppression” errors that can occur during -Fix reanalysis passes and in DSC scenarios where both class-based and module-layout DSC logic apply to the same file.
Changes:
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Tests/Rules/UseDSCResourceFunctions.tests.ps1 | Adds regression test ensuring DSC suppression errors aren’t duplicated when both DSC detection paths apply. |
| Tests/Engine/RuleSuppression.tests.ps1 | Adds regression test ensuring -Fix reanalysis doesn’t emit multiple unapplied suppression errors. |
| Engine/ScriptAnalyzer.cs | Introduces emitSuppressionErrors plumbing and makes DSC analysis branches mutually exclusive to prevent duplicate suppression errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| public List<DiagnosticRecord> AnalyzeScriptDefinition(string scriptDefinition, out ScriptBlockAst scriptAst, out Token[] scriptTokens, bool skipVariableAnalysis = false, bool emitSuppressionErrors = true) | ||
| { |
There was a problem hiding this comment.
I'm not sure how much of a real concern this is. While it's technically correct, I'm not sure anyone takes a package reference on PSScriptAnalyzer. PSES is the only tightly coupled .NET caller and that updates alongside PSSA.
These signatures have changed before (When adding skipVariable analysis) without shipping overloads.
But to appease the AI review gods, I've restored the original method signature and added an overload - there's no harm in doing so.
Sorry, something went wrong.
| bool skipVariableAnalysis = false, | ||
| bool emitSuppressionErrors = true) | ||
| { |
There was a problem hiding this comment.
I'm not sure how much of a real concern this is. While it's technically correct, I'm not sure anyone takes a package reference on PSScriptAnalyzer. PSES is the only tightly coupled .NET caller and that updates alongside PSSA.
These signatures have changed before (When adding skipVariable analysis) without shipping overloads.
But to appease the AI review gods, I've restored the original method signature and added an overload.
Sorry, something went wrong.
There was a problem hiding this comment.
The overload restoration in 0efd4876 is fine — EmitSuppressionErrors now preserves the old AnalyzeScriptDefinition and AnalyzeSyntaxTree signatures and forwards through to the new internal-bool form, which addresses the binary-compat concern without changing call-site shape. CI is green on all three platforms (run 25387220273). Re-affirming the approval — this is good to merge from my side.
Drafted by Copilot (Claude Sonnet 4.6)
Sorry, something went wrong.
|
We are all just appeasing the AI gods now aren't we 😆 |
Sorry, something went wrong.
|
Sorry, forgot. Looks good to me |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
Added regression tests covering these 2 scenarios.
Fixes #2177
PR Checklist