Skip to content

Commit 96b1a60

Browse files
author
Kapil Borle
committed
Change keyword lookup implementation
1 parent 99a7eed commit 96b1a60

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

Rules/UseConsistentWhitespace.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ public class UseConsistentWhitespace : ConfigurableRule
3232
private enum ErrorKind { Brace, Paren, Operator, SeparatorComma, SeparatorSemi };
3333
private const int whiteSpaceSize = 1;
3434
private const string whiteSpace = " ";
35+
private readonly SortedSet<TokenKind> openParenKeywordWhitelist = new SortedSet<TokenKind>()
36+
{
37+
TokenKind.If,
38+
TokenKind.ElseIf,
39+
TokenKind.Switch,
40+
TokenKind.For,
41+
TokenKind.Foreach,
42+
TokenKind.While
43+
};
3544

3645
private List<Func<TokenOperations, IEnumerable<DiagnosticRecord>>> violationFinders
3746
= new List<Func<TokenOperations, IEnumerable<DiagnosticRecord>>>();
@@ -278,19 +287,7 @@ private DiagnosticRecord getDiagnosticRecord(
278287

279288
private bool IsKeyword(Token token)
280289
{
281-
switch (token.Kind)
282-
{
283-
case TokenKind.If:
284-
case TokenKind.ElseIf:
285-
case TokenKind.Switch:
286-
case TokenKind.For:
287-
case TokenKind.Foreach:
288-
case TokenKind.While:
289-
return true;
290-
291-
default:
292-
return false;
293-
}
290+
return openParenKeywordWhitelist.Contains(token.Kind);
294291
}
295292

296293
private bool IsPreviousTokenApartByWhitespace(LinkedListNode<Token> tokenNode)

0 commit comments

Comments
 (0)