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