Skip to content

Commit c8a5395

Browse files
committed
Fix severity ignore case bug
1 parent 30f434b commit c8a5395

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

Engine/Commands/GetScriptAnalyzerRuleCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected override void ProcessRecord()
142142
{
143143
if (severity != null)
144144
{
145-
var ruleSeverity = severity.Select(item => Enum.Parse(typeof (RuleSeverity), item));
145+
var ruleSeverity = severity.Select(item => Enum.Parse(typeof (RuleSeverity), item, true));
146146
rules = rules.Where(item => ruleSeverity.Contains(item.GetSeverity())).ToList();
147147
}
148148

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ private void AnalyzeFile(string filePath)
601601

602602
if (severity != null)
603603
{
604-
var diagSeverity = severity.Select(item => Enum.Parse(typeof(DiagnosticSeverity), item));
604+
var diagSeverity = severity.Select(item => Enum.Parse(typeof(DiagnosticSeverity), item, true));
605605
diagnostics = diagnostics.Where(item => diagSeverity.Contains(item.Severity)).ToList();
606606
}
607607

Tests/Engine/GetScriptAnalyzerRule.tests.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,17 @@ Describe "Test RuleExtension" {
113113
Describe "TestSeverity" {
114114
It "filters rules based on the specified rule severity" {
115115
$rules = Get-ScriptAnalyzerRule -Severity Error
116-
$rules.Count | Should be 4
116+
$rules.Count | Should be 6
117117
}
118118

119119
It "filters rules based on multiple severity inputs"{
120120
$rules = Get-ScriptAnalyzerRule -Severity Error,Information
121-
$rules.Count | Should be 8
121+
$rules.Count | Should be 9
122+
}
123+
124+
It "takes lower case inputs" {
125+
$rules = Get-ScriptAnalyzerRule -Severity error
126+
$rules.Count | Should be 6
122127
}
123128
}
124129

@@ -130,6 +135,6 @@ Describe "TestWildCard" {
130135

131136
It "filters rules based on wild card input and severity"{
132137
$rules = Get-ScriptAnalyzerRule -Name PSDSC* -Severity Information
133-
$rules.Count | Should be 2
138+
$rules.Count | Should be 1
134139
}
135140
}

Tests/Engine/InvokeScriptAnalyzer.tests.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ Describe "Test Severity" {
169169
$errors = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -Severity Information, Warning
170170
$errors.Count | Should Be 2
171171
}
172+
173+
It "works with lowercase argument"{
174+
$errors = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -Severity information, warning
175+
$errors.Count | Should Be 2
176+
}
172177
}
173178

174179
Context "When used incorrectly" {

0 commit comments

Comments
 (0)