Skip to content

Commit 0410d9e

Browse files
author
Kapil Borle
committed
Rename methods to get correction extent
1 parent dc091f1 commit 0410d9e

1 file changed

Lines changed: 13 additions & 28 deletions

File tree

rules/UseSupportsShouldProcess.cs

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ private List<DiagnosticRecord> FindViolations()
6868
continue;
6969
}
7070

71-
7271
// get paramterAsts and parameter block
7372
// then use get parameter on the parameterAsts
7473
var addsWhatIf = TryGetParameterAst(parameterAsts, "whatif", out whatIfIndex);
@@ -87,12 +86,10 @@ private List<DiagnosticRecord> FindViolations()
8786
// with null Text value, it crashes editorservices.
8887
if (addsWhatIf)
8988
{
90-
// mark the whatif parameter
9189
scriptExtent = whatIfParamAst.Extent;
9290
}
9391
else
9492
{
95-
// mark the confirm parameter
9693
scriptExtent = confirmParamAst.Extent;
9794
}
9895

@@ -135,34 +132,22 @@ private List<CorrectionExtent> GetCorrections(
135132
ParamBlockAst paramBlockAst,
136133
FunctionDefinitionAst funcDefnAst)
137134
{
138-
// we need to handle the following cases
139-
// - If a function has paramBlockAst
140-
// - if it has cmdletbinding
141-
// - if it has supportsshouldprocess
142-
// - else it doesn't have supportsshouldprocess
143-
// - else it does not have cmdlet binding
144-
// - else a function doesn't have paramBlockAst
145135
var filePath = funcDefnAst.Extent.File;
146136
var correctionExtents = new List<CorrectionExtent>();
147137

148-
// replace whatif/confirm extent starting with the last character of the previous parameter and ending with the last character of the whatif/confirm/parameter. This will take care of the trailing comma.
149-
// the next parameter
150-
// TODO Do not incrementally correct the text as it may lead to a situation in which a following
151-
// edits might try to modify edits that have already taken place.
152-
// A better approach is to gather all the edits and give them to the text edit class to handle.
153-
154138
if (paramBlockAst != null)
155139
{
156140
if (whatIfIndex != -1)
157141
{
158142
// TODO update method name to reflect its purpose.
159-
correctionExtents.Add(GetCorrectionExtent(whatIfIndex, parameterAsts));
143+
correctionExtents.Add(GetCorrectionToRemoveParam(whatIfIndex, parameterAsts));
160144
}
161145

162146
if (confirmIndex != -1)
163147
{
164-
correctionExtents.Add(GetCorrectionExtent(confirmIndex, parameterAsts));
148+
correctionExtents.Add(GetCorrectionToRemoveParam(confirmIndex, parameterAsts));
165149
}
150+
166151
AttributeAst attributeAst;
167152

168153
// check if it has cmdletbinding attribute
@@ -173,14 +158,14 @@ private List<CorrectionExtent> GetCorrections(
173158
StringComparison.OrdinalIgnoreCase)))
174159
{
175160
// add supportsshouldprocess to the attribute
176-
correctionExtents.Add(GetCorrectionExtent(attributeAst));
161+
correctionExtents.Add(GetCorrectionToAddShouldProcess(attributeAst));
177162
}
178163
}
179164
else
180165
{
181166
// has no cmdletbinding attribute
182167
// hence, add the attribute and supportsshouldprocess argument
183-
correctionExtents.Add(GetCorrectionExtent(paramBlockAst));
168+
correctionExtents.Add(GetCorrectionToAddParamBlock(paramBlockAst));
184169
}
185170
}
186171
else
@@ -189,11 +174,11 @@ private List<CorrectionExtent> GetCorrections(
189174
// remove the parameter list
190175
// and create an equivalent param block
191176
// add cmdletbinding attribute and add supportsshouldprocess to it.
192-
correctionExtents.Add(GetCorrectionExtentRemoveParams(funcDefnAst, ast, tokens));
193-
correctionExtents.Add(GetCorrectionExtentAddParamBlock(funcDefnAst, parameterAsts));
177+
correctionExtents.Add(GetCorrectionToRemoveFuncParamDecl(funcDefnAst, ast, tokens));
178+
correctionExtents.Add(GetCorrectionToAddParamBlock(funcDefnAst, parameterAsts));
194179
}
195180

196-
// This is how we handle multiple edits.
181+
// This is how we handle multiple edits-
197182
// create separate edits
198183
// apply those edits to the original script extent1
199184
// and then give the corrected extent as suggested correction.
@@ -225,7 +210,7 @@ private List<CorrectionExtent> GetCorrections(
225210
return result;
226211
}
227212

228-
private CorrectionExtent GetCorrectionExtentAddParamBlock(
213+
private CorrectionExtent GetCorrectionToAddParamBlock(
229214
FunctionDefinitionAst funcDefnAst,
230215
ParameterAst[] parameterAsts)
231216
{
@@ -277,7 +262,7 @@ private IList<String> WriteParamBlock(ParameterAst[] parameterAsts)
277262
}
278263

279264

280-
private static CorrectionExtent GetCorrectionExtentRemoveParams(
265+
private static CorrectionExtent GetCorrectionToRemoveFuncParamDecl(
281266
FunctionDefinitionAst funcDefnAst,
282267
Ast ast,
283268
Token[] tokens)
@@ -330,7 +315,7 @@ private static bool TryGetCmdletBindingAttribute(
330315
return attributeAst != null;
331316
}
332317

333-
private static CorrectionExtent GetCorrectionExtent(ParamBlockAst paramBlockAst)
318+
private static CorrectionExtent GetCorrectionToAddParamBlock(ParamBlockAst paramBlockAst)
334319
{
335320
return new CorrectionExtent(
336321
paramBlockAst.Extent.StartLineNumber,
@@ -345,7 +330,7 @@ private static CorrectionExtent GetCorrectionExtent(ParamBlockAst paramBlockAst)
345330
null,
346331
null);
347332
}
348-
private static CorrectionExtent GetCorrectionExtent(AttributeAst cmdletBindingAttributeAst)
333+
private static CorrectionExtent GetCorrectionToAddShouldProcess(AttributeAst cmdletBindingAttributeAst)
349334
{
350335
// 1 for the next position.
351336
var startColumnNumber = cmdletBindingAttributeAst.Extent.Text.IndexOf("(")
@@ -365,7 +350,7 @@ private static CorrectionExtent GetCorrectionExtent(AttributeAst cmdletBindingAt
365350
extent.File);
366351
}
367352

368-
private static CorrectionExtent GetCorrectionExtent(
353+
private static CorrectionExtent GetCorrectionToRemoveParam(
369354
int paramIndex,
370355
ParameterAst[] parameterAsts)
371356
{

0 commit comments

Comments
 (0)