From 16b407f5705ac3523ad5e7abffd9b4c374f30332 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sun, 27 Mar 2016 15:24:39 -0600 Subject: [PATCH] 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. --- Engine/ScriptAnalyzer.cs | 69 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/Engine/ScriptAnalyzer.cs b/Engine/ScriptAnalyzer.cs index 07b891ae3..af111b426 100644 --- a/Engine/ScriptAnalyzer.cs +++ b/Engine/ScriptAnalyzer.cs @@ -133,7 +133,8 @@ public void Initialize( string[] excludeRuleNames = null, string[] severity = null, bool includeDefaultRules = false, - bool suppressedOnly = false) + bool suppressedOnly = false, + string profile = null) { if (runspace == null) { @@ -149,7 +150,8 @@ public void Initialize( excludeRuleNames, severity, includeDefaultRules, - suppressedOnly); + suppressedOnly, + profile); } /// @@ -476,13 +478,70 @@ private void Initialize( #region Initializes Rules + var includeRuleList = new List(); + var excludeRuleList = new List(); + var severityList = new List(); + + if (profile != null) + { + ParseProfileString(profile, path, outputWriter, severityList, includeRuleList, excludeRuleList); + } + + if (includeRuleNames != null) + { + foreach (string includeRuleName in includeRuleNames.Where(rule => !includeRuleList.Contains(rule, StringComparer.OrdinalIgnoreCase))) + { + includeRuleList.Add(includeRuleName); + } + } + + if (excludeRuleNames != null) + { + foreach (string excludeRuleName in excludeRuleNames.Where(rule => !excludeRuleList.Contains(rule, StringComparer.OrdinalIgnoreCase))) + { + excludeRuleList.Add(excludeRuleName); + } + } + + if (severity != null) + { + foreach (string sev in severity.Where(s => !severityList.Contains(s, StringComparer.OrdinalIgnoreCase))) + { + severityList.Add(sev); + } + } + this.suppressedOnly = suppressedOnly; - this.severity = this.severity == null ? severity : this.severity.Union(severity ?? new String[0]).ToArray(); - this.includeRule = this.includeRule == null ? includeRuleNames : this.includeRule.Union(includeRuleNames ?? new String[0]).ToArray(); - this.excludeRule = this.excludeRule == null ? excludeRuleNames : this.excludeRule.Union(excludeRuleNames ?? new String[0]).ToArray(); this.includeRegexList = new List(); this.excludeRegexList = new List(); + if (this.severity == null) + { + this.severity = severityList.Count == 0 ? null : severityList.ToArray(); + } + else + { + this.severity = this.severity.Union(severityList).ToArray(); + } + + if (this.includeRule == null) + { + this.includeRule = includeRuleList.Count == 0 ? null : includeRuleList.ToArray(); + } + else + { + this.includeRule = this.includeRule.Union(includeRuleList).ToArray(); + } + + if (this.excludeRule == null) + { + this.excludeRule = excludeRuleList.Count == 0 ? null : excludeRuleList.ToArray(); + } + else + { + this.excludeRule = this.excludeRule.Union(excludeRuleList).ToArray(); + } + //Check wild card input for the Include/ExcludeRules and create regex match patterns if (this.includeRule != null) {