@@ -105,7 +105,8 @@ internal void Initialize<TCmdlet>(
105105 string [ ] excludeRuleNames = null ,
106106 string [ ] severity = null ,
107107 bool includeDefaultRules = false ,
108- bool suppressedOnly = false )
108+ bool suppressedOnly = false ,
109+ bool resolveDSCResourceDependency = false )
109110 where TCmdlet : PSCmdlet , IOutputWriter
110111 {
111112 if ( cmdlet == null )
@@ -122,7 +123,8 @@ internal void Initialize<TCmdlet>(
122123 excludeRuleNames ,
123124 severity ,
124125 includeDefaultRules ,
125- suppressedOnly ) ;
126+ suppressedOnly ,
127+ resolveDSCResourceDependency : resolveDSCResourceDependency ) ;
126128 }
127129
128130 /// <summary>
@@ -167,8 +169,11 @@ public void CleanUp()
167169 severity = null ;
168170 includeRegexList = null ;
169171 excludeRegexList = null ;
170- suppressedOnly = false ;
171- moduleHandler . Dispose ( ) ;
172+ suppressedOnly = false ;
173+ if ( moduleHandler != null )
174+ {
175+ moduleHandler . Dispose ( ) ;
176+ }
172177 }
173178
174179 internal bool ParseProfile ( object profileObject , PathIntrinsics path , IOutputWriter writer )
@@ -462,16 +467,17 @@ private bool ParseProfileString(string profile, PathIntrinsics path, IOutputWrit
462467 }
463468
464469 private void Initialize (
465- IOutputWriter outputWriter ,
466- PathIntrinsics path ,
467- CommandInvocationIntrinsics invokeCommand ,
468- string [ ] customizedRulePath ,
470+ IOutputWriter outputWriter ,
471+ PathIntrinsics path ,
472+ CommandInvocationIntrinsics invokeCommand ,
473+ string [ ] customizedRulePath ,
469474 string [ ] includeRuleNames ,
470475 string [ ] excludeRuleNames ,
471476 string [ ] severity ,
472477 bool includeDefaultRules = false ,
473478 bool suppressedOnly = false ,
474- string profile = null )
479+ string profile = null ,
480+ bool resolveDSCResourceDependency = false )
475481 {
476482 if ( outputWriter == null )
477483 {
@@ -481,8 +487,8 @@ private void Initialize(
481487 this . outputWriter = outputWriter ;
482488
483489 // TODO Create a runspace pool
484- runspace = RunspaceFactory . CreateRunspace ( ) ;
485- moduleHandler = new ModuleDependencyHandler ( runspace ) ;
490+ runspace = RunspaceFactory . CreateRunspace ( ) ;
491+ moduleHandler = resolveDSCResourceDependency ? new ModuleDependencyHandler ( runspace ) : null ;
486492
487493 #region Verifies rule extensions and loggers path
488494
@@ -1318,8 +1324,8 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
13181324 // - OR
13191325 // - swallow the these errors
13201326
1321-
1322- if ( errors != null && errors . Length > 0 )
1327+ bool parseAgain = false ;
1328+ if ( moduleHandler != null && errors != null && errors . Length > 0 )
13231329 {
13241330 foreach ( ParseError error in errors )
13251331 {
@@ -1329,6 +1335,8 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
13291335 if ( moduleName != null )
13301336 {
13311337 moduleHandler . SaveModule ( moduleName ) ;
1338+ // if successfully saved
1339+ parseAgain = true ;
13321340 }
13331341 }
13341342 }
@@ -1337,9 +1345,12 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
13371345 //try parsing again
13381346 //var oldDefault = Runspace.DefaultRunspace;
13391347 //Runspace.DefaultRunspace = moduleHandler.Runspace;
1340- scriptAst = Parser . ParseFile ( filePath , out scriptTokens , out errors ) ;
1341- //Runspace.DefaultRunspace = oldDefault;
1348+ if ( parseAgain )
1349+ {
1350+ scriptAst = Parser . ParseFile ( filePath , out scriptTokens , out errors ) ;
1351+ }
13421352
1353+ //Runspace.DefaultRunspace = oldDefault;
13431354 if ( errors != null && errors . Length > 0 )
13441355 {
13451356 foreach ( ParseError error in errors )
0 commit comments