@@ -27,6 +27,15 @@ public class AnalysisService : IDisposable
2727 private const int NumRunspaces = 2 ;
2828 private RunspacePool analysisRunspacePool ;
2929 private PSModuleInfo scriptAnalyzerModuleInfo ;
30+
31+ private bool hasScriptAnalyzerModule
32+ {
33+ get
34+ {
35+ return scriptAnalyzerModuleInfo != null ;
36+ }
37+ }
38+
3039 private string [ ] activeRules ;
3140 private string settingsPath ;
3241
@@ -160,7 +169,7 @@ public async Task<ScriptFileMarker[]> GetSemanticMarkersAsync(ScriptFile file, H
160169 public IEnumerable < string > GetPSScriptAnalyzerRules ( )
161170 {
162171 List < string > ruleNames = new List < string > ( ) ;
163- if ( scriptAnalyzerModuleInfo != null )
172+ if ( hasScriptAnalyzerModule )
164173 {
165174 var ruleObjects = InvokePowerShell ( "Get-ScriptAnalyzerRule" , new Dictionary < string , object > ( ) ) ;
166175 foreach ( var rule in ruleObjects )
@@ -215,7 +224,7 @@ private async Task<ScriptFileMarker[]> GetSemanticMarkersAsync<TSettings>(
215224 string [ ] rules ,
216225 TSettings settings ) where TSettings : class
217226 {
218- if ( this . scriptAnalyzerModuleInfo != null
227+ if ( hasScriptAnalyzerModule
219228 && file . IsAnalysisEnabled
220229 && ( typeof ( TSettings ) == typeof ( string ) || typeof ( TSettings ) == typeof ( Hashtable ) )
221230 && ( rules != null || settings != null ) )
@@ -246,16 +255,16 @@ private static PSModuleInfo FindPSScriptAnalyzerModule()
246255 . AddParameter ( "First" , 1 ) ;
247256
248257 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 )
251260 {
252261 Logger . Write (
253262 LogLevel . Normal ,
254263 string . Format (
255264 "PSScriptAnalyzer found at {0}" ,
256- scriptAnalyzerModuleInfo . Path ) ) ;
265+ psModuleInfo . Path ) ) ;
257266
258- return scriptAnalyzerModuleInfo ;
267+ return psModuleInfo ;
259268 }
260269
261270 Logger . Write (
@@ -267,7 +276,7 @@ private static PSModuleInfo FindPSScriptAnalyzerModule()
267276
268277 private void EnumeratePSScriptAnalyzerRules ( )
269278 {
270- if ( scriptAnalyzerModuleInfo != null )
279+ if ( hasScriptAnalyzerModule )
271280 {
272281 var rules = GetPSScriptAnalyzerRules ( ) ;
273282 var sb = new StringBuilder ( ) ;
@@ -288,7 +297,7 @@ private async Task<PSObject[]> GetDiagnosticRecordsAsync<TSettings>(
288297 {
289298 var diagnosticRecords = new PSObject [ 0 ] ;
290299
291- if ( this . scriptAnalyzerModuleInfo != null
300+ if ( hasScriptAnalyzerModule
292301 && ( typeof ( TSettings ) == typeof ( string )
293302 || typeof ( TSettings ) == typeof ( Hashtable ) ) )
294303 {
0 commit comments