Prevent duplicate rule ID suppression errors in `-Fix` and DSC scenarios (#2181)
* Enhance suppression error handling in ScriptAnalyzer and add tests for unapplied suppression errors
* Skip new -Fix suppression test under Library Usage harness
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).
* Add copilot review suggestions
---------
Co-authored-by: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> L
Liam Peters committed
940024a12dfc1f9240984104aaab8fd38c195817
Parent: d97ddd4
Committed by GitHub <noreply@github.com>
on 5/7/2026, 8:48:51 PM