@@ -37,7 +37,7 @@ public class PlaceCloseBrace : ConfigurableRule
3737 public bool NoEmptyLineBefore { get ; protected set ; }
3838
3939 [ ConfigurableRuleProperty ( defaultValue : true ) ]
40- public bool IgnoreOneLineIf { get ; protected set ; }
40+ public bool IgnoreOneLineBlock { get ; protected set ; }
4141
4242 private HashSet < Token > tokensToIgnore ;
4343
@@ -61,22 +61,22 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
6161
6262 // TODO Should have the following options
6363 // * no-empty-lines-before
64- // * align (if close brance and open brace on new lines align with open brace,
65- // if close brace is on new line but open brace is not align with the first keyword on open brace line)
6664
6765 var tokens = Helper . Instance . Tokens ;
6866 var diagnosticRecords = new List < DiagnosticRecord > ( ) ;
6967 var curlyStack = new Stack < Tuple < Token , int > > ( ) ;
7068
7169 // TODO move part common with PlaceOpenBrace to one place
72- // TODO use a general switch to ignore blocks on one line
7370 var tokenOps = new TokenOperations ( tokens , ast ) ;
7471 tokensToIgnore = new HashSet < Token > ( tokenOps . GetCloseBracesInCommandElements ( ) ) ;
75- if ( IgnoreOneLineIf )
72+
73+ // Ignore open braces that are part of a one line if-else statement
74+ // E.g. $x = if ($true) { "blah" } else { "blah blah" }
75+ if ( IgnoreOneLineBlock )
7676 {
77- foreach ( var closeBraceToken in tokenOps . GetCloseBraceInOneLineIfStatement ( ) )
77+ foreach ( var pair in tokenOps . GetBracePairsOnSameLine ( ) )
7878 {
79- tokensToIgnore . Add ( closeBraceToken ) ;
79+ tokensToIgnore . Add ( pair . Item2 ) ;
8080 }
8181 }
8282
0 commit comments