Skip to content

Commit 3cd8b24

Browse files
author
Kapil Borle
committed
Add method to remove function parameter declaration
1 parent 74f67c7 commit 3cd8b24

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

rules/UseSupportsShouldProcess.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,12 @@ private List<CorrectionExtent> GetCorrections(
188188
// remove the parameter list
189189
// and create an equivalent param block
190190
// add cmdletbinding attribute and add supportsshouldprocess to it.
191+
correctionExtents.Add(GetCorrectionsExtentRemoveParams(funcDefnAst, ast, tokens));
191192
}
192193

193194
// sort in descending order of start position
194-
correctionExtents.Sort((x, y) => {
195+
correctionExtents.Sort((x, y) =>
196+
{
195197
var xRange = (Range)x;
196198
var yRange = (Range)y;
197199
return xRange.Start < yRange.Start ? 1 : (xRange.Start == yRange.Start ? 0 : -1);
@@ -220,6 +222,24 @@ private List<CorrectionExtent> GetCorrections(
220222
// and then give the corrected extent as suggested correction.
221223
}
222224

225+
private static CorrectionExtent GetCorrectionsExtentRemoveParams(
226+
FunctionDefinitionAst funcDefnAst,
227+
Ast ast,
228+
Token[] tokens)
229+
{
230+
var funcDefnTokens = TokenOperations.GetTokens(ast, funcDefnAst, tokens).ToArray();
231+
var lParenTokenIdx = Array.FindIndex(funcDefnTokens, tok => tok.Kind == TokenKind.LParen);
232+
var rParenTokenIdx = Array.FindIndex(funcDefnTokens, tok => tok.Kind == TokenKind.RParen);
233+
234+
return new CorrectionExtent(
235+
tokens[lParenTokenIdx - 1].Extent.EndLineNumber,
236+
tokens[rParenTokenIdx].Extent.EndLineNumber,
237+
tokens[lParenTokenIdx - 1].Extent.EndColumnNumber,
238+
tokens[rParenTokenIdx].Extent.EndColumnNumber,
239+
"",
240+
ast.Extent.File);
241+
}
242+
223243
// doesn't seem right. The arguments should be of same type.
224244
private CorrectionExtent Normalize(IScriptExtent referenceExtent, CorrectionExtent cextent)
225245
{

0 commit comments

Comments
 (0)