Skip to content

Commit dd381e6

Browse files
author
Kapil Borle
committed
Add an out parameter to relay updated range
Whenever PSSA makes a fix, it may change the number of lines in the script, thereby invalidating the original range. We need relay the updated range so that future calls to fix can use the updated range.
1 parent 4ae9a90 commit dd381e6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Engine/Formatter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ public static string Format<TCmdlet>(
4141
var currentSettings = GetCurrentSettings(settings, rule);
4242
ScriptAnalyzer.Instance.UpdateSettings(currentSettings);
4343
ScriptAnalyzer.Instance.Initialize(cmdlet, null, null, null, null, true, false);
44-
text = ScriptAnalyzer.Instance.Fix(text, range);
44+
45+
Range updatedRange;
46+
text = ScriptAnalyzer.Instance.Fix(text, range, out updatedRange);
47+
range = updatedRange;
4548
}
4649

4750
return text.ToString();

Engine/ScriptAnalyzer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,15 +1539,17 @@ public string Fix(string scriptDefinition)
15391539
throw new ArgumentNullException(nameof(scriptDefinition));
15401540
}
15411541

1542-
return Fix(new EditableText(scriptDefinition), null).ToString();
1542+
Range updatedRange;
1543+
return Fix(new EditableText(scriptDefinition), null, out updatedRange).ToString();
15431544
}
15441545

15451546
/// <summary>
15461547
/// Fix the violations in the given script text.
15471548
/// </summary>
15481549
/// <param name="text">An object of type `EditableText` that encapsulates the script text to be fixed.</param>
1550+
/// <param name="updatedRange">The updated range after the fixes have been applied.</param>
15491551
/// <returns>The same instance of `EditableText` that was passed to the method, but the instance encapsulates the fixed script text. This helps in chaining the Fix method.</returns>
1550-
public EditableText Fix(EditableText text, Range range)
1552+
public EditableText Fix(EditableText text, Range range, out Range updatedRange)
15511553
{
15521554
if (text == null)
15531555
{
@@ -1598,6 +1600,7 @@ public EditableText Fix(EditableText text, Range range)
15981600
previousLineCount = lineCount;
15991601
} while (previousUnusedCorrections > 0);
16001602

1603+
updatedRange = range;
16011604
return text;
16021605
}
16031606

0 commit comments

Comments
 (0)