@@ -474,7 +474,9 @@ private void LoadRules(Dictionary<string, List<string>> result, CommandInvocatio
474474
475475 // Gets external rules.
476476 if ( result . ContainsKey ( "ValidModPaths" ) && result [ "ValidModPaths" ] . Count > 0 )
477+ {
477478 ExternalRules = GetExternalRule ( result [ "ValidModPaths" ] . ToArray ( ) ) ;
479+ }
478480 }
479481
480482 internal string [ ] GetValidModulePaths ( )
@@ -495,8 +497,12 @@ public IEnumerable<IRule> GetRule(string[] moduleNames, string[] ruleNames)
495497 IEnumerable < IExternalRule > externalRules = null ;
496498
497499 // 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+ }
500506
501507 // Gets PowerShell Rules.
502508 if ( moduleNames != null )
@@ -565,9 +571,17 @@ private List<ExternalRule> GetExternalRule(string[] moduleNames)
565571 posh . Commands . Clear ( ) ;
566572
567573 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+ }
571585
572586 //Only add functions that are defined as rules.
573587 if ( param != null )
@@ -746,7 +760,7 @@ internal IEnumerable<DiagnosticRecord> GetExternalRecord(Ast ast, Token[] token,
746760
747761 if ( ! string . IsNullOrEmpty ( message ) )
748762 {
749- diagnostics . Add ( new DiagnosticRecord ( message , extent , ruleName , severity , null ) ) ;
763+ diagnostics . Add ( new DiagnosticRecord ( message , extent , ruleName , severity , filePath ) ) ;
750764 }
751765 }
752766 }
0 commit comments