@@ -122,21 +122,21 @@ $x = if ($true) { "blah" } else { "blah blah" }
122
122
123
123
Context " When a close brace should be follow a new line" {
124
124
BeforeAll {
125
+ $ruleConfiguration .' NoEmptyLineBefore' = $false
126
+ $ruleConfiguration .' IgnoreOneLineBlock' = $false
127
+ $ruleConfiguration .' NewLineAfter' = $true
128
+ }
129
+
130
+ It " Should find a violation for a close brace followed by else" {
125
131
$def = @'
126
132
if (Test-Path "blah") {
127
133
"blah"
128
134
} else {
129
135
"blah blah"
130
136
}
131
137
'@
132
- $ruleConfiguration .' NoEmptyLineBefore' = $false
133
- $ruleConfiguration .' IgnoreOneLineBlock' = $false
134
- $ruleConfiguration .' NewLineAfter' = $true
135
138
$violations = Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings
136
- }
137
-
138
- It " Should find two violations" {
139
- $violations.Count | Should Be 2
139
+ $violations.Count | Should Be 1
140
140
$params = @ {
141
141
RawContent = $def
142
142
DiagnosticRecord = $violations [0 ]
@@ -145,15 +145,48 @@ if (Test-Path "blah") {
145
145
CorrectionText = ' }' + [System.Environment ]::NewLine
146
146
}
147
147
Test-CorrectionExtentFromContent @params
148
+ }
148
149
150
+ It " Should find a violation for a close brace followed by elseif" {
151
+ $def = @'
152
+ if (Test-Path "blah") {
153
+ "blah"
154
+ } elseif (Test-Path "blah blah") {
155
+ "blah blah"
156
+ }
157
+ '@
158
+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings
159
+ $violations.Count | Should Be 1
149
160
$params = @ {
150
161
RawContent = $def
151
- DiagnosticRecord = $violations [1 ]
162
+ DiagnosticRecord = $violations [0 ]
152
163
CorrectionsCount = 1
153
164
ViolationText = ' }'
154
165
CorrectionText = ' }' + [System.Environment ]::NewLine
155
166
}
156
167
Test-CorrectionExtentFromContent @params
157
168
}
169
+
170
+ It " Should not find a violation for a close brace followed by a comma in an array expression" {
171
+ $def = @'
172
+ Some-Command -Param1 @{
173
+ key1="value1"
174
+ },@{
175
+ key2="value2"
176
+ }
177
+ '@
178
+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings
179
+ $violations.Count | Should Be 0
180
+ }
181
+
182
+ It " Should not find a violation for a close brace followed by parameter in a command expression" {
183
+ $def = @'
184
+ Some-Command -Param1 @{
185
+ key="value"
186
+ } -Param2
187
+ '@
188
+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings
189
+ $violations.Count | Should Be 0
190
+ }
158
191
}
159
192
}
0 commit comments