@@ -46,7 +46,7 @@ public class PlaceOpenBrace : ConfigurableRule
4646 public bool NewLineAfter { get ; protected set ; }
4747
4848 [ ConfigurableRuleProperty ( defaultValue : true ) ]
49- public bool IgnoreOneLineIf { get ; protected set ; }
49+ public bool IgnoreOneLineBlock { get ; protected set ; }
5050
5151 private List < Func < Token [ ] , Ast , string , IEnumerable < DiagnosticRecord > > > violationFinders
5252 = new List < Func < Token [ ] , Ast , string , IEnumerable < DiagnosticRecord > > > ( ) ;
@@ -99,18 +99,20 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
9999 var tokens = Helper . Instance . Tokens ;
100100
101101 // Ignore open braces that are part of arguments to a command
102- // * E.g. get-process | % { "blah }f
102+ // * E.g. get-process | % { "blah }
103103 // In the above case even if OnSameLine == false, we should not
104104 // flag the open brace as it would move the brace to the next line
105105 // and will invalidate the command
106106 var tokenOps = new TokenOperations ( tokens , ast ) ;
107107 tokensToIgnore = new HashSet < Token > ( tokenOps . GetOpenBracesInCommandElements ( ) ) ;
108108
109- if ( IgnoreOneLineIf )
109+ // Ignore open braces that are part of a one line if-else statement
110+ // E.g. $x = if ($true) { "blah" } else { "blah blah" }
111+ if ( IgnoreOneLineBlock )
110112 {
111- foreach ( var openBraceToken in tokenOps . GetOpenBraceInOneLineIfStatement ( ) )
113+ foreach ( var pair in tokenOps . GetBracePairsOnSameLine ( ) )
112114 {
113- tokensToIgnore . Add ( openBraceToken ) ;
115+ tokensToIgnore . Add ( pair . Item1 ) ;
114116 }
115117 }
116118
0 commit comments