@@ -37,7 +37,7 @@ public class PlaceCloseBrace : ConfigurableRule
37
37
public bool NoEmptyLineBefore { get ; protected set ; }
38
38
39
39
[ ConfigurableRuleProperty ( defaultValue : true ) ]
40
- public bool IgnoreOneLineIf { get ; protected set ; }
40
+ public bool IgnoreOneLineBlock { get ; protected set ; }
41
41
42
42
private HashSet < Token > tokensToIgnore ;
43
43
@@ -61,22 +61,22 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
61
61
62
62
// TODO Should have the following options
63
63
// * 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)
66
64
67
65
var tokens = Helper . Instance . Tokens ;
68
66
var diagnosticRecords = new List < DiagnosticRecord > ( ) ;
69
67
var curlyStack = new Stack < Tuple < Token , int > > ( ) ;
70
68
71
69
// TODO move part common with PlaceOpenBrace to one place
72
- // TODO use a general switch to ignore blocks on one line
73
70
var tokenOps = new TokenOperations ( tokens , ast ) ;
74
71
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 )
76
76
{
77
- foreach ( var closeBraceToken in tokenOps . GetCloseBraceInOneLineIfStatement ( ) )
77
+ foreach ( var pair in tokenOps . GetBracePairsOnSameLine ( ) )
78
78
{
79
- tokensToIgnore . Add ( closeBraceToken ) ;
79
+ tokensToIgnore . Add ( pair . Item2 ) ;
80
80
}
81
81
}
82
82
0 commit comments