@@ -66,10 +66,6 @@ protected override void BeginProcessing()
66
66
}
67
67
#endif
68
68
69
- // var settings = PSSASettings.Create(Settings);
70
- // formatter = new Formatter(settings);
71
-
72
- // todo move to a common initalize session method
73
69
Helper . Instance = new Helper ( SessionState . InvokeCommand , this ) ;
74
70
Helper . Instance . Initialize ( ) ;
75
71
@@ -90,83 +86,10 @@ protected override void BeginProcessing()
90
86
}
91
87
}
92
88
93
-
94
89
protected override void ProcessRecord ( )
95
90
{
96
- // this.WriteObject(formatter.Format(ScriptDefinition));
97
-
98
- var ruleOrder = new string [ ]
99
- {
100
- "PSPlaceCloseBrace" ,
101
- "PSPlaceOpenBrace" ,
102
- "PSUseConsistentWhitespace" ,
103
- "PSUseConsistentIndentation" ,
104
- "PSAlignAssignmentStatement"
105
- } ;
106
-
107
- var text = new EditableText ( ScriptDefinition ) ;
108
- foreach ( var rule in ruleOrder )
109
- {
110
- if ( ! inputSettings . RuleArguments . ContainsKey ( rule ) )
111
- {
112
- continue ;
113
- }
114
-
115
- this . WriteVerbose ( "Running " + rule ) ;
116
- var currentSettingsHashtable = new Hashtable ( ) ;
117
- currentSettingsHashtable . Add ( "IncludeRules" , new string [ ] { rule } ) ;
118
- var ruleSettings = new Hashtable ( ) ;
119
- ruleSettings . Add ( rule , new Hashtable ( inputSettings . RuleArguments [ rule ] ) ) ;
120
- currentSettingsHashtable . Add ( "Rules" , ruleSettings ) ;
121
- var currentSettings = new Settings ( currentSettingsHashtable ) ;
122
- ScriptAnalyzer . Instance . UpdateSettings ( currentSettings ) ;
123
- ScriptAnalyzer . Instance . Initialize ( this , null , null , null , null , true , false ) ;
124
-
125
- var corrections = new List < CorrectionExtent > ( ) ;
126
- var records = Enumerable . Empty < DiagnosticRecord > ( ) ;
127
- var numPreviousCorrections = corrections . Count ;
128
-
129
- do
130
- {
131
- var correctionApplied = new HashSet < int > ( ) ;
132
- foreach ( var correction in corrections )
133
- {
134
- // apply only one edit per line
135
- if ( correctionApplied . Contains ( correction . StartLineNumber ) )
136
- {
137
- continue ;
138
- }
139
-
140
- correctionApplied . Add ( correction . StartLineNumber ) ;
141
- text . ApplyEdit ( correction ) ;
142
- }
143
-
144
- records = ScriptAnalyzer . Instance . AnalyzeScriptDefinition ( text . ToString ( ) ) ;
145
- corrections = records . Select ( r => r . SuggestedCorrections . ElementAt ( 0 ) ) . ToList ( ) ;
146
- if ( numPreviousCorrections > 0 && numPreviousCorrections == corrections . Count )
147
- {
148
- this . ThrowTerminatingError ( new ErrorRecord (
149
- new InvalidOperationException ( ) ,
150
- "FORMATTER_ERROR" ,
151
- ErrorCategory . InvalidOperation ,
152
- corrections ) ) ;
153
- }
154
-
155
- numPreviousCorrections = corrections . Count ;
156
-
157
- // get unique correction instances
158
- // sort them by line numbers
159
- corrections . Sort ( ( x , y ) =>
160
- {
161
- return x . StartLineNumber < x . StartLineNumber ?
162
- 1 :
163
- ( x . StartLineNumber == x . StartLineNumber ? 0 : - 1 ) ;
164
- } ) ;
165
-
166
- } while ( numPreviousCorrections > 0 ) ;
167
- }
168
-
169
- this . WriteObject ( text . ToString ( ) ) ;
91
+ var text = Formatter . Format ( ScriptDefinition , inputSettings , this ) ;
92
+ this . WriteObject ( text ) ;
170
93
}
171
94
172
95
private void ValidateInputSettings ( )
0 commit comments