Skip to content

Commit da59328

Browse files
author
Kapil Borle
committed
Add corrections for bracket violations
1 parent 02a0b9d commit da59328

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

Rules/UseWhitespace.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
2929
public class UseWhitespace : ConfigurableRule
3030
{
3131
private enum ErrorKind { Brace, Paren, Operator };
32-
private readonly int whiteSpaceSize = 1;
32+
private const int whiteSpaceSize = 1;
33+
private const string whiteSpace = " ";
3334

3435
private List<Func<TokenOperations, IEnumerable<DiagnosticRecord>>> violationFinders
3536
= new List<Func<TokenOperations, IEnumerable<DiagnosticRecord>>>();
@@ -118,7 +119,7 @@ private IEnumerable<DiagnosticRecord> FindOpenBraceViolations(TokenOperations to
118119
GetDiagnosticSeverity(),
119120
tokenOperations.Ast.Extent.File,
120121
null,
121-
null);
122+
GetOpenBracketCorrections(lcurly.Value).ToList());
122123
}
123124
}
124125
}
@@ -147,11 +148,23 @@ private IEnumerable<DiagnosticRecord> FindOpenParenViolations(TokenOperations to
147148
GetDiagnosticSeverity(),
148149
tokenOperations.Ast.Extent.File,
149150
null,
150-
null);
151+
GetOpenBracketCorrections(lparen.Value).ToList());
151152
}
152153
}
153154
}
154155

156+
private IEnumerable<CorrectionExtent> GetOpenBracketCorrections(Token token)
157+
{
158+
yield return new CorrectionExtent(
159+
token.Extent.StartLineNumber,
160+
token.Extent.EndLineNumber,
161+
token.Extent.StartColumnNumber,
162+
token.Extent.EndColumnNumber,
163+
whiteSpace + token.Text,
164+
token.Extent.File,
165+
GetError(ErrorKind.Brace));
166+
}
167+
155168
private bool IsPreviousTokenApartByWhitespace(LinkedListNode<Token> tokenNode)
156169
{
157170
return whiteSpaceSize ==

0 commit comments

Comments
 (0)