Skip to content

Commit 8210765

Browse files
author
Kapil Borle
committed
Ignore close brace in a one line if else statement
1 parent 2d2f716 commit 8210765

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Rules/PlaceCloseBrace.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public class PlaceCloseBrace : ConfigurableRule
3636
[ConfigurableRuleProperty(defaultValue:false)]
3737
public bool NoEmptyLineBefore { get; protected set; }
3838

39+
[ConfigurableRuleProperty(defaultValue: true)]
40+
public bool IgnoreOneLineIf { get; protected set; }
41+
3942
private HashSet<Token> tokensToIgnore;
4043

4144
/// <summary>
@@ -64,8 +67,18 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
6467
var tokens = Helper.Instance.Tokens;
6568
var diagnosticRecords = new List<DiagnosticRecord>();
6669
var curlyStack = new Stack<Tuple<Token, int>> ();
67-
tokensToIgnore = new HashSet<Token> (
68-
new TokenOperations(tokens, ast).GetCloseBracesInCommandElements());
70+
71+
// TODO move part common with PlaceOpenBrace to one place
72+
// TODO use a general switch to ignore blocks on one line
73+
var tokenOps = new TokenOperations(tokens, ast);
74+
tokensToIgnore = new HashSet<Token> (tokenOps.GetCloseBracesInCommandElements());
75+
if (IgnoreOneLineIf)
76+
{
77+
foreach (var closeBraceToken in tokenOps.GetCloseBraceInOneLineIfStatement())
78+
{
79+
tokensToIgnore.Add(closeBraceToken);
80+
}
81+
}
6982

7083
for (int k = 0; k < tokens.Length; k++)
7184
{

0 commit comments

Comments
 (0)