@@ -133,7 +133,8 @@ public void Initialize(
133
133
string [ ] excludeRuleNames = null ,
134
134
string [ ] severity = null ,
135
135
bool includeDefaultRules = false ,
136
- bool suppressedOnly = false )
136
+ bool suppressedOnly = false ,
137
+ string profile = null )
137
138
{
138
139
if ( runspace == null )
139
140
{
@@ -149,7 +150,8 @@ public void Initialize(
149
150
excludeRuleNames ,
150
151
severity ,
151
152
includeDefaultRules ,
152
- suppressedOnly ) ;
153
+ suppressedOnly ,
154
+ profile ) ;
153
155
}
154
156
155
157
/// <summary>
@@ -476,13 +478,70 @@ private void Initialize(
476
478
477
479
#region Initializes Rules
478
480
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
+
479
514
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 ( ) ;
483
515
this . includeRegexList = new List < Regex > ( ) ;
484
516
this . excludeRegexList = new List < Regex > ( ) ;
485
517
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
+
486
545
//Check wild card input for the Include/ExcludeRules and create regex match patterns
487
546
if ( this . includeRule != null )
488
547
{
0 commit comments