Skip to content

Commit 3057c03

Browse files
author
Kapil Borle
committed
Create a method to get current settings
1 parent 7fa659d commit 3057c03

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

Engine/Formatter.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
1010
{
1111
public class Formatter
1212
{
13+
// TODO add a method that takes range parameter
1314
public static string Format<TCmdlet>(
1415
string scriptDefinition,
15-
Settings inputSettings,
16+
Settings settings,
1617
TCmdlet cmdlet) where TCmdlet : PSCmdlet, IOutputWriter
1718
{
1819
Helper.Instance = new Helper(cmdlet.SessionState.InvokeCommand, cmdlet);
@@ -30,18 +31,14 @@ public static string Format<TCmdlet>(
3031
var text = new EditableText(scriptDefinition);
3132
foreach (var rule in ruleOrder)
3233
{
33-
if (!inputSettings.RuleArguments.ContainsKey(rule))
34+
if (!settings.RuleArguments.ContainsKey(rule))
3435
{
3536
continue;
3637
}
3738

3839
cmdlet.WriteVerbose("Running " + rule);
39-
var currentSettingsHashtable = new Hashtable();
40-
currentSettingsHashtable.Add("IncludeRules", new string[] { rule });
41-
var ruleSettings = new Hashtable();
42-
ruleSettings.Add(rule, new Hashtable(inputSettings.RuleArguments[rule]));
43-
currentSettingsHashtable.Add("Rules", ruleSettings);
44-
var currentSettings = new Settings(currentSettingsHashtable);
40+
41+
var currentSettings = GetCurrentSettings(settings, rule);
4542
ScriptAnalyzer.Instance.UpdateSettings(currentSettings);
4643
ScriptAnalyzer.Instance.Initialize(cmdlet, null, null, null, null, true, false);
4744

@@ -51,6 +48,7 @@ public static string Format<TCmdlet>(
5148

5249
do
5350
{
51+
// TODO create better verbose messages
5452
var correctionApplied = new HashSet<int>();
5553
foreach (var correction in corrections)
5654
{
@@ -91,5 +89,18 @@ public static string Format<TCmdlet>(
9189

9290
return text.ToString();
9391
}
92+
93+
private static Settings GetCurrentSettings(Settings settings, string rule)
94+
{
95+
var currentSettingsHashtable = new Hashtable();
96+
currentSettingsHashtable.Add("IncludeRules", new string[] { rule });
97+
98+
var ruleSettings = new Hashtable();
99+
ruleSettings.Add(rule, new Hashtable(settings.RuleArguments[rule]));
100+
currentSettingsHashtable.Add("Rules", ruleSettings);
101+
102+
var currentSettings = new Settings(currentSettingsHashtable);
103+
return currentSettings;
104+
}
94105
}
95106
}

0 commit comments

Comments
 (0)