File tree 2 files changed +19
-4
lines changed 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -164,6 +164,7 @@ internal enum PreferenceVariable
164
164
internal const string Null = "null" ;
165
165
internal const string True = "true" ;
166
166
internal const string False = "false" ;
167
+ internal const string LastExitCode = "LastExitCode" ;
167
168
168
169
internal static readonly string [ ] OtherInitializedVariables = new string [ ]
169
170
{
@@ -184,7 +185,8 @@ internal enum PreferenceVariable
184
185
pwd ,
185
186
Null ,
186
187
True ,
187
- False
188
+ False ,
189
+ LastExitCode
188
190
} ;
189
191
190
192
}
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ Describe "AvoidGlobalVars" {
28
28
It " has 1 avoid using global variable violation" {
29
29
$globalViolations.Count | Should Be 1
30
30
}
31
-
31
+
32
32
<#
33
33
# PSAvoidUninitializedVariable rule has been deprecated
34
34
It "has 4 violations for dsc resources (not counting the variables in parameters)" {
@@ -47,6 +47,19 @@ Describe "AvoidGlobalVars" {
47
47
$noGlobalViolations.Count | Should Be 0
48
48
}
49
49
}
50
+
51
+ Context " When a script contains global:lastexitcode" {
52
+ It " returns no violation" {
53
+ $def = @'
54
+ if ($global:lastexitcode -ne 0)
55
+ {
56
+ exit
57
+ }
58
+ '@
59
+ $local :violations = Invoke-ScriptAnalyzer - ScriptDefinition $def - IncludeRule $globalName
60
+ $local :violations.Count | Should Be 0
61
+ }
62
+ }
50
63
}
51
64
52
65
<#
@@ -66,6 +79,6 @@ Describe "AvoidUnitializedVars" {
66
79
It "returns no violations" {
67
80
$noUninitializedViolations.Count | Should Be 0
68
81
}
69
- }
82
+ }
70
83
}
71
- #>
84
+ #>
You can’t perform that action at this time.
0 commit comments