From c14b5f940858055d048727cf90ce7ee4f311c752 Mon Sep 17 00:00:00 2001 From: Quoc Truong Date: Wed, 16 Dec 2015 12:23:39 -0800 Subject: [PATCH] Fix a bug where AvoidPositionalParameter is raised based on number of total arguments rather than positional arguments --- Engine/Helper.cs | 3 ++- Tests/Rules/AvoidPositionalParametersNoViolations.ps1 | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Engine/Helper.cs b/Engine/Helper.cs index 78e43dc2a..8fcae65f9 100644 --- a/Engine/Helper.cs +++ b/Engine/Helper.cs @@ -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; } diff --git a/Tests/Rules/AvoidPositionalParametersNoViolations.ps1 b/Tests/Rules/AvoidPositionalParametersNoViolations.ps1 index 1c3841846..9a5cc7d75 100644 --- a/Tests/Rules/AvoidPositionalParametersNoViolations.ps1 +++ b/Tests/Rules/AvoidPositionalParametersNoViolations.ps1 @@ -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} \ No newline at end of file +Get-Process | ForEach-Object {Write-Host $_.name -foregroundcolor cyan} + +$srvc = Get-WmiObject Win32_Service -ComputerName $computername -Filter "name=""$service""" -Credential $credential \ No newline at end of file