@@ -45,13 +45,12 @@ public sealed class ScriptAnalyzer
45
45
List < Regex > includeRegexList ;
46
46
List < Regex > excludeRegexList ;
47
47
bool suppressedOnly ;
48
+ private bool resolveDscResourceDependency ;
48
49
#endregion
49
50
50
51
#region Singleton
51
52
private static object syncRoot = new Object ( ) ;
52
-
53
53
private static ScriptAnalyzer instance ;
54
-
55
54
public static ScriptAnalyzer Instance
56
55
{
57
56
get
@@ -103,7 +102,7 @@ internal void Initialize<TCmdlet>(
103
102
string [ ] severity = null ,
104
103
bool includeDefaultRules = false ,
105
104
bool suppressedOnly = false ,
106
- bool resolveDSCResourceDependency = false )
105
+ bool resolveDscResourceDependency = false )
107
106
where TCmdlet : PSCmdlet , IOutputWriter
108
107
{
109
108
if ( cmdlet == null )
@@ -121,7 +120,7 @@ internal void Initialize<TCmdlet>(
121
120
severity ,
122
121
includeDefaultRules ,
123
122
suppressedOnly ,
124
- resolveDSCResourceDependency : resolveDSCResourceDependency ) ;
123
+ resolveDscResourceDependency : resolveDscResourceDependency ) ;
125
124
}
126
125
127
126
/// <summary>
@@ -470,14 +469,15 @@ private void Initialize(
470
469
bool includeDefaultRules = false ,
471
470
bool suppressedOnly = false ,
472
471
string profile = null ,
473
- bool resolveDSCResourceDependency = false )
472
+ bool resolveDscResourceDependency = false )
474
473
{
475
474
if ( outputWriter == null )
476
475
{
477
476
throw new ArgumentNullException ( "outputWriter" ) ;
478
477
}
479
478
480
479
this . outputWriter = outputWriter ;
480
+ this . resolveDscResourceDependency = resolveDscResourceDependency ;
481
481
482
482
#region Verifies rule extensions and loggers path
483
483
@@ -1165,22 +1165,36 @@ public IEnumerable<DiagnosticRecord> AnalyzePath(string path, bool searchRecursi
1165
1165
// is an optimization over doing the whole operation at once
1166
1166
// and calling .Concat on IEnumerables to join results.
1167
1167
this . BuildScriptPathList ( path , searchRecursively , scriptFilePaths ) ;
1168
- using ( var rsp = RunspaceFactory . CreateRunspace ( ) )
1168
+ if ( resolveDscResourceDependency )
1169
1169
{
1170
- rsp . Open ( ) ;
1171
- using ( var moduleHandler = new ModuleDependencyHandler ( rsp ) )
1170
+ using ( var rsp = RunspaceFactory . CreateRunspace ( ) )
1172
1171
{
1173
- foreach ( string scriptFilePath in scriptFilePaths )
1172
+ rsp . Open ( ) ;
1173
+ using ( var moduleHandler = new ModuleDependencyHandler ( rsp ) )
1174
1174
{
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 ) ;
1181
1176
}
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 ;
1182
1196
}
1183
- } // disposing the runspace also closes it if it not already closed
1197
+ }
1184
1198
}
1185
1199
1186
1200
/// <summary>
0 commit comments