@@ -146,29 +146,31 @@ private IEnumerable<DiagnosticRecord> FindHashtableViolations(TokenOperations to
146
146
{
147
147
var hashtableAsts = tokenOps . Ast . FindAll ( ast => ast is HashtableAst , true ) ;
148
148
var groups = new List < List < Tuple < IScriptExtent , IScriptExtent > > > ( ) ;
149
- if ( hashtableAsts == null || ! hashtableAsts . Any ( ) )
149
+ if ( hashtableAsts != null )
150
150
{
151
- var configAsts = tokenOps . Ast . FindAll ( ast => ast is ConfigurationDefinitionAst , true ) ;
152
- if ( configAsts != null )
151
+ foreach ( var astItem in hashtableAsts )
153
152
{
154
- // There are probably parse errors caused by an "Undefined DSC resource"
155
- // which prevents the parser from detecting the property value pairs as
156
- // hashtable. Hence, this is a workaround to format configurations which
157
- // have "Undefined DSC resource" parse errors.
158
-
159
- // TODO break down the function and reuse the alignment logic.
160
-
161
- // find all commandAsts of the form "prop" "=" "val" that have the same parent
162
- // and format those pairs.
163
- foreach ( var configAst in configAsts )
164
- {
165
- groups . AddRange ( GetCommandElementExtentGroups ( configAst ) ) ;
166
- }
153
+ groups . Add ( GetExtents ( tokenOps , ( HashtableAst ) astItem ) ) ;
167
154
}
155
+ }
168
156
169
- yield break ;
157
+ var configAsts = tokenOps . Ast . FindAll ( ast => ast is ConfigurationDefinitionAst , true ) ;
158
+ if ( configAsts != null )
159
+ {
160
+ // There are probably parse errors caused by an "Undefined DSC resource"
161
+ // which prevents the parser from detecting the property value pairs as
162
+ // hashtable. Hence, this is a workaround to format configurations which
163
+ // have "Undefined DSC resource" parse errors.
164
+
165
+ // find all commandAsts of the form "prop" "=" "val" that have the same parent
166
+ // and format those pairs.
167
+ foreach ( var configAst in configAsts )
168
+ {
169
+ groups . AddRange ( GetCommandElementExtentGroups ( configAst ) ) ;
170
+ }
170
171
}
171
172
173
+
172
174
// it is probably much easier have a hashtable writer that formats the hashtable and writes it
173
175
// but it makes handling comments hard. So we need to use this approach.
174
176
@@ -183,11 +185,8 @@ private IEnumerable<DiagnosticRecord> FindHashtableViolations(TokenOperations to
183
185
// make sure all the assignment operators are in the same column as that of the longest left hand.
184
186
185
187
186
- foreach ( var astItem in hashtableAsts )
188
+ foreach ( var extentTuples in groups )
187
189
{
188
- var hashtableAst = ( HashtableAst ) astItem ;
189
- var extentTuples = GetExtents ( tokenOps , hashtableAst ) ;
190
-
191
190
if ( ! HasPropertiesOnSeparateLines ( extentTuples ) )
192
191
{
193
192
continue ;
@@ -294,7 +293,7 @@ private string GetError()
294
293
return String . Format ( CultureInfo . CurrentCulture , Strings . AlignAssignmentStatementError ) ;
295
294
}
296
295
297
- private static IList < Tuple < IScriptExtent , IScriptExtent > > GetExtents (
296
+ private static List < Tuple < IScriptExtent , IScriptExtent > > GetExtents (
298
297
TokenOperations tokenOps ,
299
298
HashtableAst hashtableAst )
300
299
{
0 commit comments