@@ -11,10 +11,18 @@ BeforeAll {
1111}
1212
1313Describe " AvoidDynamicallyCreatingVariableNames" {
14+
15+ BeforeAll {
16+ $Settings = @ {
17+ IncludeRules = @ ($ruleName )
18+ Rules = @ { $ruleName = @ { Enable = $true } }
19+ }
20+ }
21+
1422 Context " Violates" {
1523 It " Basic dynamic variable name" {
1624 $scriptDefinition = { New-Variable - Name $Test }.ToString()
17- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
25+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $Settings
1826 $violations.Count | Should - Be 1
1927 $violations.Severity | Should - Be Information
2028 $violations.Extent.Text | Should - Be {New-Variable - Name $Test }.ToString()
@@ -23,7 +31,7 @@ Describe "AvoidDynamicallyCreatingVariableNames" {
2331
2432 It " Using alias" {
2533 $scriptDefinition = { nv - Name $Test }.ToString()
26- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
34+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $Settings
2735 $violations.Count | Should - Be 1
2836 $violations.Severity | Should - Be Information
2937 $violations.Extent.Text | Should - Be {nv - Name $Test }.ToString()
@@ -32,7 +40,7 @@ Describe "AvoidDynamicallyCreatingVariableNames" {
3240
3341 It " Using uppercase" {
3442 $scriptDefinition = { NEW-VARIABLE - Name $Test }.ToString()
35- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
43+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $Settings
3644 $violations.Count | Should - Be 1
3745 $violations.Severity | Should - Be Information
3846 $violations.Extent.Text | Should - Be {NEW-VARIABLE - Name $Test }.ToString()
@@ -46,7 +54,7 @@ Describe "AvoidDynamicallyCreatingVariableNames" {
4654 }
4755 $MyTwo # returns 2
4856 }.ToString()
49- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
57+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $Settings
5058 $violations.Count | Should - Be 1
5159 $violations.Severity | Should - Be Information
5260 $violations.Extent.Text | Should - Be {New-Variable - Name " My$_ " - Value ($i ++ )}.ToString()
@@ -58,7 +66,7 @@ Describe "AvoidDynamicallyCreatingVariableNames" {
5866 $myVarName = ' foo'
5967 New-Variable $myVarName
6068 }.ToString()
61- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
69+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $Settings
6270 $violations.Count | Should - Be 1
6371 $violations.Severity | Should - Be Information
6472 $violations.Extent.Text | Should - Be {New-Variable $myVarName }.ToString()
@@ -72,7 +80,7 @@ Describe "AvoidDynamicallyCreatingVariableNames" {
7280 }
7381 $MyTwo # returns 2
7482 }.ToString()
75- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
83+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $Settings
7684 $violations.Count | Should - Be 1
7785 $violations.Severity | Should - Be Information
7886 $violations.Extent.Text | Should - Be {New-Variable " My$_ " ($i ++ )}.ToString()
@@ -89,7 +97,7 @@ Describe "AvoidDynamicallyCreatingVariableNames" {
8997 }
9098 $My.Two # returns 2
9199 }.ToString()
92- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
100+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $Settings
93101 $violations | Should - BeNullOrEmpty
94102 }
95103
@@ -101,7 +109,7 @@ Describe "AvoidDynamicallyCreatingVariableNames" {
101109 }
102110 $Script :My.Two # returns 2
103111 }.ToString()
104- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
112+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $Settings
105113 $violations | Should - BeNullOrEmpty
106114 }
107115
@@ -110,7 +118,22 @@ Describe "AvoidDynamicallyCreatingVariableNames" {
110118 New-Variable - Name ' $Sign1'
111119 New-Variable - Name ' $Sign2' - Value ' Dollar'
112120 }.ToString()
113- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ($ruleName )
121+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $Settings
122+ $violations | Should - BeNullOrEmpty
123+ }
124+ }
125+
126+ Context " Disabled" {
127+ BeforeAll {
128+ $Settings = @ {
129+ IncludeRules = @ ($ruleName )
130+ Rules = @ { $ruleName = @ { Enable = $false } }
131+ }
132+ }
133+
134+ It " ConvertFrom-SecureString -AsPlainText" {
135+ $scriptDefinition = { New-Variable - Name $Test }.ToString()
136+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $Settings
114137 $violations | Should - BeNullOrEmpty
115138 }
116139 }
@@ -122,7 +145,7 @@ Describe "AvoidDynamicallyCreatingVariableNames" {
122145 Param ()
123146 New-Variable - Name $Test
124147 }.ToString()
125- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
148+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $Settings
126149 $violations | Should - BeNullOrEmpty
127150 }
128151 It " Common dynamic variable iteration" {
@@ -134,7 +157,7 @@ Describe "AvoidDynamicallyCreatingVariableNames" {
134157 }
135158 $MyTwo # returns 2
136159 }.ToString()
137- $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ( $ruleName )
160+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - Settings $Settings
138161 $violations | Should - BeNullOrEmpty
139162 }
140163 }
0 commit comments