Skip to content

Commit d849e11

Browse files
committed
Add a new switch parameter to run default rules along with custom ones
1 parent a748d20 commit d849e11

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

Engine/Commands/GetScriptAnalyzerRuleCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected override void BeginProcessing()
9191
{
9292
string[] rulePaths = Helper.ProcessCustomRulePaths(customRulePath,
9393
this.SessionState, recurseCustomRulePath);
94-
ScriptAnalyzer.Instance.Initialize(this, rulePaths);
94+
ScriptAnalyzer.Instance.Initialize(this, rulePaths, null, null, null, null == rulePaths ? true : false);
9595
}
9696

9797
/// <summary>

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ public SwitchParameter RecurseCustomRulePath
9393
}
9494
private bool recurseCustomRulePath;
9595

96+
/// <summary>
97+
/// IncludeDefaultRules: Invoke default rules along with Custom rules
98+
/// </summary>
99+
[Parameter(Mandatory = false)]
100+
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
101+
public SwitchParameter IncludeDefaultRules
102+
{
103+
get { return includeDefaultRules; }
104+
set { includeDefaultRules = value; }
105+
}
106+
private bool includeDefaultRules;
107+
96108
/// <summary>
97109
/// ExcludeRule: Array of names of rules to be disabled.
98110
/// </summary>
@@ -195,6 +207,7 @@ protected override void BeginProcessing()
195207
this.includeRule,
196208
this.excludeRule,
197209
this.severity,
210+
null == rulePaths ? true : this.includeDefaultRules,
198211
this.suppressedOnly,
199212
this.configuration);
200213
}

Engine/ScriptAnalyzer.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ public static ScriptAnalyzer Instance
9696
/// </summary>
9797
internal void Initialize<TCmdlet>(
9898
TCmdlet cmdlet,
99-
string[] customizedRulePath = null,
99+
string[] customizedRulePath = null,
100100
string[] includeRuleNames = null,
101101
string[] excludeRuleNames = null,
102102
string[] severity = null,
103+
bool includeDefaultRules = false,
103104
bool suppressedOnly = false,
104105
string profile = null)
105106
where TCmdlet : PSCmdlet, IOutputWriter
@@ -117,6 +118,7 @@ internal void Initialize<TCmdlet>(
117118
includeRuleNames,
118119
excludeRuleNames,
119120
severity,
121+
includeDefaultRules,
120122
suppressedOnly,
121123
profile);
122124
}
@@ -127,10 +129,11 @@ internal void Initialize<TCmdlet>(
127129
public void Initialize(
128130
Runspace runspace,
129131
IOutputWriter outputWriter,
130-
string[] customizedRulePath = null,
132+
string[] customizedRulePath = null,
131133
string[] includeRuleNames = null,
132134
string[] excludeRuleNames = null,
133135
string[] severity = null,
136+
bool includeDefaultRules = false,
134137
bool suppressedOnly = false,
135138
string profile = null)
136139
{
@@ -147,6 +150,7 @@ public void Initialize(
147150
includeRuleNames,
148151
excludeRuleNames,
149152
severity,
153+
includeDefaultRules,
150154
suppressedOnly,
151155
profile);
152156
}
@@ -308,10 +312,11 @@ private void Initialize(
308312
IOutputWriter outputWriter,
309313
PathIntrinsics path,
310314
CommandInvocationIntrinsics invokeCommand,
311-
string[] customizedRulePath,
312-
string[] includeRuleNames,
315+
string[] customizedRulePath,
316+
string[] includeRuleNames,
313317
string[] excludeRuleNames,
314318
string[] severity,
319+
bool includeDefaultRules = false,
315320
bool suppressedOnly = false,
316321
string profile = null)
317322
{
@@ -358,7 +363,7 @@ private void Initialize(
358363

359364
try
360365
{
361-
this.LoadRules(this.validationResults, invokeCommand, null == customizedRulePath ? true : false);
366+
this.LoadRules(this.validationResults, invokeCommand, includeDefaultRules);
362367
}
363368
catch (Exception ex)
364369
{

0 commit comments

Comments
 (0)