Repository navigation
Description
Summary
Test-PSBuildScriptAnalysis counts analyzer findings by severity using $_Severity
(an undefined variable) instead of $_.Severity (the property). Every count is
therefore always 0, so the function — and the psake/Invoke-Build Analyze task that
calls it — never throws, regardless of findings. PSScriptAnalyzer enforcement is
silently disabled for every consumer relying on the Analyze task.
Affected code
PowerShellBuild/Public/Test-PSBuildScriptAnalysis.ps1:
$errors = ($analysisResult.where({ $_Severity -eq 'Error' })).Count
$warnings = ($analysisResult.where({ $_Severity -eq 'Warning' })).Count
$infos = ($analysisResult.where({ $_Severity -eq 'Information' })).Count$_Severity is parsed as the variable $_Severity (which does not exist → $null), not
as the Severity property of the pipeline item $_. $null -eq 'Error' is $false for
every record, so .where({...}) always returns an empty collection and .Count is 0.
The downstream gate is then dead code:
if ($errors -gt 0) { throw ... } # never true
if ($errors -gt 0 -or $warnings -gt 0) { throw ... } # never trueImpact
- Any project whose build relies on the
Analyzetask believes PSScriptAnalyzer is
gating its build, when in fact violations of any severity (includingError) pass. - Affects both the psake (
psakeFile.ps1) and Invoke-Build (IB.tasks.ps1) task wrappers,
since both callTest-PSBuildScriptAnalysis.
Affected versions
Confirmed present in every published version on the PowerShell Gallery (0.1.0 through
0.8.0, the current latest) and on the main branch. Not version-specific.
Reproduction
$record = [pscustomobject]@{ Severity = 'Error' }
(@($record).Where({ $_Severity -eq 'Error' })).Count # => 0 (bug)
(@($record).Where({ $_.Severity -eq 'Error' })).Count # => 1 (correct)Or end to end: add a function guaranteed to raise an Error-severity diagnostic, run the
Analyze/Test task, and observe that the build still succeeds.
Suggested fix
Reference the property, not a variable:
$errors = ($analysisResult.where({ $_.Severity -eq 'Error' })).Count
$warnings = ($analysisResult.where({ $_.Severity -eq 'Warning' })).Count
$infos = ($analysisResult.where({ $_.Severity -eq 'Information' })).CountRelated
- Tests: Test-PSBuildScriptAnalysis #96 (adding unit tests for
Test-PSBuildScriptAnalysis): a test that feeds the function a
result set containing anErrorrecord and asserts it throws atSeverityThreshold = 'Error'
would have caught this and would guard against recurrence.
Activity
fix: enforce PSScriptAnalyzer in the build and drop the redundant lin…
fix: enforce PSScriptAnalyzer in the build and drop the redundant lin…
fix: enforce PSScriptAnalyzer in the build and drop the redundant lin…
fix: enforce PSScriptAnalyzer in the build and drop the redundant lin…
tablackburn commentedon Aug 20, 2026
Fixed by #143 (merged as
64b7207). Verified againstmain:grep -rn '_Severity' PowerShellBuild/returns no matches —Test-PSBuildScriptAnalysisnow reads$_.Severityand the severity gate fails the build as intended.The related gaps this bug was hiding —
ParseErrorfindings escaping every threshold, and the documented-but-rejected'Any'value — are tracked separately in #144.Closed during v1.0.0 route charting (#120).