Skip to content

Commit 7a421a8

Browse files
author
Kapil Borle
committed
Update separator violation logic
1 parent 92f64b6 commit 7a421a8

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

Rules/UseWhitespace.cs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -159,44 +159,41 @@ private IEnumerable<DiagnosticRecord> FindOpenParenViolations(TokenOperations to
159159
}
160160
}
161161

162+
private bool IsSeparator(Token token)
163+
{
164+
return token.Kind == TokenKind.Comma || token.Kind == TokenKind.Semi;
165+
}
162166
private IEnumerable<DiagnosticRecord> FindSeparatorViolations(TokenOperations tokenOperations)
163167
{
164168
Func<LinkedListNode<Token>, bool> predicate = node =>
165169
{
166170
return node.Next != null
171+
&& node.Next.Value.Kind != TokenKind.NewLine
172+
&& node.Next.Value.Kind != TokenKind.EndOfInput // semicolon can be followed by end of input
167173
&& !IsPreviousTokenApartByWhitespace(node.Next);
168174
};
169175

170-
Func<Token, ErrorKind, DiagnosticRecord> getDiagnosticRecord = (token, errKind) =>
171-
{
172-
return new DiagnosticRecord(
173-
GetError(errKind),
174-
token.Extent,
175-
GetName(),
176-
GetDiagnosticSeverity(),
177-
token.Extent.File,
178-
null,
179-
null);
180-
};
181-
182-
foreach (var tokenNode in tokenOperations.GetTokenNodes(TokenKind.Comma).Where(predicate))
183-
{
184-
yield return getDiagnosticRecord(tokenNode.Value, ErrorKind.SeparatorComma);
185-
}
186-
187-
foreach (var tokenNode in tokenOperations.GetTokenNodes(TokenKind.Semi).Where(predicate))
176+
// TODO replace semi-colon with semicolon
177+
// TODO update separator error string
178+
foreach (var tokenNode in tokenOperations.GetTokenNodes(IsSeparator).Where(predicate))
188179
{
189-
// semi-colon can be followed by newline or end of input
190-
if (tokenNode.Next.Value.Kind == TokenKind.EndOfInput
191-
|| tokenNode.Next.Value.Kind == TokenKind.NewLine)
192-
{
193-
continue;
194-
}
195-
196-
yield return getDiagnosticRecord(tokenNode.Value, ErrorKind.SeparatorSemi);
180+
yield return getDiagnosticRecord(
181+
tokenNode.Value,
182+
tokenNode.Value.Kind == TokenKind.Comma ? ErrorKind.SeparatorComma : ErrorKind.SeparatorSemi);
197183
}
198184
}
199185

186+
private DiagnosticRecord getDiagnosticRecord(Token token, ErrorKind errKind)
187+
{
188+
return new DiagnosticRecord(
189+
GetError(errKind),
190+
token.Extent,
191+
GetName(),
192+
GetDiagnosticSeverity(),
193+
token.Extent.File,
194+
null,
195+
null);
196+
}
200197

201198
private bool IsKeyword(Token token)
202199
{

0 commit comments

Comments
 (0)