@@ -45,13 +45,12 @@ public sealed class ScriptAnalyzer
4545 List < Regex > includeRegexList ;
4646 List < Regex > excludeRegexList ;
4747 bool suppressedOnly ;
48+ private bool resolveDscResourceDependency ;
4849 #endregion
4950
5051 #region Singleton
5152 private static object syncRoot = new Object ( ) ;
52-
5353 private static ScriptAnalyzer instance ;
54-
5554 public static ScriptAnalyzer Instance
5655 {
5756 get
@@ -103,7 +102,7 @@ internal void Initialize<TCmdlet>(
103102 string [ ] severity = null ,
104103 bool includeDefaultRules = false ,
105104 bool suppressedOnly = false ,
106- bool resolveDSCResourceDependency = false )
105+ bool resolveDscResourceDependency = false )
107106 where TCmdlet : PSCmdlet , IOutputWriter
108107 {
109108 if ( cmdlet == null )
@@ -121,7 +120,7 @@ internal void Initialize<TCmdlet>(
121120 severity ,
122121 includeDefaultRules ,
123122 suppressedOnly ,
124- resolveDSCResourceDependency : resolveDSCResourceDependency ) ;
123+ resolveDscResourceDependency : resolveDscResourceDependency ) ;
125124 }
126125
127126 /// <summary>
@@ -470,14 +469,15 @@ private void Initialize(
470469 bool includeDefaultRules = false ,
471470 bool suppressedOnly = false ,
472471 string profile = null ,
473- bool resolveDSCResourceDependency = false )
472+ bool resolveDscResourceDependency = false )
474473 {
475474 if ( outputWriter == null )
476475 {
477476 throw new ArgumentNullException ( "outputWriter" ) ;
478477 }
479478
480479 this . outputWriter = outputWriter ;
480+ this . resolveDscResourceDependency = resolveDscResourceDependency ;
481481
482482 #region Verifies rule extensions and loggers path
483483
@@ -1165,22 +1165,36 @@ public IEnumerable<DiagnosticRecord> AnalyzePath(string path, bool searchRecursi
11651165 // is an optimization over doing the whole operation at once
11661166 // and calling .Concat on IEnumerables to join results.
11671167 this . BuildScriptPathList ( path , searchRecursively , scriptFilePaths ) ;
1168- using ( var rsp = RunspaceFactory . CreateRunspace ( ) )
1168+ if ( resolveDscResourceDependency )
11691169 {
1170- rsp . Open ( ) ;
1171- using ( var moduleHandler = new ModuleDependencyHandler ( rsp ) )
1170+ using ( var rsp = RunspaceFactory . CreateRunspace ( ) )
11721171 {
1173- foreach ( string scriptFilePath in scriptFilePaths )
1172+ rsp . Open ( ) ;
1173+ using ( var moduleHandler = new ModuleDependencyHandler ( rsp ) )
11741174 {
1175- // Yield each record in the result so that the
1176- // caller can pull them one at a time
1177- foreach ( var diagnosticRecord in this . AnalyzeFile ( scriptFilePath , moduleHandler ) )
1178- {
1179- yield return diagnosticRecord ;
1180- }
1175+ return AnalyzePaths ( scriptFilePaths , moduleHandler ) ;
11811176 }
1177+ } // disposing the runspace also closes it if it not already closed
1178+ }
1179+ else
1180+ {
1181+ return AnalyzePaths ( scriptFilePaths , null ) ;
1182+ }
1183+ }
1184+
1185+ private IEnumerable < DiagnosticRecord > AnalyzePaths (
1186+ IEnumerable < string > scriptFilePaths ,
1187+ ModuleDependencyHandler moduleHandler )
1188+ {
1189+ foreach ( string scriptFilePath in scriptFilePaths )
1190+ {
1191+ // Yield each record in the result so that the
1192+ // caller can pull them one at a time
1193+ foreach ( var diagnosticRecord in this . AnalyzeFile ( scriptFilePath , moduleHandler ) )
1194+ {
1195+ yield return diagnosticRecord ;
11821196 }
1183- } // disposing the runspace also closes it if it not already closed
1197+ }
11841198 }
11851199
11861200 /// <summary>
0 commit comments