@@ -105,7 +105,8 @@ internal void Initialize<TCmdlet>(
105
105
string [ ] excludeRuleNames = null ,
106
106
string [ ] severity = null ,
107
107
bool includeDefaultRules = false ,
108
- bool suppressedOnly = false )
108
+ bool suppressedOnly = false ,
109
+ bool resolveDSCResourceDependency = false )
109
110
where TCmdlet : PSCmdlet , IOutputWriter
110
111
{
111
112
if ( cmdlet == null )
@@ -122,7 +123,8 @@ internal void Initialize<TCmdlet>(
122
123
excludeRuleNames ,
123
124
severity ,
124
125
includeDefaultRules ,
125
- suppressedOnly ) ;
126
+ suppressedOnly ,
127
+ resolveDSCResourceDependency : resolveDSCResourceDependency ) ;
126
128
}
127
129
128
130
/// <summary>
@@ -167,8 +169,11 @@ public void CleanUp()
167
169
severity = null ;
168
170
includeRegexList = null ;
169
171
excludeRegexList = null ;
170
- suppressedOnly = false ;
171
- moduleHandler . Dispose ( ) ;
172
+ suppressedOnly = false ;
173
+ if ( moduleHandler != null )
174
+ {
175
+ moduleHandler . Dispose ( ) ;
176
+ }
172
177
}
173
178
174
179
internal bool ParseProfile ( object profileObject , PathIntrinsics path , IOutputWriter writer )
@@ -462,16 +467,17 @@ private bool ParseProfileString(string profile, PathIntrinsics path, IOutputWrit
462
467
}
463
468
464
469
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 ,
469
474
string [ ] includeRuleNames ,
470
475
string [ ] excludeRuleNames ,
471
476
string [ ] severity ,
472
477
bool includeDefaultRules = false ,
473
478
bool suppressedOnly = false ,
474
- string profile = null )
479
+ string profile = null ,
480
+ bool resolveDSCResourceDependency = false )
475
481
{
476
482
if ( outputWriter == null )
477
483
{
@@ -481,8 +487,8 @@ private void Initialize(
481
487
this . outputWriter = outputWriter ;
482
488
483
489
// 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 ;
486
492
487
493
#region Verifies rule extensions and loggers path
488
494
@@ -1318,8 +1324,8 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
1318
1324
// - OR
1319
1325
// - swallow the these errors
1320
1326
1321
-
1322
- if ( errors != null && errors . Length > 0 )
1327
+ bool parseAgain = false ;
1328
+ if ( moduleHandler != null && errors != null && errors . Length > 0 )
1323
1329
{
1324
1330
foreach ( ParseError error in errors )
1325
1331
{
@@ -1329,6 +1335,8 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
1329
1335
if ( moduleName != null )
1330
1336
{
1331
1337
moduleHandler . SaveModule ( moduleName ) ;
1338
+ // if successfully saved
1339
+ parseAgain = true ;
1332
1340
}
1333
1341
}
1334
1342
}
@@ -1337,9 +1345,12 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
1337
1345
//try parsing again
1338
1346
//var oldDefault = Runspace.DefaultRunspace;
1339
1347
//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
+ }
1342
1352
1353
+ //Runspace.DefaultRunspace = oldDefault;
1343
1354
if ( errors != null && errors . Length > 0 )
1344
1355
{
1345
1356
foreach ( ParseError error in errors )
0 commit comments