Skip to content

Commit 401b195

Browse files
committed
Code cleanup
1 parent b60f00d commit 401b195

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

Engine/Helper.cs

+5-15
Original file line numberDiff line numberDiff line change
@@ -631,30 +631,20 @@ public bool PositionalParameterUsed(CommandAst cmdAst, bool moreThanTwoPositiona
631631

632632
// Because of the way we count, we will also count the cmdlet as an argument so we have to -1
633633
int argumentsWithoutProcedingParameters = -1;
634-
bool parameterPreceding = false;
635634

636-
foreach (CommandElementAst ceAst in cmdAst.CommandElements)
637-
{
638-
var cmdParamAst = ceAst as CommandParameterAst;
639-
if (cmdParamAst != null)
640-
{
641-
parameterPreceding = true;
642-
} else
635+
var commandElementCollection = cmdAst.CommandElements;
636+
for (int i = 0; i < commandElementCollection.Count(); i++) {
637+
if (!(commandElementCollection[i] is CommandParameterAst) && (i ==0 || !(commandElementCollection[i-1] is CommandParameterAst)))
643638
{
644-
if (!parameterPreceding)
645-
{
646-
argumentsWithoutProcedingParameters += 1;
647-
}
648-
parameterPreceding = false;
639+
argumentsWithoutProcedingParameters++;
649640
}
650641
}
651642

652643
// if not the first element in a pipeline, increase the number of arguments by 1
653644
PipelineAst parent = cmdAst.Parent as PipelineAst;
654-
655645
if (parent != null && parent.PipelineElements.Count > 1 && parent.PipelineElements[0] != cmdAst)
656646
{
657-
argumentsWithoutProcedingParameters += 1;
647+
argumentsWithoutProcedingParameters++;
658648
}
659649

660650
return moreThanTwoPositional ? argumentsWithoutProcedingParameters > 2 : argumentsWithoutProcedingParameters > 0;

0 commit comments

Comments
 (0)