diff --git a/Engine/Commands/GetScriptAnalyzerRuleCommand.cs b/Engine/Commands/GetScriptAnalyzerRuleCommand.cs index 60ee1c607..7a9d50561 100644 --- a/Engine/Commands/GetScriptAnalyzerRuleCommand.cs +++ b/Engine/Commands/GetScriptAnalyzerRuleCommand.cs @@ -116,7 +116,7 @@ protected override void ProcessRecord() foreach (IRule rule in rules) { WriteObject(new RuleInfo(rule.GetName(), rule.GetCommonName(), rule.GetDescription(), - rule.GetSourceType(), rule.GetSourceName(), rule.GetSeverity())); + rule.GetSourceType(), rule.GetSourceName(), rule.GetSeverity(), rule.GetType())); } } } diff --git a/Engine/Generic/RuleInfo.cs b/Engine/Generic/RuleInfo.cs index 4f65db1aa..755d16d15 100644 --- a/Engine/Generic/RuleInfo.cs +++ b/Engine/Generic/RuleInfo.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; using System.Diagnostics.CodeAnalysis; namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic @@ -16,6 +17,7 @@ public class RuleInfo private SourceType sourceType; private string sourceName; private RuleSeverity ruleSeverity; + private Type implementingType; /// /// Name: The name of the rule. @@ -50,7 +52,7 @@ public string Description /// /// SourceType: The source type of the rule. /// - /// + /// [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] public SourceType SourceType { @@ -78,6 +80,16 @@ public RuleSeverity Severity private set { ruleSeverity = value; } } + /// + /// ImplementingType : The type which implements the rule. + /// + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public Type ImplementingType + { + get { return implementingType; } + private set { implementingType = value; } + } + /// /// Constructor for a RuleInfo. /// @@ -93,12 +105,32 @@ public RuleInfo(string name, string commonName, string description, SourceType s Description = description; SourceType = sourceType; SourceName = sourceName; - Severity = severity; + Severity = severity; + } + + /// + /// Constructor for a RuleInfo. + /// + /// Name of the rule. + /// Common Name of the rule. + /// Description of the rule. + /// Source type of the rule. + /// Source name of the rule. + /// The dotnet type of the rule. + public RuleInfo(string name, string commonName, string description, SourceType sourceType, string sourceName, RuleSeverity severity, Type implementingType) + { + RuleName = name; + CommonName = commonName; + Description = description; + SourceType = sourceType; + SourceName = sourceName; + Severity = severity; + ImplementingType = implementingType; } public override string ToString() { return RuleName; - } + } } } diff --git a/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 b/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 index dffd4e75c..668590672 100644 --- a/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 +++ b/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 @@ -177,3 +177,11 @@ Describe "TestWildCard" { $rules.Count | Should -Be 4 } } + +Describe "TestImplementingType" { + It "retrieves rule which have an implementing type" { + $rule = Get-ScriptAnalyzerRule PSPlaceCloseBrace + $type = $rule.ImplementingType + $type.BaseType.Name | Should -Be "ConfigurableRule" + } +}