@@ -474,7 +474,9 @@ private void LoadRules(Dictionary<string, List<string>> result, CommandInvocatio
474
474
475
475
// Gets external rules.
476
476
if ( result . ContainsKey ( "ValidModPaths" ) && result [ "ValidModPaths" ] . Count > 0 )
477
+ {
477
478
ExternalRules = GetExternalRule ( result [ "ValidModPaths" ] . ToArray ( ) ) ;
479
+ }
478
480
}
479
481
480
482
internal string [ ] GetValidModulePaths ( )
@@ -495,8 +497,12 @@ public IEnumerable<IRule> GetRule(string[] moduleNames, string[] ruleNames)
495
497
IEnumerable < IExternalRule > externalRules = null ;
496
498
497
499
// Combines C# rules.
498
- IEnumerable < IRule > rules = ScriptRules . Union < IRule > ( TokenRules )
499
- . Union < IRule > ( DSCResourceRules ) ;
500
+ IEnumerable < IRule > rules = Enumerable . Empty < IRule > ( ) ;
501
+
502
+ if ( null != ScriptRules )
503
+ {
504
+ rules = ScriptRules . Union < IRule > ( TokenRules ) . Union < IRule > ( DSCResourceRules ) ;
505
+ }
500
506
501
507
// Gets PowerShell Rules.
502
508
if ( moduleNames != null )
@@ -565,9 +571,17 @@ private List<ExternalRule> GetExternalRule(string[] moduleNames)
565
571
posh . Commands . Clear ( ) ;
566
572
567
573
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 ) ) ;
574
+ ParameterMetadata param = null ;
575
+
576
+ // Ignore any exceptions associated with finding functions that are ScriptAnalyzer rules
577
+ try
578
+ {
579
+ param = funcInfo . Parameters . Values . First < ParameterMetadata > ( item => item . Name . EndsWith ( "ast" , StringComparison . OrdinalIgnoreCase ) ||
580
+ item . Name . EndsWith ( "token" , StringComparison . OrdinalIgnoreCase ) ) ;
581
+ }
582
+ catch
583
+ {
584
+ }
571
585
572
586
//Only add functions that are defined as rules.
573
587
if ( param != null )
@@ -746,7 +760,7 @@ internal IEnumerable<DiagnosticRecord> GetExternalRecord(Ast ast, Token[] token,
746
760
747
761
if ( ! string . IsNullOrEmpty ( message ) )
748
762
{
749
- diagnostics . Add ( new DiagnosticRecord ( message , extent , ruleName , severity , null ) ) ;
763
+ diagnostics . Add ( new DiagnosticRecord ( message , extent , ruleName , severity , filePath ) ) ;
750
764
}
751
765
}
752
766
}
0 commit comments