Skip to content

Commit 5c08380

Browse files
author
Quoc Truong
committed
Fix merged conflict
2 parents 8ba1409 + 967461a commit 5c08380

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ private void ProcessPath(string path)
271271

272272
}
273273

274+
ConcurrentBag<DiagnosticRecord> diagnostics;
275+
ConcurrentBag<SuppressedRecord> suppressed;
276+
Dictionary<string, List<RuleSuppression>> ruleSuppressions;
277+
List<Regex> includeRegexList;
278+
List<Regex> excludeRegexList;
279+
CountdownEvent cde;
280+
ConcurrentDictionary<string, List<object>> ruleDictionary;
281+
274282
/// <summary>
275283
/// Analyzes a single script file.
276284
/// </summary>
@@ -287,8 +295,8 @@ private void AnalyzeFile(string filePath)
287295
List<KeyValuePair<CommandInfo, IScriptExtent>> cmdInfoTable = new List<KeyValuePair<CommandInfo, IScriptExtent>>();
288296

289297
//Check wild card input for the Include/ExcludeRules and create regex match patterns
290-
List<Regex> includeRegexList = new List<Regex>();
291-
List<Regex> excludeRegexList = new List<Regex>();
298+
includeRegexList = new List<Regex>();
299+
excludeRegexList = new List<Regex>();
292300
if (includeRule != null)
293301
{
294302
foreach (string rule in includeRule)
@@ -336,7 +344,7 @@ private void AnalyzeFile(string filePath)
336344
return;
337345
}
338346

339-
Dictionary<string, List<RuleSuppression>> ruleSuppressions = Helper.Instance.GetRuleSuppression(ast);
347+
ruleSuppressions = Helper.Instance.GetRuleSuppression(ast);
340348

341349
foreach (List<RuleSuppression> ruleSuppressionsList in ruleSuppressions.Values)
342350
{
@@ -665,6 +673,65 @@ private void AnalyzeFile(string filePath)
665673
}
666674
}
667675

676+
void bg_DoWork(object sender, DoWorkEventArgs e)
677+
{
678+
bool includeRegexMatch = false;
679+
bool excludeRegexMatch = false;
680+
681+
object[] parameters = e.Argument as object[];
682+
683+
IScriptRule scriptRule = parameters[0] as IScriptRule;
684+
685+
foreach (Regex include in includeRegexList)
686+
{
687+
if (include.IsMatch(scriptRule.GetName()))
688+
{
689+
includeRegexMatch = true;
690+
break;
691+
}
692+
}
693+
694+
foreach (Regex exclude in excludeRegexList)
695+
{
696+
if (exclude.IsMatch(scriptRule.GetName()))
697+
{
698+
excludeRegexMatch = true;
699+
break;
700+
}
701+
}
702+
703+
List<object> result = new List<object>();
704+
705+
if ((includeRule == null || includeRegexMatch) && (excludeRule == null || !excludeRegexMatch))
706+
{
707+
//WriteVerbose(string.Format(CultureInfo.CurrentCulture, Strings.VerboseRunningMessage, scriptRule.GetName()));
708+
result.Add(string.Format(CultureInfo.CurrentCulture, Strings.VerboseRunningMessage, scriptRule.GetName()));
709+
710+
// Ensure that any unhandled errors from Rules are converted to non-terminating errors
711+
// We want the Engine to continue functioning even if one or more Rules throws an exception
712+
try
713+
{
714+
var records = Helper.Instance.SuppressRule(scriptRule.GetName(), ruleSuppressions, scriptRule.AnalyzeScript(ast, ast.Extent.File).ToList());
715+
foreach (var record in records.Item2)
716+
{
717+
diagnostics.Add(record);
718+
}
719+
foreach (var suppressedRec in records.Item1)
720+
{
721+
suppressed.Add(suppressedRec);
722+
}
723+
}
724+
catch (Exception scriptRuleException)
725+
{
726+
result.Add(new ErrorRecord(scriptRuleException, Strings.RuleErrorMessage, ErrorCategory.InvalidOperation, ast.Extent.File));
727+
}
728+
}
729+
730+
ruleDictionary[scriptRule.GetName()] = result;
731+
732+
cde.Signal();
733+
}
734+
668735
#endregion
669736
}
670737
}

0 commit comments

Comments
 (0)