Skip to content

Commit 9d59247

Browse files
author
Quoc Truong
committed
Merge pull request #406 from PowerShell/FixAvoidPositionalParameterBug
Fix AvoidPositionalParameter bug
2 parents 3485de5 + c14b5f9 commit 9d59247

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Engine/Helper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ public bool PositionalParameterUsed(CommandAst cmdAst, bool moreThanThreePositio
353353
arguments += 1;
354354
}
355355

356-
if (moreThanThreePositional && arguments < 3)
356+
// if we are only checking for 3 or more positional parameters, check that arguments < parameters + 3
357+
if (moreThanThreePositional && (arguments - parameters) < 3)
357358
{
358359
return false;
359360
}

Tests/Rules/AvoidPositionalParametersNoViolations.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ Get-Content Test
2020
Get-ChildItem Tests
2121
Write-Output "I don't want to use positional parameters"
2222
Split-Path "RandomPath" -Leaf
23-
Get-Process | ForEach-Object {Write-Host $_.name -foregroundcolor cyan}
23+
Get-Process | ForEach-Object {Write-Host $_.name -foregroundcolor cyan}
24+
25+
$srvc = Get-WmiObject Win32_Service -ComputerName $computername -Filter "name=""$service""" -Credential $credential

0 commit comments

Comments
 (0)