@@ -466,15 +466,16 @@ private void LoadRules(Dictionary<string, List<string>> result, CommandInvocatio
466
466
{
467
467
container . ComposeParts ( this ) ;
468
468
}
469
- catch ( CompositionException compositionException )
470
- {
471
- this . outputWriter . WriteWarning ( compositionException . ToString ( ) ) ;
469
+ catch
470
+ {
472
471
}
473
472
}
474
473
475
474
// Gets external rules.
476
475
if ( result . ContainsKey ( "ValidModPaths" ) && result [ "ValidModPaths" ] . Count > 0 )
476
+ {
477
477
ExternalRules = GetExternalRule ( result [ "ValidModPaths" ] . ToArray ( ) ) ;
478
+ }
478
479
}
479
480
480
481
internal string [ ] GetValidModulePaths ( )
@@ -495,8 +496,12 @@ public IEnumerable<IRule> GetRule(string[] moduleNames, string[] ruleNames)
495
496
IEnumerable < IExternalRule > externalRules = null ;
496
497
497
498
// Combines C# rules.
498
- IEnumerable < IRule > rules = ScriptRules . Union < IRule > ( TokenRules )
499
- . Union < IRule > ( DSCResourceRules ) ;
499
+ IEnumerable < IRule > rules = Enumerable . Empty < IRule > ( ) ;
500
+
501
+ if ( null != ScriptRules )
502
+ {
503
+ rules = ScriptRules . Union < IRule > ( TokenRules ) . Union < IRule > ( DSCResourceRules ) ;
504
+ }
500
505
501
506
// Gets PowerShell Rules.
502
507
if ( moduleNames != null )
@@ -565,9 +570,17 @@ private List<ExternalRule> GetExternalRule(string[] moduleNames)
565
570
posh . Commands . Clear ( ) ;
566
571
567
572
FunctionInfo funcInfo = ( FunctionInfo ) psobject . ImmediateBaseObject ;
568
- ParameterMetadata param = funcInfo . Parameters . Values
569
- . First < ParameterMetadata > ( item => item . Name . EndsWith ( "ast" , StringComparison . OrdinalIgnoreCase ) ||
570
- item . Name . EndsWith ( "token" , StringComparison . OrdinalIgnoreCase ) ) ;
573
+ ParameterMetadata param = null ;
574
+
575
+ // Ignore any exceptions associated with finding functions that are ScriptAnalyzer rules
576
+ try
577
+ {
578
+ param = funcInfo . Parameters . Values . First < ParameterMetadata > ( item => item . Name . EndsWith ( "ast" , StringComparison . OrdinalIgnoreCase ) ||
579
+ item . Name . EndsWith ( "token" , StringComparison . OrdinalIgnoreCase ) ) ;
580
+ }
581
+ catch
582
+ {
583
+ }
571
584
572
585
//Only add functions that are defined as rules.
573
586
if ( param != null )
0 commit comments