Skip to content

Commit 23c7f9e

Browse files
committed
Refactor GetSourceType method
* Refactor GetSourceType method into one-liner using lambda operator. * Make code cleaner removing docstrings; The main one is provided in base IRule interface. * Unify GetSourceType method implementation across all rules.
1 parent d97ddd4 commit 23c7f9e

79 files changed

Lines changed: 261 additions & 703 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/Generic/AvoidCmdletGeneric.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ 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>
8480
public abstract SourceType GetSourceType();
8581

8682
/// <summary>

Engine/Generic/AvoidParameterGeneric.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ 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>
9490
public abstract SourceType GetSourceType();
9591

9692
/// <summary>

Engine/Generic/ConfigurableRule.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ 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>
110106
public abstract SourceType GetSourceType();
111107

112108
private void SetDefaultValues()

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 SourceType GetSourceType() => SourceType.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

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 SourceType GetSourceType() => SourceType.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 SourceType GetSourceType() => SourceType.Builtin;
270264

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

Rules/AvoidAssignmentToAutomaticVariable.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,7 @@ public string GetDescription()
178178
return string.Format(CultureInfo.CurrentCulture, Strings.AvoidAssignmentToReadOnlyAutomaticVariableDescription);
179179
}
180180

181-
/// <summary>
182-
/// GetSourceType: Retrieves the type of the rule: builtin, managed or module.
183-
/// </summary>
184-
public SourceType GetSourceType()
185-
{
186-
return SourceType.Builtin;
187-
}
181+
public SourceType GetSourceType() => SourceType.Builtin;
188182

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

Rules/AvoidDefaultTrueValueSwitchParameter.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,7 @@ public string GetDescription()
8080
return string.Format(CultureInfo.CurrentCulture, Strings.AvoidDefaultValueSwitchParameterDescription);
8181
}
8282

83-
/// <summary>
84-
/// GetSourceType: Retrieves the type of the rule, builtin, managed or module.
85-
/// </summary>
86-
public SourceType GetSourceType()
87-
{
88-
return SourceType.Builtin;
89-
}
83+
public SourceType GetSourceType() => SourceType.Builtin;
9084

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

Rules/AvoidDefaultValueForMandatoryParameter.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
7575
/// <param name="paramAst">The parameter AST to examine</param>
7676
/// <param name="comparer">String comparer for case-insensitive attribute name matching</param>
7777
/// <returns>
78-
/// True if the parameter has at least one [Parameter] attribute and ALL of them
78+
/// True if the parameter has at least one [Parameter] attribute and ALL of them
7979
/// have the Mandatory named argument set to true (explicitly or implicitly).
80-
/// False if the parameter has no [Parameter] attributes or if any [Parameter]
80+
/// False if the parameter has no [Parameter] attributes or if any [Parameter]
8181
/// attribute does not have Mandatory=true.
8282
/// </returns>
8383
private static bool HasMandatoryInAllParameterAttributes(ParameterAst paramAst)
@@ -122,13 +122,7 @@ public string GetDescription()
122122
return string.Format(CultureInfo.CurrentCulture, Strings.AvoidDefaultValueForMandatoryParameterDescription);
123123
}
124124

125-
/// <summary>
126-
/// Method: Retrieves the type of the rule: builtin, managed or module.
127-
/// </summary>
128-
public SourceType GetSourceType()
129-
{
130-
return SourceType.Builtin;
131-
}
125+
public SourceType GetSourceType() => SourceType.Builtin;
132126

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

Rules/AvoidEmptyCatchBlock.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,7 @@ public string GetDescription()
7070
return string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingEmptyCatchBlockDescription);
7171
}
7272

73-
/// <summary>
74-
/// Method: Retrieves the type of the rule: builtin, managed or module.
75-
/// </summary>
76-
public SourceType GetSourceType()
77-
{
78-
return SourceType.Builtin;
79-
}
73+
public SourceType GetSourceType() => SourceType.Builtin;
8074

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

0 commit comments

Comments
 (0)