@@ -31,7 +31,7 @@ public class PlaceCloseBrace : ConfigurableRule
31
31
/// <summary>
32
32
/// Indicates if there should or should not be an empty line before a close brace.
33
33
///
34
- /// Default value if false.
34
+ /// Default value is false.
35
35
/// </summary>
36
36
[ ConfigurableRuleProperty ( defaultValue : false ) ]
37
37
public bool NoEmptyLineBefore { get ; protected set ; }
@@ -42,11 +42,21 @@ public class PlaceCloseBrace : ConfigurableRule
42
42
/// In the above example, if the property is set to true then the rule will
43
43
/// not fire a violation.
44
44
///
45
- /// Default value if true.
45
+ /// Default value is true.
46
46
/// </summary>
47
47
[ ConfigurableRuleProperty ( defaultValue : true ) ]
48
48
public bool IgnoreOneLineBlock { get ; protected set ; }
49
49
50
+ /// <summary>
51
+ /// Indicates if a new line should follow a close brace.
52
+ ///
53
+ /// If set to true a close brace should be followed by a new line.
54
+ ///
55
+ /// Default value is true.
56
+ /// </summary>
57
+ [ ConfigurableRuleProperty ( defaultValue : true ) ]
58
+ public bool NewLineAfter { get ; protected set ; }
59
+
50
60
private HashSet < Token > tokensToIgnore ;
51
61
52
62
/// <summary>
@@ -121,6 +131,13 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
121
131
GetViolationForBraceShouldNotFollowEmptyLine ( tokens , k , openBracePos , fileName ) ,
122
132
ref diagnosticRecords ) ;
123
133
}
134
+
135
+ if ( NewLineAfter )
136
+ {
137
+ AddToDiagnosticRecords (
138
+ GetViolationForBraceShouldHaveNewLineAfter ( tokens , k , openBracePos , fileName ) ,
139
+ ref diagnosticRecords ) ;
140
+ }
124
141
}
125
142
else
126
143
{
@@ -244,6 +261,22 @@ private List<CorrectionExtent> GetCorrectionsForBraceShouldNotFollowEmptyLine(
244
261
return corrections ;
245
262
}
246
263
264
+ private List < CorrectionExtent > GetCorrectionsForBraceShouldHaveNewLineAfter (
265
+ Token [ ] tokens ,
266
+ int closeBracePos ,
267
+ int openBracePos ,
268
+ string fileName )
269
+ {
270
+ var corrections = new List < CorrectionExtent > ( ) ;
271
+ var nextToken = tokens [ closeBracePos + 1 ] ;
272
+ var closeBraceToken = tokens [ closeBracePos ] ;
273
+ corrections . Add ( new CorrectionExtent (
274
+ closeBraceToken . Extent ,
275
+ closeBraceToken . Text + Environment . NewLine ,
276
+ fileName ) ) ;
277
+ return corrections ;
278
+ }
279
+
247
280
private string GetIndentation ( Token [ ] tokens , int closeBracePos , int openBracePos )
248
281
{
249
282
// if open brace on a new line by itself, use its indentation
@@ -271,7 +304,40 @@ private string GetIndentation(Token[] tokens, int closeBracePos, int openBracePo
271
304
return new String ( ' ' , firstTokenOnOpenBraceLine . Extent . StartColumnNumber - 1 ) ;
272
305
}
273
306
274
- private DiagnosticRecord GetViolationForBraceShouldBeOnNewLine ( Token [ ] tokens , int closeBracePos , int openBracePos , string fileName )
307
+ private DiagnosticRecord GetViolationForBraceShouldHaveNewLineAfter (
308
+ Token [ ] tokens ,
309
+ int closeBracePos ,
310
+ int openBracePos ,
311
+ string fileName )
312
+ {
313
+ var expectedNewLinePos = closeBracePos + 1 ;
314
+ if ( tokens . Length > 1 && tokens . Length > expectedNewLinePos )
315
+ {
316
+ var closeBraceToken = tokens [ closeBracePos ] ;
317
+ if ( tokens [ expectedNewLinePos ] . Kind != TokenKind . NewLine
318
+ && tokens [ expectedNewLinePos ] . Kind != TokenKind . Comment
319
+ && ! tokensToIgnore . Contains ( tokens [ closeBracePos ] ) )
320
+ {
321
+
322
+ return new DiagnosticRecord (
323
+ GetError ( Strings . PlaceCloseBraceErrorShouldFollowNewLine ) ,
324
+ closeBraceToken . Extent ,
325
+ GetName ( ) ,
326
+ GetDiagnosticSeverity ( ) ,
327
+ fileName ,
328
+ null ,
329
+ GetCorrectionsForBraceShouldHaveNewLineAfter ( tokens , closeBracePos , openBracePos , fileName ) ) ;
330
+ }
331
+ }
332
+
333
+ return null ;
334
+ }
335
+
336
+ private DiagnosticRecord GetViolationForBraceShouldBeOnNewLine (
337
+ Token [ ] tokens ,
338
+ int closeBracePos ,
339
+ int openBracePos ,
340
+ string fileName )
275
341
{
276
342
if ( tokens . Length > 1 && tokens . Length > closeBracePos )
277
343
{
0 commit comments