33
44BeforeAll {
55 $ruleName = ' PSUseConsistentParameterSetName'
6+
7+ $ruleSettings = @ {
8+ Enable = $true
9+ }
10+ $settings = @ {
11+ IncludeRules = @ ($ruleName )
12+ Rules = @ { $ruleName = $ruleSettings }
13+ }
614}
715
816Describe " UseConsistentParameterSetName" {
@@ -20,7 +28,7 @@ function Test-Function {
2028 )
2129}
2230'@
23- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
31+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
2432 $violations.Count | Should - Be 1
2533 $violations [0 ].Severity | Should - Be ' Warning'
2634 $violations [0 ].Message | Should -Match " DefaultParameterSetName 'SetOne' does not match the case of ParameterSetName 'setone'"
@@ -39,7 +47,7 @@ function Test-Function {
3947 )
4048}
4149'@
42- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
50+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
4351 $violations.Count | Should - Be 2
4452 $violations | ForEach-Object { $_.Severity | Should - Be ' Warning' }
4553 }
@@ -62,7 +70,7 @@ function Test-Function {
6270 )
6371}
6472'@
65- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
73+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
6674 $violations.Count | Should - Be 1
6775 $violations [0 ].Severity | Should - Be ' Warning'
6876 $violations [0 ].Message | Should -Match " ParameterSetName 'setone' does not match the case of 'SetOne'"
@@ -83,7 +91,7 @@ function Test-Function {
8391 )
8492}
8593'@
86- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
94+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
8795 $violations.Count | Should - Be 2 # Two mismatches with the first occurrence
8896 $violations | ForEach-Object { $_.Severity | Should - Be ' Warning' }
8997 }
@@ -103,7 +111,7 @@ function Test-Function {
103111 )
104112}
105113'@
106- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
114+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
107115 $violations.Count | Should - Be 1
108116 $violations [0 ].Severity | Should - Be ' Warning'
109117 $violations [0 ].Message | Should -Match " uses parameter sets but does not specify a DefaultParameterSetName"
@@ -121,7 +129,7 @@ function Test-Function {
121129 )
122130}
123131'@
124- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
132+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
125133 $violations.Count | Should - Be 2
126134 $violations | ForEach-Object { $_.Message | Should - Be " Parameter 'Parameter1' is declared in parameter-set 'SetOne' multiple times." }
127135 }
@@ -136,7 +144,7 @@ function Test-Function {
136144 )
137145}
138146'@
139- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
147+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
140148 $violations.Count | Should - Be 2
141149 $violations | ForEach-Object { $_.Message | Should - Be " Parameter 'Parameter1' is declared in parameter-set '__AllParameterSets' multiple times." }
142150 }
@@ -151,7 +159,7 @@ function Test-Function {
151159 )
152160}
153161'@
154- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
162+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
155163 $violations.Count | Should - Be 2
156164 $violations | ForEach-Object { $_.Message | Should - Be " Parameter 'Parameter1' is declared in parameter-set '__AllParameterSets' multiple times." }
157165 }
@@ -169,7 +177,7 @@ function Test-Function {
169177 )
170178}
171179'@
172- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
180+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
173181 $violations.Count | Should - Be 1
174182 $violations [0 ].Message | Should -Match " should not contain new lines"
175183 }
@@ -183,7 +191,7 @@ function Test-Function {
183191 )
184192}
185193'@
186- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
194+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
187195 $violations.Count | Should - Be 1
188196 $violations [0 ].Message | Should -Match " should not contain new lines"
189197 }
@@ -197,7 +205,7 @@ function Test-Function {
197205 )
198206}
199207'@
200- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
208+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
201209 $violations.Count | Should - Be 1
202210 }
203211
@@ -210,7 +218,7 @@ function Test-Function {
210218 )
211219}
212220'@
213- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
221+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
214222 $violations.Count | Should - Be 1
215223 $violations [0 ].Message | Should -Match " should not contain new lines"
216224 }
@@ -224,7 +232,7 @@ function Test-Function {
224232 )
225233}
226234'@
227- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
235+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
228236 $violations.Count | Should - Be 1
229237 $violations [0 ].Message | Should -Match " should not contain new lines"
230238 }
@@ -237,7 +245,7 @@ function Test-Function {
237245 param([string]$Parameter1)
238246}
239247'@
240- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
248+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
241249 $violations.Count | Should - Be 1
242250 }
243251
@@ -253,7 +261,7 @@ function Test-Function {
253261 )
254262}
255263'@
256- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
264+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
257265 $violations.Count | Should - Be 0
258266 }
259267
@@ -267,7 +275,7 @@ function Test-Function {
267275 )
268276}
269277'@
270- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
278+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
271279 $violations.Count | Should - Be 0
272280 }
273281
@@ -284,7 +292,7 @@ function Test-Function {
284292 )
285293}
286294'@
287- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
295+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
288296 $violations.Count | Should - Be 0
289297 }
290298
@@ -304,7 +312,7 @@ function Test-Function {
304312 )
305313}
306314'@
307- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
315+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
308316 $violations.Count | Should - Be 0
309317 }
310318
@@ -323,7 +331,7 @@ function Test-Function {
323331 )
324332}
325333'@
326- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
334+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
327335 $violations.Count | Should - Be 0
328336 }
329337
@@ -339,7 +347,7 @@ function Test-Function {
339347 )
340348}
341349'@
342- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
350+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
343351 $violations.Count | Should - Be 0
344352 }
345353 }
@@ -362,7 +370,7 @@ function Test-ComplexFunction {
362370 )
363371}
364372'@
365- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
373+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
366374 $violations.Count | Should - Be 0
367375 }
368376
@@ -383,7 +391,7 @@ function Test-ComplexFunction {
383391 )
384392}
385393'@
386- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
394+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $settings
387395 $violations.Count | Should - Be 2 # 'byname' and 'byid' case mismatches
388396 $violations | ForEach-Object { $_.Severity | Should - Be ' Warning' }
389397 }
0 commit comments