@@ -46,7 +46,7 @@ public class PlaceOpenBrace : ConfigurableRule
46
46
public bool NewLineAfter { get ; protected set ; }
47
47
48
48
[ ConfigurableRuleProperty ( defaultValue : true ) ]
49
- public bool IgnoreOneLineIf { get ; protected set ; }
49
+ public bool IgnoreOneLineBlock { get ; protected set ; }
50
50
51
51
private List < Func < Token [ ] , Ast , string , IEnumerable < DiagnosticRecord > > > violationFinders
52
52
= new List < Func < Token [ ] , Ast , string , IEnumerable < DiagnosticRecord > > > ( ) ;
@@ -99,18 +99,20 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
99
99
var tokens = Helper . Instance . Tokens ;
100
100
101
101
// Ignore open braces that are part of arguments to a command
102
- // * E.g. get-process | % { "blah }f
102
+ // * E.g. get-process | % { "blah }
103
103
// In the above case even if OnSameLine == false, we should not
104
104
// flag the open brace as it would move the brace to the next line
105
105
// and will invalidate the command
106
106
var tokenOps = new TokenOperations ( tokens , ast ) ;
107
107
tokensToIgnore = new HashSet < Token > ( tokenOps . GetOpenBracesInCommandElements ( ) ) ;
108
108
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 )
110
112
{
111
- foreach ( var openBraceToken in tokenOps . GetOpenBraceInOneLineIfStatement ( ) )
113
+ foreach ( var pair in tokenOps . GetBracePairsOnSameLine ( ) )
112
114
{
113
- tokensToIgnore . Add ( openBraceToken ) ;
115
+ tokensToIgnore . Add ( pair . Item1 ) ;
114
116
}
115
117
}
116
118
0 commit comments