From b9f114916ff97bdc9f5d2c571085934592561623 Mon Sep 17 00:00:00 2001 From: ewisniew0 Date: Tue, 22 Nov 2022 18:43:27 +0000 Subject: [PATCH] add ErrorView to SpecialVars and create test --- Engine/SpecialVars.cs | 5 ++++- Tests/Rules/UseDeclaredVarsMoreThanAssignments.tests.ps1 | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Engine/SpecialVars.cs b/Engine/SpecialVars.cs index 26f1afcf7..64945d1c2 100644 --- a/Engine/SpecialVars.cs +++ b/Engine/SpecialVars.cs @@ -91,6 +91,7 @@ static SpecialVars() internal const string ConfirmPreference = "ConfirmPreference"; internal const string ProgressPreference = "ProgressPreference"; internal const string InformationPreference = "InformationPreference"; + internal const string ErrorView = "ErrorView"; internal static readonly string[] PreferenceVariables = new string[] { @@ -101,7 +102,8 @@ static SpecialVars() WarningPreference, ConfirmPreference, ProgressPreference, - InformationPreference + InformationPreference, + ErrorView }; internal static readonly Type[] PreferenceVariableTypes = new Type[] @@ -114,6 +116,7 @@ static SpecialVars() /* ConfirmPreference */ typeof(ConfirmImpact), /* ProgressPreference */ typeof(Enum), /* InformationPreference */ typeof(ActionPreference), + /* ErrorView */ typeof(ErrorView), }; internal enum AutomaticVariable diff --git a/Tests/Rules/UseDeclaredVarsMoreThanAssignments.tests.ps1 b/Tests/Rules/UseDeclaredVarsMoreThanAssignments.tests.ps1 index 983ac017f..823334afb 100644 --- a/Tests/Rules/UseDeclaredVarsMoreThanAssignments.tests.ps1 +++ b/Tests/Rules/UseDeclaredVarsMoreThanAssignments.tests.ps1 @@ -72,6 +72,11 @@ function MyFunc2() { } Context "When there are no violations" { + It "No warning is issued for assignment without use of preference variable ErrorView" { + $results = Invoke-ScriptAnalyzer -ScriptDefinition '$ErrorView = NormalView' + $results.Count | Should -Be 0 + } + It "returns no violations" { $noViolations.Count | Should -Be 0 }