Skip to content

Commit 9ce81fe

Browse files
author
Kapil Borle
committed
Remove severity inconsistency for AvoidUsingConvertToSecureStringWithPlainText rule.
The severity showed by Get-ScriptAnalyzerRule and Invoke-ScriptAnalyzer for this rule were different. This was because scriptanalyzer defines two types of severities, viz., RuleSeverity and DiagnosticSeverity and the severity levels were not consistent. This commit makes the severity level consistent by setting them both to Warning.
1 parent d43a478 commit 9ce81fe

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

Engine/Generic/AvoidParameterGeneric.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
4444
{
4545
if (ParameterCondition(cmdAst, ceAst))
4646
{
47-
yield return new DiagnosticRecord(GetError(fileName, cmdAst), cmdAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName, cmdAst.GetCommandName());
47+
yield return new DiagnosticRecord(GetError(fileName, cmdAst), cmdAst.Extent, GetName(), GetDiagnosticSeverity(), fileName, cmdAst.GetCommandName());
4848
}
4949
}
5050
}
@@ -102,6 +102,16 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
102102
/// <returns>The source type of the rule.</returns>
103103
public abstract SourceType GetSourceType();
104104

105+
/// <summary>
106+
/// RuleSeverity: Returns the severity of the rule.
107+
/// </summary>
108+
/// <returns></returns>
105109
public abstract RuleSeverity GetSeverity();
110+
111+
/// <summary>
112+
/// DiagnosticSeverity: Returns the severity of the rule of type DiagnosticSeverity
113+
/// </summary>
114+
/// <returns></returns>
115+
public abstract DiagnosticSeverity GetDiagnosticSeverity();
106116
}
107117
}

Rules/AvoidUsingComputerNameHardcoded.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ public override RuleSeverity GetSeverity()
149149
return RuleSeverity.Error;
150150
}
151151

152+
/// <summary>
153+
/// DiagnosticSeverity: Retrieves the severity of the rule of type DiagnosticSeverity: error, warning of information.
154+
/// </summary>
155+
/// <returns></returns>
156+
public override DiagnosticSeverity GetDiagnosticSeverity()
157+
{
158+
return DiagnosticSeverity.Error;
159+
}
160+
152161
/// <summary>
153162
/// GetSourceName: Retrieves the module/assembly name the rule is from.
154163
/// </summary>

Rules/AvoidUsingConvertToSecureStringWithPlainText.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,16 @@ public override SourceType GetSourceType()
113113
/// <returns></returns>
114114
public override RuleSeverity GetSeverity()
115115
{
116-
return RuleSeverity.Error;
116+
return RuleSeverity.Warning;
117+
}
118+
119+
/// <summary>
120+
/// DiagnosticSeverity: Retrieves the severity of the rule of type DiagnosticSeverity: error, warning of information.
121+
/// </summary>
122+
/// <returns></returns>
123+
public override DiagnosticSeverity GetDiagnosticSeverity()
124+
{
125+
return DiagnosticSeverity.Warning;
117126
}
118127

119128
/// <summary>

Tests/Engine/GetScriptAnalyzerRule.tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ Describe "Test RuleExtension" {
126126
Describe "TestSeverity" {
127127
It "filters rules based on the specified rule severity" {
128128
$rules = Get-ScriptAnalyzerRule -Severity Error
129-
$rules.Count | Should be 6
129+
$rules.Count | Should be 5
130130
}
131131

132132
It "filters rules based on multiple severity inputs"{
133133
$rules = Get-ScriptAnalyzerRule -Severity Error,Information
134-
$rules.Count | Should be 13
134+
$rules.Count | Should be 12
135135
}
136136

137137
It "takes lower case inputs" {
138138
$rules = Get-ScriptAnalyzerRule -Severity error
139-
$rules.Count | Should be 6
139+
$rules.Count | Should be 5
140140
}
141141
}
142142

0 commit comments

Comments
 (0)