Skip to content

Commit 16b407f

Browse files
committed
Updates the Initialize method to process the profile parameter.
We need this capability in the PowerShell extension for VSCode to enable it to use an external settings file. This will allow users of the extension to be able to customize the default settings.
1 parent 6b51b94 commit 16b407f

File tree

1 file changed

+64
-5
lines changed

1 file changed

+64
-5
lines changed

Engine/ScriptAnalyzer.cs

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ public void Initialize(
133133
string[] excludeRuleNames = null,
134134
string[] severity = null,
135135
bool includeDefaultRules = false,
136-
bool suppressedOnly = false)
136+
bool suppressedOnly = false,
137+
string profile = null)
137138
{
138139
if (runspace == null)
139140
{
@@ -149,7 +150,8 @@ public void Initialize(
149150
excludeRuleNames,
150151
severity,
151152
includeDefaultRules,
152-
suppressedOnly);
153+
suppressedOnly,
154+
profile);
153155
}
154156

155157
/// <summary>
@@ -476,13 +478,70 @@ private void Initialize(
476478

477479
#region Initializes Rules
478480

481+
var includeRuleList = new List<string>();
482+
var excludeRuleList = new List<string>();
483+
var severityList = new List<string>();
484+
485+
if (profile != null)
486+
{
487+
ParseProfileString(profile, path, outputWriter, severityList, includeRuleList, excludeRuleList);
488+
}
489+
490+
if (includeRuleNames != null)
491+
{
492+
foreach (string includeRuleName in includeRuleNames.Where(rule => !includeRuleList.Contains(rule, StringComparer.OrdinalIgnoreCase)))
493+
{
494+
includeRuleList.Add(includeRuleName);
495+
}
496+
}
497+
498+
if (excludeRuleNames != null)
499+
{
500+
foreach (string excludeRuleName in excludeRuleNames.Where(rule => !excludeRuleList.Contains(rule, StringComparer.OrdinalIgnoreCase)))
501+
{
502+
excludeRuleList.Add(excludeRuleName);
503+
}
504+
}
505+
506+
if (severity != null)
507+
{
508+
foreach (string sev in severity.Where(s => !severityList.Contains(s, StringComparer.OrdinalIgnoreCase)))
509+
{
510+
severityList.Add(sev);
511+
}
512+
}
513+
479514
this.suppressedOnly = suppressedOnly;
480-
this.severity = this.severity == null ? severity : this.severity.Union(severity ?? new String[0]).ToArray();
481-
this.includeRule = this.includeRule == null ? includeRuleNames : this.includeRule.Union(includeRuleNames ?? new String[0]).ToArray();
482-
this.excludeRule = this.excludeRule == null ? excludeRuleNames : this.excludeRule.Union(excludeRuleNames ?? new String[0]).ToArray();
483515
this.includeRegexList = new List<Regex>();
484516
this.excludeRegexList = new List<Regex>();
485517

518+
if (this.severity == null)
519+
{
520+
this.severity = severityList.Count == 0 ? null : severityList.ToArray();
521+
}
522+
else
523+
{
524+
this.severity = this.severity.Union(severityList).ToArray();
525+
}
526+
527+
if (this.includeRule == null)
528+
{
529+
this.includeRule = includeRuleList.Count == 0 ? null : includeRuleList.ToArray();
530+
}
531+
else
532+
{
533+
this.includeRule = this.includeRule.Union(includeRuleList).ToArray();
534+
}
535+
536+
if (this.excludeRule == null)
537+
{
538+
this.excludeRule = excludeRuleList.Count == 0 ? null : excludeRuleList.ToArray();
539+
}
540+
else
541+
{
542+
this.excludeRule = this.excludeRule.Union(excludeRuleList).ToArray();
543+
}
544+
486545
//Check wild card input for the Include/ExcludeRules and create regex match patterns
487546
if (this.includeRule != null)
488547
{

0 commit comments

Comments
 (0)