Skip to content

Commit 3450c95

Browse files
author
Kapil Borle
committed
Update open brace violation finder implementation
1 parent 688a881 commit 3450c95

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

Rules/UseWhitespace.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,20 @@ private string GetError(ErrorKind kind)
9191

9292
private IEnumerable<DiagnosticRecord> FindOpenBraceViolations(TokenOperations tokenOperations)
9393
{
94-
var tokensAndWhitespaces = tokenOperations.GetOpenBracesWithWhiteSpacesBefore();
95-
foreach (var item in tokensAndWhitespaces)
94+
foreach (var lcurly in tokenOperations.GetTokenNodes(TokenKind.LCurly))
9695
{
97-
if (item.Item2 != whiteSpaceSize)
96+
if (lcurly.Previous == null
97+
|| !IsPreviousTokenOnSameLine(lcurly)
98+
|| lcurly.Previous.Value.Kind == TokenKind.LCurly)
99+
{
100+
continue;
101+
}
102+
103+
if (!IsPreviousTokenApartByWhitespace(lcurly))
98104
{
99105
yield return new DiagnosticRecord(
100106
GetError(ErrorKind.Brace),
101-
item.Item1.Extent,
107+
lcurly.Value.Extent,
102108
GetName(),
103109
GetDiagnosticSeverity(),
104110
tokenOperations.Ast.Extent.File,
@@ -123,8 +129,7 @@ private IEnumerable<DiagnosticRecord> FindOpenParenViolations(TokenOperations to
123129
continue;
124130
}
125131

126-
if (whiteSpaceSize !=
127-
lparen.Value.Extent.StartColumnNumber - lparen.Previous.Value.Extent.EndColumnNumber)
132+
if (!IsPreviousTokenApartByWhitespace(lparen))
128133
{
129134
yield return new DiagnosticRecord(
130135
GetError(ErrorKind.Paren),
@@ -138,6 +143,12 @@ private IEnumerable<DiagnosticRecord> FindOpenParenViolations(TokenOperations to
138143
}
139144
}
140145

146+
private bool IsPreviousTokenApartByWhitespace(LinkedListNode<Token> tokenNode)
147+
{
148+
return whiteSpaceSize ==
149+
(tokenNode.Value.Extent.StartColumnNumber - tokenNode.Previous.Value.Extent.EndColumnNumber);
150+
}
151+
141152
private bool IsPreviousTokenOnSameLine(LinkedListNode<Token> lparen)
142153
{
143154
return lparen.Previous.Value.Extent.StartLineNumber == lparen.Value.Extent.EndLineNumber;

0 commit comments

Comments
 (0)