Skip to content

Commit b597b82

Browse files
author
Kapil Borle
committed
Use rule path parameters from settings file
1 parent b6de244 commit b597b82

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ protected override void BeginProcessing()
265265
ProcessPath();
266266
}
267267

268+
string[] combRulePaths = null;
269+
var combRecurseCustomRulePath = RecurseCustomRulePath.IsPresent;
270+
var combIncludeDefaultRules = IncludeDefaultRules.IsPresent;
268271
try
269272
{
270273
var settingsObj = PSSASettings.Create(
@@ -274,7 +277,26 @@ protected override void BeginProcessing()
274277
if (settingsObj != null)
275278
{
276279
ScriptAnalyzer.Instance.UpdateSettings(settingsObj);
280+
281+
// For includeDefaultRules and RecurseCustomRulePath we override the value in the settings file by
282+
// command line argument.
283+
combRecurseCustomRulePath = combRecurseCustomRulePath || settingsObj.RecurseCustomRulePath;
284+
combIncludeDefaultRules = combIncludeDefaultRules || settingsObj.IncludeDefaultRules;
277285
}
286+
287+
// Ideally we should not allow the parameter to be set from settings and command line
288+
// simultaneously. But since, this was done before with IncludeRules, ExcludeRules and Severity,
289+
// we use the same strategy for CustomRulePath. So, we take the union of CustomRulePath provided in
290+
// the settings file and if provided on command line.
291+
var settingsCustomRulePath = Helper.ProcessCustomRulePaths(
292+
settingsObj?.CustomRulePath?.ToArray(),
293+
this.SessionState,
294+
combRecurseCustomRulePath);
295+
combRulePaths = rulePaths == null
296+
? settingsCustomRulePath
297+
: settingsCustomRulePath == null
298+
? rulePaths
299+
: rulePaths.Concat(settingsCustomRulePath).ToArray();
278300
}
279301
catch
280302
{
@@ -285,11 +307,11 @@ protected override void BeginProcessing()
285307

286308
ScriptAnalyzer.Instance.Initialize(
287309
this,
288-
rulePaths,
310+
combRulePaths,
289311
this.includeRule,
290312
this.excludeRule,
291313
this.severity,
292-
null == rulePaths ? true : this.includeDefaultRules,
314+
combRulePaths == null || combIncludeDefaultRules,
293315
this.suppressedOnly);
294316
}
295317

0 commit comments

Comments
 (0)