Skip to content

Commit

Permalink
Fix a bug where AvoidPositionalParameter is raised based on number of…
Browse files Browse the repository at this point in the history
… total arguments rather than positional arguments
  • Loading branch information
Quoc Truong committed Dec 16, 2015
1 parent 51f9d93 commit c14b5f9
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 c14b5f9

Please sign in to comment.