From 9ce81fe285399513f2414d3a6d2393243a842b3b Mon Sep 17 00:00:00 2001 From: Kapil Borle Date: Wed, 16 Mar 2016 13:12:00 -0700 Subject: [PATCH 1/6] 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. --- Engine/Generic/AvoidParameterGeneric.cs | 12 +++++++++++- Rules/AvoidUsingComputerNameHardcoded.cs | 9 +++++++++ .../AvoidUsingConvertToSecureStringWithPlainText.cs | 11 ++++++++++- Tests/Engine/GetScriptAnalyzerRule.tests.ps1 | 6 +++--- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Engine/Generic/AvoidParameterGeneric.cs b/Engine/Generic/AvoidParameterGeneric.cs index 2f108b07d..039994c1f 100644 --- a/Engine/Generic/AvoidParameterGeneric.cs +++ b/Engine/Generic/AvoidParameterGeneric.cs @@ -44,7 +44,7 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) { if (ParameterCondition(cmdAst, ceAst)) { - yield return new DiagnosticRecord(GetError(fileName, cmdAst), cmdAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName, cmdAst.GetCommandName()); + yield return new DiagnosticRecord(GetError(fileName, cmdAst), cmdAst.Extent, GetName(), GetDiagnosticSeverity(), fileName, cmdAst.GetCommandName()); } } } @@ -102,6 +102,16 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) /// The source type of the rule. public abstract SourceType GetSourceType(); + /// + /// RuleSeverity: Returns the severity of the rule. + /// + /// public abstract RuleSeverity GetSeverity(); + + /// + /// DiagnosticSeverity: Returns the severity of the rule of type DiagnosticSeverity + /// + /// + public abstract DiagnosticSeverity GetDiagnosticSeverity(); } } diff --git a/Rules/AvoidUsingComputerNameHardcoded.cs b/Rules/AvoidUsingComputerNameHardcoded.cs index 95ec0a454..58f49fe1a 100644 --- a/Rules/AvoidUsingComputerNameHardcoded.cs +++ b/Rules/AvoidUsingComputerNameHardcoded.cs @@ -149,6 +149,15 @@ public override RuleSeverity GetSeverity() return RuleSeverity.Error; } + /// + /// DiagnosticSeverity: Retrieves the severity of the rule of type DiagnosticSeverity: error, warning of information. + /// + /// + public override DiagnosticSeverity GetDiagnosticSeverity() + { + return DiagnosticSeverity.Error; + } + /// /// GetSourceName: Retrieves the module/assembly name the rule is from. /// diff --git a/Rules/AvoidUsingConvertToSecureStringWithPlainText.cs b/Rules/AvoidUsingConvertToSecureStringWithPlainText.cs index 0105680c8..378f5fe77 100644 --- a/Rules/AvoidUsingConvertToSecureStringWithPlainText.cs +++ b/Rules/AvoidUsingConvertToSecureStringWithPlainText.cs @@ -113,7 +113,16 @@ public override SourceType GetSourceType() /// public override RuleSeverity GetSeverity() { - return RuleSeverity.Error; + return RuleSeverity.Warning; + } + + /// + /// DiagnosticSeverity: Retrieves the severity of the rule of type DiagnosticSeverity: error, warning of information. + /// + /// + public override DiagnosticSeverity GetDiagnosticSeverity() + { + return DiagnosticSeverity.Warning; } /// diff --git a/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 b/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 index ef2cefc31..b4c78d797 100644 --- a/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 +++ b/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 @@ -126,17 +126,17 @@ Describe "Test RuleExtension" { Describe "TestSeverity" { It "filters rules based on the specified rule severity" { $rules = Get-ScriptAnalyzerRule -Severity Error - $rules.Count | Should be 6 + $rules.Count | Should be 5 } It "filters rules based on multiple severity inputs"{ $rules = Get-ScriptAnalyzerRule -Severity Error,Information - $rules.Count | Should be 13 + $rules.Count | Should be 12 } It "takes lower case inputs" { $rules = Get-ScriptAnalyzerRule -Severity error - $rules.Count | Should be 6 + $rules.Count | Should be 5 } } From 159a394a608538aac719a5859850deee38b9276b Mon Sep 17 00:00:00 2001 From: Kapil Borle Date: Wed, 16 Mar 2016 17:02:48 -0700 Subject: [PATCH 2/6] Set the severity level of AvoidUsingConvertToSecureStringWithPlainText --- Rules/AvoidUsingConvertToSecureStringWithPlainText.cs | 4 ++-- Tests/Engine/GetScriptAnalyzerRule.tests.ps1 | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Rules/AvoidUsingConvertToSecureStringWithPlainText.cs b/Rules/AvoidUsingConvertToSecureStringWithPlainText.cs index 378f5fe77..4371f57d7 100644 --- a/Rules/AvoidUsingConvertToSecureStringWithPlainText.cs +++ b/Rules/AvoidUsingConvertToSecureStringWithPlainText.cs @@ -113,7 +113,7 @@ public override SourceType GetSourceType() /// public override RuleSeverity GetSeverity() { - return RuleSeverity.Warning; + return RuleSeverity.Error; } /// @@ -122,7 +122,7 @@ public override RuleSeverity GetSeverity() /// public override DiagnosticSeverity GetDiagnosticSeverity() { - return DiagnosticSeverity.Warning; + return DiagnosticSeverity.Error; } /// diff --git a/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 b/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 index b4c78d797..ef2cefc31 100644 --- a/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 +++ b/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 @@ -126,17 +126,17 @@ Describe "Test RuleExtension" { Describe "TestSeverity" { It "filters rules based on the specified rule severity" { $rules = Get-ScriptAnalyzerRule -Severity Error - $rules.Count | Should be 5 + $rules.Count | Should be 6 } It "filters rules based on multiple severity inputs"{ $rules = Get-ScriptAnalyzerRule -Severity Error,Information - $rules.Count | Should be 12 + $rules.Count | Should be 13 } It "takes lower case inputs" { $rules = Get-ScriptAnalyzerRule -Severity error - $rules.Count | Should be 5 + $rules.Count | Should be 6 } } From e0a5cb66a44ed5dcce73f710c07514cdb0634fc8 Mon Sep 17 00:00:00 2001 From: Kapil Borle Date: Mon, 21 Mar 2016 15:36:54 -0700 Subject: [PATCH 3/6] Fix the severity level of UseIdenticalParametersDSC rule. --- Rules/UseIdenticalParametersDSC.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rules/UseIdenticalParametersDSC.cs b/Rules/UseIdenticalParametersDSC.cs index 99b9fac5e..f7eb69453 100644 --- a/Rules/UseIdenticalParametersDSC.cs +++ b/Rules/UseIdenticalParametersDSC.cs @@ -53,7 +53,7 @@ public IEnumerable AnalyzeDSCResource(Ast ast, string fileName if (funcParamAsts.Count() != funcParamAsts2.Count()) { yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.UseIdenticalParametersDSCError), - firstFunc.Extent, GetName(), DiagnosticSeverity.Information, fileName); + firstFunc.Extent, GetName(), DiagnosticSeverity.Error, fileName); } foreach (ParameterAst paramAst in funcParamAsts) From 8c15ac901d35f5454edb232f9e6cdffe468d5107 Mon Sep 17 00:00:00 2001 From: Kapil Borle Date: Mon, 21 Mar 2016 15:45:39 -0700 Subject: [PATCH 4/6] Add an abstract method to retrieve DiagnosticSeverity in AvoidCmdletGeneric class --- Engine/Generic/AvoidCmdletGeneric.cs | 8 +++++++- Rules/AvoidUsingInvokeExpression.cs | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Engine/Generic/AvoidCmdletGeneric.cs b/Engine/Generic/AvoidCmdletGeneric.cs index b23d85679..7a54d7331 100644 --- a/Engine/Generic/AvoidCmdletGeneric.cs +++ b/Engine/Generic/AvoidCmdletGeneric.cs @@ -45,7 +45,7 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) if (cmdletNameAndAliases.Contains(cmdAst.GetCommandName(), StringComparer.OrdinalIgnoreCase)) { - yield return new DiagnosticRecord(GetError(fileName), cmdAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName); + yield return new DiagnosticRecord(GetError(fileName), cmdAst.Extent, GetName(), GetDiagnosticSeverity(), fileName); } } } @@ -97,5 +97,11 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) /// /// public abstract RuleSeverity GetSeverity(); + + /// + /// DiagnosticSeverity: Returns the severity of the rule of type DiagnosticSeverity + /// + /// + public abstract DiagnosticSeverity GetDiagnosticSeverity(); } } diff --git a/Rules/AvoidUsingInvokeExpression.cs b/Rules/AvoidUsingInvokeExpression.cs index 597383495..c91fd2ad1 100644 --- a/Rules/AvoidUsingInvokeExpression.cs +++ b/Rules/AvoidUsingInvokeExpression.cs @@ -85,6 +85,15 @@ public override RuleSeverity GetSeverity() return RuleSeverity.Warning; } + /// + /// DiagnosticSeverity: Retrieves the severity of the rule of type DiagnosticSeverity: error, warning or information. + /// + /// + public override DiagnosticSeverity GetDiagnosticSeverity() + { + return DiagnosticSeverity.Warning; + } + /// /// Method: Retrieves the module/assembly name the rule is from. /// From b66e1ccf2597fbe217afc7b70d3d1036b20402a1 Mon Sep 17 00:00:00 2001 From: Kapil Borle Date: Mon, 21 Mar 2016 15:46:14 -0700 Subject: [PATCH 5/6] Fix typos in source comments --- Rules/AvoidUsingComputerNameHardcoded.cs | 4 ++-- Rules/AvoidUsingConvertToSecureStringWithPlainText.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Rules/AvoidUsingComputerNameHardcoded.cs b/Rules/AvoidUsingComputerNameHardcoded.cs index 58f49fe1a..869a27f09 100644 --- a/Rules/AvoidUsingComputerNameHardcoded.cs +++ b/Rules/AvoidUsingComputerNameHardcoded.cs @@ -141,7 +141,7 @@ public override SourceType GetSourceType() } /// - /// GetSeverity: Retrieves the severity of the rule: error, warning of information. + /// GetSeverity: Retrieves the severity of the rule: error, warning or information. /// /// public override RuleSeverity GetSeverity() @@ -150,7 +150,7 @@ public override RuleSeverity GetSeverity() } /// - /// DiagnosticSeverity: Retrieves the severity of the rule of type DiagnosticSeverity: error, warning of information. + /// DiagnosticSeverity: Retrieves the severity of the rule of type DiagnosticSeverity: error, warning or information. /// /// public override DiagnosticSeverity GetDiagnosticSeverity() diff --git a/Rules/AvoidUsingConvertToSecureStringWithPlainText.cs b/Rules/AvoidUsingConvertToSecureStringWithPlainText.cs index 4371f57d7..b7bafde15 100644 --- a/Rules/AvoidUsingConvertToSecureStringWithPlainText.cs +++ b/Rules/AvoidUsingConvertToSecureStringWithPlainText.cs @@ -108,7 +108,7 @@ public override SourceType GetSourceType() } /// - /// GetSeverity: Retrieves the severity of the rule: error, warning of information. + /// GetSeverity: Retrieves the severity of the rule: error, warning or information. /// /// public override RuleSeverity GetSeverity() @@ -117,7 +117,7 @@ public override RuleSeverity GetSeverity() } /// - /// DiagnosticSeverity: Retrieves the severity of the rule of type DiagnosticSeverity: error, warning of information. + /// DiagnosticSeverity: Retrieves the severity of the rule of type DiagnosticSeverity: error, warning or information. /// /// public override DiagnosticSeverity GetDiagnosticSeverity() From 8334c5e7543aea614ead712bc2c16957b88d7a4c Mon Sep 17 00:00:00 2001 From: Kapil Borle Date: Mon, 21 Mar 2016 15:47:56 -0700 Subject: [PATCH 6/6] Move AvoidUsingFilePaths and AvoidUnloadableModule to deprecated rules folder --- {Rules => DeprecatedRules}/AvoidUnloadableModule.cs | 0 {Rules => DeprecatedRules}/AvoidUsingFilePaths.cs | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {Rules => DeprecatedRules}/AvoidUnloadableModule.cs (100%) rename {Rules => DeprecatedRules}/AvoidUsingFilePaths.cs (100%) diff --git a/Rules/AvoidUnloadableModule.cs b/DeprecatedRules/AvoidUnloadableModule.cs similarity index 100% rename from Rules/AvoidUnloadableModule.cs rename to DeprecatedRules/AvoidUnloadableModule.cs diff --git a/Rules/AvoidUsingFilePaths.cs b/DeprecatedRules/AvoidUsingFilePaths.cs similarity index 100% rename from Rules/AvoidUsingFilePaths.cs rename to DeprecatedRules/AvoidUsingFilePaths.cs