Skip to content

Commit 956fcde

Browse files
committed
Trigger AvoidPositionalParameters rule for function defined and called inside a sript given as argument to Script Analyzer.
1 parent 29f5017 commit 956fcde

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Engine/Helper.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ public bool IsCmdlet(CommandAst cmdAst) {
620620
/// Given a commandast, checks whether positional parameters are used or not.
621621
/// </summary>
622622
/// <param name="cmdAst"></param>
623-
/// <param name="moreThanTwoPositional">only return true if more than three positional parameters are used</param>
623+
/// <param name="moreThanTwoPositional">only return true if more than two positional parameters are used</param>
624624
/// <returns></returns>
625625
public bool PositionalParameterUsed(CommandAst cmdAst, bool moreThanTwoPositional = false)
626626
{
@@ -629,13 +629,18 @@ public bool PositionalParameterUsed(CommandAst cmdAst, bool moreThanTwoPositiona
629629
return false;
630630
}
631631

632+
<<<<<<< 29f5017120de0ccf4c9737ca8a89d50ee66b63a1
633+
=======
634+
int parameters = 0;
635+
>>>>>>> Trigger AvoidPositionalParameters rule for function defined and called inside a sript given as argument to Script Analyzer.
632636
// Because of the way we count, we will also count the cmdlet as an argument so we have to -1
633637
int argumentsWithoutProcedingParameters = -1;
634638
bool parameterPreceding = false;
635639

636640
foreach (CommandElementAst ceAst in cmdAst.CommandElements)
637641
{
638642
var cmdParamAst = ceAst as CommandParameterAst;
643+
<<<<<<< 29f5017120de0ccf4c9737ca8a89d50ee66b63a1
639644
if (cmdParamAst != null)
640645
{
641646
parameterPreceding = true;
@@ -646,6 +651,11 @@ public bool PositionalParameterUsed(CommandAst cmdAst, bool moreThanTwoPositiona
646651
argumentsWithoutProcedingParameters += 1;
647652
}
648653
parameterPreceding = false;
654+
=======
655+
if (cmdParamAst == null)
656+
{
657+
arguments += 1;
658+
>>>>>>> Trigger AvoidPositionalParameters rule for function defined and called inside a sript given as argument to Script Analyzer.
649659
}
650660
}
651661

Rules/UseCmdletCorrectly.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ private bool MandatoryParameterExists(CommandAst cmdAst)
129129
return true;
130130
}
131131

132+
<<<<<<< 29f5017120de0ccf4c9737ca8a89d50ee66b63a1
132133
if (mandParams.Count == 0 || (Helper.Instance.IsCmdlet(cmdAst) && Helper.Instance.PositionalParameterUsed(cmdAst)))
134+
=======
135+
if (mandParams.Count() == 0 || (Helper.Instance.IsCmdlet(cmdAst) && Helper.Instance.PositionalParameterUsed(cmdAst)))
136+
>>>>>>> Trigger AvoidPositionalParameters rule for function defined and called inside a sript given as argument to Script Analyzer.
133137
{
134138
returnValue = true;
135139
}

0 commit comments

Comments
 (0)