Skip to content

Commit dd25a91

Browse files
committed
Refactor GetSourceType method
* Refactor GetSourceType method into SourceType property. * Make code cleaner. * Unify SourceType property implementation across all rules.
1 parent a143b9f commit dd25a91

83 files changed

Lines changed: 277 additions & 719 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Engine/Commands/GetScriptAnalyzerRuleCommand.cs

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

Engine/Generic/AvoidCmdletGeneric.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
7777
/// <returns>The source name of the rule.</returns>
7878
public abstract string GetSourceName();
7979

80-
/// <summary>
81-
/// GetSourceType: Retrieves the source type of the rule.
82-
/// </summary>
83-
/// <returns>The source type of the rule.</returns>
84-
public abstract SourceType GetSourceType();
80+
public abstract RuleSourceType SourceType { get; }
8581

8682
/// <summary>
8783
/// GetSeverity: Retrieves the severity of the rule: error, warning of information.

Engine/Generic/AvoidParameterGeneric.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
8787
/// <returns>The source name of the rule.</returns>
8888
public abstract string GetSourceName();
8989

90-
/// <summary>
91-
/// GetSourceType: Retrieves the source type of the rule.
92-
/// </summary>
93-
/// <returns>The source type of the rule.</returns>
94-
public abstract SourceType GetSourceType();
90+
public abstract RuleSourceType SourceType { get; }
9591

9692
/// <summary>
9793
/// RuleSeverity: Returns the severity of the rule.

Engine/Generic/ConfigurableRule.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,7 @@ public virtual void ConfigureRule(IDictionary<string, object> paramValueMap)
103103
/// <returns>The source name of the rule.</returns>
104104
public abstract string GetSourceName();
105105

106-
/// <summary>
107-
/// Retrieves the source type of the rule.
108-
/// </summary>
109-
/// <returns>The source type of the rule.</returns>
110-
public abstract SourceType GetSourceType();
106+
public abstract RuleSourceType SourceType { get; }
111107

112108
private void SetDefaultValues()
113109
{

Engine/Generic/ExternalRule.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ public string GetParameter()
4242
return this.param;
4343
}
4444

45-
public SourceType GetSourceType()
46-
{
47-
return SourceType.Module;
48-
}
45+
public RuleSourceType SourceType => RuleSourceType.Module;
4946

5047
public string GetParameterType()
5148
{
@@ -71,7 +68,7 @@ public string GetFullModulePath()
7168
#endregion
7269

7370
#region Constructors
74-
71+
7572
public ExternalRule()
7673
{
7774

Engine/Generic/IRule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public interface IRule
3333
string GetSourceName();
3434

3535
/// <summary>
36-
/// GetSourceType: Retrieves the source type of the rule.
36+
/// SourceType: Retrieves the source type of the rule.
3737
/// </summary>
3838
/// <returns>The source type of the rule.</returns>
39-
SourceType GetSourceType();
39+
public abstract RuleSourceType SourceType { get; }
4040

4141
/// <summary>
4242
/// GetSeverity: Retrieves severity of the rule.

Engine/Generic/RuleInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class RuleInfo
1414
private string name;
1515
private string commonName;
1616
private string description;
17-
private SourceType sourceType;
17+
private RuleSourceType sourceType;
1818
private string sourceName;
1919
private RuleSeverity ruleSeverity;
2020
private Type implementingType;
@@ -54,7 +54,7 @@ public string Description
5454
/// </summary>
5555
///
5656
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
57-
public SourceType SourceType
57+
public RuleSourceType SourceType
5858
{
5959
get { return sourceType; }
6060
private set { sourceType = value; }
@@ -98,7 +98,7 @@ public Type ImplementingType
9898
/// <param name="description">Description of the rule.</param>
9999
/// <param name="sourceType">Source type of the rule.</param>
100100
/// <param name="sourceName">Source name of the rule.</param>
101-
public RuleInfo(string name, string commonName, string description, SourceType sourceType, string sourceName, RuleSeverity severity)
101+
public RuleInfo(string name, string commonName, string description, RuleSourceType sourceType, string sourceName, RuleSeverity severity)
102102
{
103103
RuleName = name;
104104
CommonName = commonName;
@@ -117,7 +117,7 @@ public RuleInfo(string name, string commonName, string description, SourceType s
117117
/// <param name="sourceType">Source type of the rule.</param>
118118
/// <param name="sourceName">Source name of the rule.</param>
119119
/// <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)
120+
public RuleInfo(string name, string commonName, string description, RuleSourceType sourceType, string sourceName, RuleSeverity severity, Type implementingType)
121121
{
122122
RuleName = name;
123123
CommonName = commonName;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
55
{
66
/// <summary>
7-
/// Represents a source name of a script analyzer rule.
7+
/// Represents a source type of a script analyzer rule.
88
/// </summary>
9-
public enum SourceType : uint
9+
public enum RuleSourceType : uint
1010
{
1111
/// <summary>
1212
/// BUILTIN: Indicates the script analyzer rule is contributed as a built-in rule.

Rules/AlignAssignmentStatement.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ var member in enumTypeDefAst.Members.Where(
481481
// Next we need to find the location of the equals sign for this
482482
// member. We know the line it should be on. We can
483483
// search all of the equals signs on that line.
484-
//
484+
//
485485
// Unlike hashtables, we don't have an extent for the LHS and
486486
// RHS of the member. We have the extent of the entire
487487
// member, the name of the member, and the extent of the
@@ -699,12 +699,6 @@ public override string GetSourceName()
699699
return string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
700700
}
701701

702-
/// <summary>
703-
/// Retrieves the type of the rule, Builtin, Managed or Module.
704-
/// </summary>
705-
public override SourceType GetSourceType()
706-
{
707-
return SourceType.Builtin;
708-
}
702+
public override RuleSourceType SourceType => RuleSourceType.Builtin;
709703
}
710704
}

Rules/AvoidAlias.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private void SetProperties()
5353
{
5454
return;
5555
}
56-
// Fallback for object from legacy allowlist argument name
56+
// Fallback for object from legacy allowlist argument name
5757
if (obj == null) {
5858
obj = objLegacy;
5959
}
@@ -260,13 +260,7 @@ public string GetDescription()
260260
return string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingCmdletAliasesDescription);
261261
}
262262

263-
/// <summary>
264-
/// GetSourceType: Retrieves the type of the rule, Builtin, Managed or Module.
265-
/// </summary>
266-
public SourceType GetSourceType()
267-
{
268-
return SourceType.Builtin;
269-
}
263+
public RuleSourceType SourceType => RuleSourceType.Builtin;
270264

271265
/// <summary>
272266
/// GetSeverity: Retrieves the severity of the rule: error, warning of information.

0 commit comments

Comments
 (0)