@@ -10,9 +10,10 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
10
10
{
11
11
public class Formatter
12
12
{
13
+ // TODO add a method that takes range parameter
13
14
public static string Format < TCmdlet > (
14
15
string scriptDefinition ,
15
- Settings inputSettings ,
16
+ Settings settings ,
16
17
TCmdlet cmdlet ) where TCmdlet : PSCmdlet , IOutputWriter
17
18
{
18
19
Helper . Instance = new Helper ( cmdlet . SessionState . InvokeCommand , cmdlet ) ;
@@ -30,18 +31,14 @@ public static string Format<TCmdlet>(
30
31
var text = new EditableText ( scriptDefinition ) ;
31
32
foreach ( var rule in ruleOrder )
32
33
{
33
- if ( ! inputSettings . RuleArguments . ContainsKey ( rule ) )
34
+ if ( ! settings . RuleArguments . ContainsKey ( rule ) )
34
35
{
35
36
continue ;
36
37
}
37
38
38
39
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 ) ;
45
42
ScriptAnalyzer . Instance . UpdateSettings ( currentSettings ) ;
46
43
ScriptAnalyzer . Instance . Initialize ( cmdlet , null , null , null , null , true , false ) ;
47
44
@@ -51,6 +48,7 @@ public static string Format<TCmdlet>(
51
48
52
49
do
53
50
{
51
+ // TODO create better verbose messages
54
52
var correctionApplied = new HashSet < int > ( ) ;
55
53
foreach ( var correction in corrections )
56
54
{
@@ -91,5 +89,18 @@ public static string Format<TCmdlet>(
91
89
92
90
return text . ToString ( ) ;
93
91
}
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
+ }
94
105
}
95
106
}
0 commit comments