@@ -27,6 +27,15 @@ public class AnalysisService : IDisposable
27
27
private const int NumRunspaces = 2 ;
28
28
private RunspacePool analysisRunspacePool ;
29
29
private PSModuleInfo scriptAnalyzerModuleInfo ;
30
+
31
+ private bool hasScriptAnalyzerModule
32
+ {
33
+ get
34
+ {
35
+ return scriptAnalyzerModuleInfo != null ;
36
+ }
37
+ }
38
+
30
39
private string [ ] activeRules ;
31
40
private string settingsPath ;
32
41
@@ -160,7 +169,7 @@ public async Task<ScriptFileMarker[]> GetSemanticMarkersAsync(ScriptFile file, H
160
169
public IEnumerable < string > GetPSScriptAnalyzerRules ( )
161
170
{
162
171
List < string > ruleNames = new List < string > ( ) ;
163
- if ( scriptAnalyzerModuleInfo != null )
172
+ if ( hasScriptAnalyzerModule )
164
173
{
165
174
var ruleObjects = InvokePowerShell ( "Get-ScriptAnalyzerRule" , new Dictionary < string , object > ( ) ) ;
166
175
foreach ( var rule in ruleObjects )
@@ -215,7 +224,7 @@ private async Task<ScriptFileMarker[]> GetSemanticMarkersAsync<TSettings>(
215
224
string [ ] rules ,
216
225
TSettings settings ) where TSettings : class
217
226
{
218
- if ( this . scriptAnalyzerModuleInfo != null
227
+ if ( hasScriptAnalyzerModule
219
228
&& file . IsAnalysisEnabled
220
229
&& ( typeof ( TSettings ) == typeof ( string ) || typeof ( TSettings ) == typeof ( Hashtable ) )
221
230
&& ( rules != null || settings != null ) )
@@ -246,16 +255,16 @@ private static PSModuleInfo FindPSScriptAnalyzerModule()
246
255
. AddParameter ( "First" , 1 ) ;
247
256
248
257
var modules = ps . Invoke < PSModuleInfo > ( ) ;
249
- var scriptAnalyzerModuleInfo = modules == null ? null : modules . FirstOrDefault ( ) ;
250
- if ( scriptAnalyzerModuleInfo != null )
258
+ var psModuleInfo = modules == null ? null : modules . FirstOrDefault ( ) ;
259
+ if ( psModuleInfo != null )
251
260
{
252
261
Logger . Write (
253
262
LogLevel . Normal ,
254
263
string . Format (
255
264
"PSScriptAnalyzer found at {0}" ,
256
- scriptAnalyzerModuleInfo . Path ) ) ;
265
+ psModuleInfo . Path ) ) ;
257
266
258
- return scriptAnalyzerModuleInfo ;
267
+ return psModuleInfo ;
259
268
}
260
269
261
270
Logger . Write (
@@ -267,7 +276,7 @@ private static PSModuleInfo FindPSScriptAnalyzerModule()
267
276
268
277
private void EnumeratePSScriptAnalyzerRules ( )
269
278
{
270
- if ( scriptAnalyzerModuleInfo != null )
279
+ if ( hasScriptAnalyzerModule )
271
280
{
272
281
var rules = GetPSScriptAnalyzerRules ( ) ;
273
282
var sb = new StringBuilder ( ) ;
@@ -288,7 +297,7 @@ private async Task<PSObject[]> GetDiagnosticRecordsAsync<TSettings>(
288
297
{
289
298
var diagnosticRecords = new PSObject [ 0 ] ;
290
299
291
- if ( this . scriptAnalyzerModuleInfo != null
300
+ if ( hasScriptAnalyzerModule
292
301
&& ( typeof ( TSettings ) == typeof ( string )
293
302
|| typeof ( TSettings ) == typeof ( Hashtable ) ) )
294
303
{
0 commit comments