16
16
using System . Globalization ;
17
17
using System . Linq ;
18
18
using System . Management . Automation . Language ;
19
+ using System . Text ;
19
20
using Microsoft . Windows . PowerShell . ScriptAnalyzer . Generic ;
20
21
21
22
namespace Microsoft . Windows . PowerShell . ScriptAnalyzer . BuiltinRules
@@ -156,10 +157,7 @@ private IEnumerable<DiagnosticRecord> FindOpenParenViolations(TokenOperations to
156
157
private IEnumerable < CorrectionExtent > GetOpenBracketCorrections ( Token token )
157
158
{
158
159
yield return new CorrectionExtent (
159
- token . Extent . StartLineNumber ,
160
- token . Extent . EndLineNumber ,
161
- token . Extent . StartColumnNumber ,
162
- token . Extent . EndColumnNumber ,
160
+ token . Extent ,
163
161
whiteSpace + token . Text ,
164
162
token . Extent . File ,
165
163
GetError ( ErrorKind . Brace ) ) ;
@@ -173,7 +171,8 @@ private bool IsPreviousTokenApartByWhitespace(LinkedListNode<Token> tokenNode)
173
171
174
172
private IEnumerable < DiagnosticRecord > FindOperatorViolations ( TokenOperations tokenOperations )
175
173
{
176
- Func < LinkedListNode < Token > , bool > predicate = tokenNode => {
174
+ Func < LinkedListNode < Token > , bool > predicate = tokenNode =>
175
+ {
177
176
return tokenNode . Previous != null
178
177
&& IsPreviousTokenOnSameLine ( tokenNode )
179
178
&& IsPreviousTokenApartByWhitespace ( tokenNode ) ;
@@ -202,11 +201,35 @@ private IEnumerable<DiagnosticRecord> FindOperatorViolations(TokenOperations tok
202
201
GetDiagnosticSeverity ( ) ,
203
202
tokenOperations . Ast . Extent . File ,
204
203
null ,
205
- null ) ;
204
+ GetOperatorCorrections ( tokenNode . Value , hasWhitespaceBefore , hasWhitespaceAfter ) . ToList ( ) ) ;
206
205
}
207
206
}
208
207
}
209
208
209
+ private IEnumerable < CorrectionExtent > GetOperatorCorrections (
210
+ Token token ,
211
+ bool hasWhitespaceBefore ,
212
+ bool hasWhitespaceAfter )
213
+ {
214
+ var sb = new StringBuilder ( ) ;
215
+ if ( ! hasWhitespaceBefore )
216
+ {
217
+ sb . Append ( whiteSpace ) ;
218
+ }
219
+
220
+ sb . Append ( token . Text ) ;
221
+ if ( ! hasWhitespaceAfter )
222
+ {
223
+ sb . Append ( whiteSpace ) ;
224
+ }
225
+
226
+ yield return new CorrectionExtent (
227
+ token . Extent ,
228
+ sb . ToString ( ) ,
229
+ token . Extent . File ,
230
+ GetError ( ErrorKind . Operator ) ) ;
231
+ }
232
+
210
233
private bool IsOperator ( Token token )
211
234
{
212
235
return TokenTraits . HasTrait ( token . Kind , TokenFlags . AssignmentOperator )
0 commit comments