Skip to content

Commit dc091f1

Browse files
author
Kapil Borle
committed
Update violation extent of UseSupportShouldProcess rule
1 parent b5f9a8a commit dc091f1

1 file changed

Lines changed: 9 additions & 32 deletions

File tree

rules/UseSupportsShouldProcess.cs

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,13 @@ private List<DiagnosticRecord> FindViolations()
7979
if (addsWhatIf || addsConfirm)
8080
{
8181
IScriptExtent scriptExtent;
82-
if (addsWhatIf && addsConfirm)
83-
{
84-
// mark everthing between the parameters including them
85-
scriptExtent = CombineExtents(whatIfParamAst.Extent, confirmParamAst.Extent);
86-
}
87-
else if (addsWhatIf)
82+
83+
// if both whatif and confirm are present,
84+
// the extent will only contain whatif.
85+
// we do this because editorservices relies on the text
86+
// property of IScriptExtent and if we create a new extent
87+
// with null Text value, it crashes editorservices.
88+
if (addsWhatIf)
8889
{
8990
// mark the whatif parameter
9091
scriptExtent = whatIfParamAst.Extent;
@@ -141,13 +142,9 @@ private List<CorrectionExtent> GetCorrections(
141142
// - else it doesn't have supportsshouldprocess
142143
// - else it does not have cmdlet binding
143144
// - else a function doesn't have paramBlockAst
144-
IScriptExtent whatIfExtent, confirmExtent;
145145
var filePath = funcDefnAst.Extent.File;
146146
var correctionExtents = new List<CorrectionExtent>();
147147

148-
// TODO Handle case where only one param is left after correction and there is a
149-
// comma left after the param.
150-
151148
// 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.
152149
// the next parameter
153150
// TODO Do not incrementally correct the text as it may lead to a situation in which a following
@@ -158,6 +155,7 @@ private List<CorrectionExtent> GetCorrections(
158155
{
159156
if (whatIfIndex != -1)
160157
{
158+
// TODO update method name to reflect its purpose.
161159
correctionExtents.Add(GetCorrectionExtent(whatIfIndex, parameterAsts));
162160
}
163161

@@ -166,6 +164,7 @@ private List<CorrectionExtent> GetCorrections(
166164
correctionExtents.Add(GetCorrectionExtent(confirmIndex, parameterAsts));
167165
}
168166
AttributeAst attributeAst;
167+
169168
// check if it has cmdletbinding attribute
170169
if (TryGetCmdletBindingAttribute(paramBlockAst, out attributeAst))
171170
{
@@ -407,28 +406,6 @@ private static CorrectionExtent GetCorrectionExtent(
407406
paramExtent.File);
408407
}
409408

410-
private IScriptExtent CombineExtents(IScriptExtent extent1, IScriptExtent extent2)
411-
{
412-
IScriptExtent sExt, eExt;
413-
414-
// There are many conditions that we need to consider but for now we are considering
415-
// this special case only.
416-
if (extent1.StartOffset < extent2.StartOffset)
417-
{
418-
sExt = extent1;
419-
eExt = extent2;
420-
}
421-
else
422-
{
423-
sExt = extent2;
424-
eExt = extent1;
425-
}
426-
427-
return new ScriptExtent(
428-
new ScriptPosition(sExt.File, sExt.StartLineNumber, sExt.StartColumnNumber, null),
429-
new ScriptPosition(eExt.File, eExt.EndLineNumber, eExt.EndColumnNumber, null));
430-
}
431-
432409
private bool TryGetParameterAst(
433410
FunctionDefinitionAst functionDefinitionAst,
434411
string parameter,

0 commit comments

Comments
 (0)