Skip to content

Commit d924831

Browse files
author
Kapil Borle
committed
Parameterize format method
1 parent 71a54ff commit d924831

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

Engine/Formatter.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ public static string Format(string scriptDefinition, Settings settings)
2222
throw new NotImplementedException();
2323
}
2424

25-
public static string Format(
25+
public static string Format<TCmdlet>(
2626
string scriptDefinition,
27-
Hashtable settingsHashtable,
28-
Runspace runspace,
29-
IOutputWriter outputWriter)
27+
Settings inputSettings,
28+
TCmdlet cmdlet) where TCmdlet : PSCmdlet, IOutputWriter
3029
{
3130
var inputSettings = new Settings(settingsHashtable);
3231
var ruleOrder = new string[]
@@ -46,15 +45,15 @@ public static string Format(
4645
continue;
4746
}
4847

49-
outputWriter.WriteVerbose("Running " + rule);
48+
cmdlet.WriteVerbose("Running " + rule);
5049
var currentSettingsHashtable = new Hashtable();
5150
currentSettingsHashtable.Add("IncludeRules", new string[] { rule });
5251
var ruleSettings = new Hashtable();
5352
ruleSettings.Add(rule, new Hashtable(inputSettings.RuleArguments[rule]));
5453
currentSettingsHashtable.Add("Rules", ruleSettings);
5554
var currentSettings = new Settings(currentSettingsHashtable);
5655
ScriptAnalyzer.Instance.UpdateSettings(inputSettings);
57-
ScriptAnalyzer.Instance.Initialize(runspace, outputWriter);
56+
ScriptAnalyzer.Instance.Initialize(cmdlet, null, null, null, null, true, false);
5857

5958
var corrections = new List<CorrectionExtent>();
6059
var records = Enumerable.Empty<DiagnosticRecord>();
@@ -79,7 +78,7 @@ public static string Format(
7978
corrections = records.Select(r => r.SuggestedCorrections.ElementAt(0)).ToList();
8079
if (numPreviousCorrections > 0 && numPreviousCorrections == corrections.Count)
8180
{
82-
outputWriter.ThrowTerminatingError(new ErrorRecord(
81+
cmdlet.ThrowTerminatingError(new ErrorRecord(
8382
new InvalidOperationException(),
8483
"FORMATTER_ERROR",
8584
ErrorCategory.InvalidOperation,

0 commit comments

Comments
 (0)