You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
$_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-gt0) { throw ... } # never trueif ($errors-gt0-or$warnings-gt0) { throw ... } # never true
Impact
Any project whose build relies on the Analyze task believes PSScriptAnalyzer is
gating its build, when in fact violations of any severity (including Error) pass.
Affects both the psake (psakeFile.ps1) and Invoke-Build (IB.tasks.ps1) task wrappers,
since both call Test-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.
Tests: Test-PSBuildScriptAnalysis #96 (adding unit tests for Test-PSBuildScriptAnalysis): a test that feeds the function a
result set containing an Error record and asserts it throws at SeverityThreshold = 'Error'
would have caught this and would guard against recurrence.
Summary
Test-PSBuildScriptAnalysiscounts analyzer findings by severity using$_Severity(an undefined variable) instead of
$_.Severity(the property). Every count istherefore always
0, so the function — and the psake/Invoke-BuildAnalyzetask thatcalls it — never throws, regardless of findings. PSScriptAnalyzer enforcement is
silently disabled for every consumer relying on the
Analyzetask.Affected code
PowerShellBuild/Public/Test-PSBuildScriptAnalysis.ps1:$_Severityis parsed as the variable$_Severity(which does not exist →$null), notas the
Severityproperty of the pipeline item$_.$null -eq 'Error'is$falseforevery record, so
.where({...})always returns an empty collection and.Countis0.The downstream gate is then dead code:
Impact
Analyzetask believes PSScriptAnalyzer isgating its build, when in fact violations of any severity (including
Error) pass.psakeFile.ps1) and Invoke-Build (IB.tasks.ps1) task wrappers,since both call
Test-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
mainbranch. Not version-specific.Reproduction
Or end to end: add a function guaranteed to raise an
Error-severity diagnostic, run theAnalyze/Testtask, and observe that the build still succeeds.Suggested fix
Reference the property, not a variable:
Related
Test-PSBuildScriptAnalysis): a test that feeds the function aresult set containing an
Errorrecord and asserts it throws atSeverityThreshold = 'Error'would have caught this and would guard against recurrence.