diff --git a/Engine/Helper.cs b/Engine/Helper.cs index 9716db704..da5bbb890 100644 --- a/Engine/Helper.cs +++ b/Engine/Helper.cs @@ -249,8 +249,6 @@ public bool PositionalParameterUsed(CommandAst cmdAst) CommandInfo commandInfo = GetCommandInfo(GetCmdletNameFromAlias(cmdAst.GetCommandName())) ?? GetCommandInfo(cmdAst.GetCommandName()); IEnumerable switchParams = null; - IEnumerable scriptBlocks = null; - bool hasScriptBlockSet = false; if (HasSplattedVariable(cmdAst)) { @@ -262,15 +260,6 @@ public bool PositionalParameterUsed(CommandAst cmdAst) try { switchParams = commandInfo.Parameters.Values.Where(pm => pm.SwitchParameter); - scriptBlocks = commandInfo.ParameterSets; - foreach (CommandParameterSetInfo cmdParaset in scriptBlocks) - { - if (String.Equals(cmdParaset.Name, "ScriptBlockSet", StringComparison.OrdinalIgnoreCase)) - { - hasScriptBlockSet = true; - } - } - } catch (Exception) { @@ -284,8 +273,6 @@ public bool PositionalParameterUsed(CommandAst cmdAst) foreach (CommandElementAst ceAst in cmdAst.CommandElements) { - if (!hasScriptBlockSet) - { if (ceAst is CommandParameterAst) { // Skip if it's a switch parameter @@ -308,7 +295,7 @@ public bool PositionalParameterUsed(CommandAst cmdAst) { arguments += 1; } - } + } // if not the first element in a pipeline, increase the number of arguments by 1 diff --git a/Tests/Rules/AvoidPositionalParametersNoViolations.ps1 b/Tests/Rules/AvoidPositionalParametersNoViolations.ps1 index 5ae0bd222..41562ffd8 100644 --- a/Tests/Rules/AvoidPositionalParametersNoViolations.ps1 +++ b/Tests/Rules/AvoidPositionalParametersNoViolations.ps1 @@ -3,4 +3,5 @@ Get-ChildItem -Path "Tests" Clear-Host Split-Path -Path "Random" -leaf Get-Process | Where-Object {$_.handles -gt 200} -get-service-computername localhost | where {($_.status -eq "Running") -and ($_.CanStop -eq $true)} \ No newline at end of file +get-service-computername localhost | where {($_.status -eq "Running") -and ($_.CanStop -eq $true)} +1, 2, $null, 4 | ForEach-Object {"Hello"} \ No newline at end of file