Skip to content

Commit a0a84c1

Browse files
author
Kapil Borle
committed
Add extension method get supportsshouldprocess attribute ast
1 parent 489938a commit a0a84c1

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

Engine/Extensions.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public static IEnumerable<string> GetLines(this string text)
1919
/// </summary>
2020
public static Range ToRange(this IScriptExtent extent)
2121
{
22-
return new Range(
23-
extent.StartLineNumber,
24-
extent.StartColumnNumber,
25-
extent.EndLineNumber,
26-
extent.EndColumnNumber);
22+
return new Range(
23+
extent.StartLineNumber,
24+
extent.StartColumnNumber,
25+
extent.EndLineNumber,
26+
extent.EndColumnNumber);
2727
}
2828

2929
public static ParameterAst[] GetParameterAsts(
@@ -59,7 +59,7 @@ public static AttributeAst GetCmdletBindingAttributeAst(this ParamBlockAst param
5959

6060
foreach (var attributeAst in attributeAsts)
6161
{
62-
if (attributeAst != null && attributeAst.IsCmdletBindingAttributeAst())
62+
if (attributeAst != null && attributeAst.IsCmdletBindingAttributeAst())
6363
{
6464
return attributeAst;
6565
}
@@ -72,5 +72,27 @@ public static bool IsCmdletBindingAttributeAst(this AttributeAst attributeAst)
7272
{
7373
return attributeAst.TypeName.GetReflectionAttributeType() == typeof(CmdletBindingAttribute);
7474
}
75+
76+
public static NamedAttributeArgumentAst GetSupportsShouldProcessAst(this AttributeAst attributeAst)
77+
{
78+
if (!attributeAst.IsCmdletBindingAttributeAst()
79+
|| attributeAst.NamedArguments == null)
80+
{
81+
return null;
82+
}
83+
84+
foreach (var namedAttrAst in attributeAst.NamedArguments)
85+
{
86+
if (namedAttrAst != null
87+
&& namedAttrAst.ArgumentName.Equals(
88+
"SupportsShouldProcess",
89+
StringComparison.OrdinalIgnoreCase))
90+
{
91+
return namedAttrAst;
92+
}
93+
}
94+
95+
return null;
96+
}
7597
}
7698
}

rules/UseSupportsShouldProcess.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,12 @@ private List<CorrectionExtent> GetCorrections(
137137
// check if it has cmdletbinding attribute
138138
if (TryGetCmdletBindingAttribute(paramBlockAst, out attributeAst))
139139
{
140-
if (!attributeAst.NamedArguments.Any(
141-
x => x.ArgumentName.Equals("supportsshouldprocess",
142-
StringComparison.OrdinalIgnoreCase)))
140+
NamedAttributeArgumentAst shouldProcessAst = attributeAst.GetSupportsShouldProcessAst();
141+
if (shouldProcessAst != null)
142+
{
143+
144+
}
145+
else
143146
{
144147
// add supportsshouldprocess to the attribute
145148
correctionExtents.Add(GetCorrectionToAddShouldProcess(attributeAst));

0 commit comments

Comments
 (0)