Skip to content

Commit 38e2c69

Browse files
author
Kapil Borle
committed
Replace only the required part in correction
1 parent de2af7a commit 38e2c69

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

Rules/UseWhitespace.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private IEnumerable<DiagnosticRecord> FindOpenParenViolations(TokenOperations to
154154
GetDiagnosticSeverity(),
155155
tokenOperations.Ast.Extent.File,
156156
null,
157-
GetOpenBracketCorrections(lparen.Value).ToList());
157+
GetCorrections(lparen.Previous.Value, lparen.Value, lparen.Next.Value, false, true).ToList());
158158
}
159159
}
160160
}
@@ -163,6 +163,7 @@ private bool IsSeparator(Token token)
163163
{
164164
return token.Kind == TokenKind.Comma || token.Kind == TokenKind.Semi;
165165
}
166+
166167
private IEnumerable<DiagnosticRecord> FindSeparatorViolations(TokenOperations tokenOperations)
167168
{
168169
Func<LinkedListNode<Token>, bool> predicate = node =>
@@ -173,8 +174,6 @@ private IEnumerable<DiagnosticRecord> FindSeparatorViolations(TokenOperations to
173174
&& !IsPreviousTokenApartByWhitespace(node.Next);
174175
};
175176

176-
// TODO replace semi-colon with semicolon
177-
// TODO update separator error string
178177
foreach (var tokenNode in tokenOperations.GetTokenNodes(IsSeparator).Where(predicate))
179178
{
180179
var errorKind = tokenNode.Value.Kind == TokenKind.Comma
@@ -224,15 +223,6 @@ private bool IsKeyword(Token token)
224223
}
225224
}
226225

227-
private IEnumerable<CorrectionExtent> GetOpenBracketCorrections(Token token)
228-
{
229-
yield return new CorrectionExtent(
230-
token.Extent,
231-
whiteSpace + token.Text,
232-
token.Extent.File,
233-
GetError(ErrorKind.Brace));
234-
}
235-
236226
private bool IsPreviousTokenApartByWhitespace(LinkedListNode<Token> tokenNode)
237227
{
238228
return whiteSpaceSize ==
@@ -285,19 +275,23 @@ private List<CorrectionExtent> GetCorrections(
285275
{
286276
sb.Append(whiteSpace);
287277
e1 = prevToken.Extent;
288-
sb.Append(token.Text);
289278
}
290279

280+
var e2 = token.Extent;
291281
if (!hasWhitespaceAfter)
292282
{
283+
if (!hasWhitespaceBefore)
284+
{
285+
sb.Append(token.Text);
286+
}
287+
288+
e2 = nextToken.Extent;
293289
sb.Append(whiteSpace);
294290
}
295291

296-
var e2 = nextToken.Extent;
297292
var extent = new ScriptExtent(
298293
new ScriptPosition(e1.File, e1.EndLineNumber, e1.EndColumnNumber, null),
299294
new ScriptPosition(e2.File, e2.StartLineNumber, e2.StartColumnNumber, null));
300-
301295
return new List<CorrectionExtent>()
302296
{
303297
new CorrectionExtent(

0 commit comments

Comments
 (0)