Skip to content

Commit e4e219d

Browse files
author
Kapil Borle
committed
Use extent tuples to check keys on different lines
1 parent f0fd2ed commit e4e219d

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Rules/AlignAssignmentStatement.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,13 @@ private IEnumerable<DiagnosticRecord> FindHashtableViolations(TokenOperations to
184184
foreach (var astItem in hashtableAsts)
185185
{
186186
var hashtableAst = (HashtableAst)astItem;
187-
if (!HasKeysOnSeparateLines(hashtableAst))
187+
var extentTuples = GetExtents(tokenOps, hashtableAst);
188+
189+
if (!HasPropertiesOnSeparateLines(extentTuples))
188190
{
189191
continue;
190192
}
191193

192-
var extentTuples = GetExtents(tokenOps, hashtableAst);
193194
if (extentTuples == null
194195
|| extentTuples.Count == 0
195196
|| !extentTuples.All(t => t.Item1.StartLineNumber == t.Item2.EndLineNumber))
@@ -296,6 +297,24 @@ private static IList<Tuple<IScriptExtent, IScriptExtent>> GetExtents(
296297
return nodeTuples;
297298
}
298299

300+
private bool HasPropertiesOnSeparateLines(IEnumerable<Tuple<IScriptExtent, IScriptExtent>> tuples)
301+
{
302+
var lines = new HashSet<int>();
303+
foreach (var kvp in tuples)
304+
{
305+
if (lines.Contains(kvp.Item1.StartLineNumber))
306+
{
307+
return false;
308+
}
309+
else
310+
{
311+
lines.Add(kvp.Item1.StartLineNumber);
312+
}
313+
}
314+
315+
return true;
316+
}
317+
299318
private bool HasKeysOnSeparateLines(HashtableAst hashtableAst)
300319
{
301320
var lines = new HashSet<int>();

0 commit comments

Comments
 (0)