Skip to content

Commit

Permalink
Merge pull request #406 from PowerShell/FixAvoidPositionalParameterBug
Browse files Browse the repository at this point in the history
Fix AvoidPositionalParameter bug
  • Loading branch information
Quoc Truong committed Dec 16, 2015
2 parents 3485de5 + c14b5f9 commit 9d59247
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Engine/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ public bool PositionalParameterUsed(CommandAst cmdAst, bool moreThanThreePositio
arguments += 1;
}

if (moreThanThreePositional && arguments < 3)
// if we are only checking for 3 or more positional parameters, check that arguments < parameters + 3
if (moreThanThreePositional && (arguments - parameters) < 3)
{
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion Tests/Rules/AvoidPositionalParametersNoViolations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ Get-Content Test
Get-ChildItem Tests
Write-Output "I don't want to use positional parameters"
Split-Path "RandomPath" -Leaf
Get-Process | ForEach-Object {Write-Host $_.name -foregroundcolor cyan}
Get-Process | ForEach-Object {Write-Host $_.name -foregroundcolor cyan}

$srvc = Get-WmiObject Win32_Service -ComputerName $computername -Filter "name=""$service""" -Credential $credential

0 comments on commit 9d59247

Please sign in to comment.