@@ -31,7 +31,7 @@ public class PlaceCloseBrace : ConfigurableRule
3131 /// <summary>
3232 /// Indicates if there should or should not be an empty line before a close brace.
3333 ///
34- /// Default value if false.
34+ /// Default value is false.
3535 /// </summary>
3636 [ ConfigurableRuleProperty ( defaultValue : false ) ]
3737 public bool NoEmptyLineBefore { get ; protected set ; }
@@ -42,11 +42,21 @@ public class PlaceCloseBrace : ConfigurableRule
4242 /// In the above example, if the property is set to true then the rule will
4343 /// not fire a violation.
4444 ///
45- /// Default value if true.
45+ /// Default value is true.
4646 /// </summary>
4747 [ ConfigurableRuleProperty ( defaultValue : true ) ]
4848 public bool IgnoreOneLineBlock { get ; protected set ; }
4949
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+
5060 private HashSet < Token > tokensToIgnore ;
5161
5262 /// <summary>
@@ -121,6 +131,13 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
121131 GetViolationForBraceShouldNotFollowEmptyLine ( tokens , k , openBracePos , fileName ) ,
122132 ref diagnosticRecords ) ;
123133 }
134+
135+ if ( NewLineAfter )
136+ {
137+ AddToDiagnosticRecords (
138+ GetViolationForBraceShouldHaveNewLineAfter ( tokens , k , openBracePos , fileName ) ,
139+ ref diagnosticRecords ) ;
140+ }
124141 }
125142 else
126143 {
@@ -244,6 +261,22 @@ private List<CorrectionExtent> GetCorrectionsForBraceShouldNotFollowEmptyLine(
244261 return corrections ;
245262 }
246263
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+
247280 private string GetIndentation ( Token [ ] tokens , int closeBracePos , int openBracePos )
248281 {
249282 // 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
271304 return new String ( ' ' , firstTokenOnOpenBraceLine . Extent . StartColumnNumber - 1 ) ;
272305 }
273306
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 )
275341 {
276342 if ( tokens . Length > 1 && tokens . Length > closeBracePos )
277343 {
0 commit comments