Skip to content

Commit d4bc9ef

Browse files
author
Kapil Borle
committed
Add method to get extent tuples from command asts
1 parent e4e219d commit d4bc9ef

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

Rules/AlignAssignmentStatement.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public override SourceType GetSourceType()
145145
private IEnumerable<DiagnosticRecord> FindHashtableViolations(TokenOperations tokenOps)
146146
{
147147
var hashtableAsts = tokenOps.Ast.FindAll(ast => ast is HashtableAst, true);
148+
var groups = new List<List<Tuple<IScriptExtent, IScriptExtent>>>();
148149
if (hashtableAsts == null || !hashtableAsts.Any())
149150
{
150151
var configAsts = tokenOps.Ast.FindAll(ast => ast is ConfigurationDefinitionAst, true);
@@ -161,7 +162,7 @@ private IEnumerable<DiagnosticRecord> FindHashtableViolations(TokenOperations to
161162
// and format those pairs.
162163
foreach (var configAst in configAsts)
163164
{
164-
var groups = GetCommandElementGroups(configAst);
165+
groups.AddRange(GetCommandElementExtentGroups(configAst));
165166
}
166167
}
167168

@@ -181,6 +182,7 @@ private IEnumerable<DiagnosticRecord> FindHashtableViolations(TokenOperations to
181182
// find the longest left expression
182183
// make sure all the assignment operators are in the same column as that of the longest left hand.
183184

185+
184186
foreach (var astItem in hashtableAsts)
185187
{
186188
var hashtableAst = (HashtableAst)astItem;
@@ -200,11 +202,12 @@ private IEnumerable<DiagnosticRecord> FindHashtableViolations(TokenOperations to
200202

201203
var widestKeyExtent = extentTuples
202204
.Select(t => t.Item1)
203-
.Aggregate((t1, tAggregate) => {
204-
return TokenOperations.GetExtentWidth(tAggregate) > TokenOperations.GetExtentWidth(t1)
205-
? tAggregate
206-
: t1;
207-
});
205+
.Aggregate((t1, tAggregate) =>
206+
{
207+
return TokenOperations.GetExtentWidth(tAggregate) > TokenOperations.GetExtentWidth(t1)
208+
? tAggregate
209+
: t1;
210+
});
208211
var expectedStartColumnNumber = widestKeyExtent.EndColumnNumber + 1;
209212
foreach (var extentTuple in extentTuples)
210213
{
@@ -223,6 +226,25 @@ private IEnumerable<DiagnosticRecord> FindHashtableViolations(TokenOperations to
223226
}
224227
}
225228

229+
private List<List<Tuple<IScriptExtent, IScriptExtent>>> GetCommandElementExtentGroups(Ast configAst)
230+
{
231+
var result = new List<List<Tuple<IScriptExtent, IScriptExtent>>>();
232+
var commandAstGroups = GetCommandElementGroups(configAst);
233+
foreach (var commandAstGroup in commandAstGroups)
234+
{
235+
var list = new List<Tuple<IScriptExtent, IScriptExtent>>();
236+
foreach (var commandAst in commandAstGroup)
237+
{
238+
var elems = commandAst.CommandElements;
239+
list.Add(new Tuple<IScriptExtent, IScriptExtent>(elems[0].Extent, elems[1].Extent));
240+
}
241+
242+
result.Add(list);
243+
}
244+
245+
return result;
246+
}
247+
226248
private List<List<CommandAst>> GetCommandElementGroups(Ast configAst)
227249
{
228250
var result = new List<List<CommandAst>>();

0 commit comments

Comments
 (0)