Skip to content

Commit a7dbee1

Browse files
authored
Merge pull request #1250 from JamesWTruher/RuleInfoEnhancement001
Add ImplementingType to RuleInfo object
2 parents a9b3d64 + 05cf516 commit a7dbee1

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

Engine/Commands/GetScriptAnalyzerRuleCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected override void ProcessRecord()
116116
foreach (IRule rule in rules)
117117
{
118118
WriteObject(new RuleInfo(rule.GetName(), rule.GetCommonName(), rule.GetDescription(),
119-
rule.GetSourceType(), rule.GetSourceName(), rule.GetSeverity()));
119+
rule.GetSourceType(), rule.GetSourceName(), rule.GetSeverity(), rule.GetType()));
120120
}
121121
}
122122
}

Engine/Generic/RuleInfo.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System;
45
using System.Diagnostics.CodeAnalysis;
56

67
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
@@ -16,6 +17,7 @@ public class RuleInfo
1617
private SourceType sourceType;
1718
private string sourceName;
1819
private RuleSeverity ruleSeverity;
20+
private Type implementingType;
1921

2022
/// <summary>
2123
/// Name: The name of the rule.
@@ -50,7 +52,7 @@ public string Description
5052
/// <summary>
5153
/// SourceType: The source type of the rule.
5254
/// </summary>
53-
///
55+
///
5456
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
5557
public SourceType SourceType
5658
{
@@ -78,6 +80,16 @@ public RuleSeverity Severity
7880
private set { ruleSeverity = value; }
7981
}
8082

83+
/// <summary>
84+
/// ImplementingType : The type which implements the rule.
85+
/// </summary>
86+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
87+
public Type ImplementingType
88+
{
89+
get { return implementingType; }
90+
private set { implementingType = value; }
91+
}
92+
8193
/// <summary>
8294
/// Constructor for a RuleInfo.
8395
/// </summary>
@@ -93,12 +105,32 @@ public RuleInfo(string name, string commonName, string description, SourceType s
93105
Description = description;
94106
SourceType = sourceType;
95107
SourceName = sourceName;
96-
Severity = severity;
108+
Severity = severity;
109+
}
110+
111+
/// <summary>
112+
/// Constructor for a RuleInfo.
113+
/// </summary>
114+
/// <param name="name">Name of the rule.</param>
115+
/// <param name="commonName">Common Name of the rule.</param>
116+
/// <param name="description">Description of the rule.</param>
117+
/// <param name="sourceType">Source type of the rule.</param>
118+
/// <param name="sourceName">Source name of the rule.</param>
119+
/// <param name="implementingType">The dotnet type of the rule.</param>
120+
public RuleInfo(string name, string commonName, string description, SourceType sourceType, string sourceName, RuleSeverity severity, Type implementingType)
121+
{
122+
RuleName = name;
123+
CommonName = commonName;
124+
Description = description;
125+
SourceType = sourceType;
126+
SourceName = sourceName;
127+
Severity = severity;
128+
ImplementingType = implementingType;
97129
}
98130

99131
public override string ToString()
100132
{
101133
return RuleName;
102-
}
134+
}
103135
}
104136
}

Tests/Engine/GetScriptAnalyzerRule.tests.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,11 @@ Describe "TestWildCard" {
177177
$rules.Count | Should -Be 4
178178
}
179179
}
180+
181+
Describe "TestImplementingType" {
182+
It "retrieves rule which have an implementing type" {
183+
$rule = Get-ScriptAnalyzerRule PSPlaceCloseBrace
184+
$type = $rule.ImplementingType
185+
$type.BaseType.Name | Should -Be "ConfigurableRule"
186+
}
187+
}

0 commit comments

Comments
 (0)