@@ -42,24 +42,15 @@ public class AnalysisService : IDisposable
42
42
"PSMisleadingBacktick" ,
43
43
} ;
44
44
45
- private List < string > activeRules ;
46
-
47
45
#endregion // Private Fields
48
46
49
47
50
48
#region Properties
51
49
52
- public string [ ] ActiveRules
53
- {
54
- get
55
- {
56
- return activeRules != null ? activeRules . ToArray ( ) : null ;
57
- }
58
- set
59
- {
60
- activeRules = new List < string > ( value ) ; // TODO check the argument
61
- }
62
- }
50
+ /// <summary>
51
+ /// Set of PSScriptAnalyzer rules used for analysis
52
+ /// </summary>
53
+ public string [ ] ActiveRules { get ; set ; }
63
54
64
55
/// <summary>
65
56
/// Gets or sets the path to a settings file (.psd1)
@@ -89,7 +80,7 @@ public AnalysisService(IConsoleHost consoleHost, string settingsPath = null)
89
80
this . analysisRunspace = RunspaceFactory . CreateRunspace ( InitialSessionState . CreateDefault2 ( ) ) ;
90
81
this . analysisRunspace . ThreadOptions = PSThreadOptions . ReuseThread ;
91
82
this . analysisRunspace . Open ( ) ;
92
- activeRules = new List < string > ( IncludedRules ) ;
83
+ ActiveRules = IncludedRules . ToArray ( ) ;
93
84
InitializePSScriptAnalyzer ( ) ;
94
85
}
95
86
catch ( Exception e )
@@ -141,18 +132,8 @@ public ScriptFileMarker[] GetSemanticMarkers(ScriptFile file)
141
132
}
142
133
143
134
/// <summary>
144
- /// Disposes the runspace being used by the analysis service.
135
+ /// Returns a list of builtin-in PSScriptAnalyzer rules
145
136
/// </summary>
146
- public void Dispose ( )
147
- {
148
- if ( this . analysisRunspace != null )
149
- {
150
- this . analysisRunspace . Close ( ) ;
151
- this . analysisRunspace . Dispose ( ) ;
152
- this . analysisRunspace = null ;
153
- }
154
- }
155
-
156
137
public IEnumerable < string > GetPSScriptAnalyzerRules ( )
157
138
{
158
139
List < string > ruleNames = new List < string > ( ) ;
@@ -162,7 +143,7 @@ public IEnumerable<string> GetPSScriptAnalyzerRules()
162
143
{
163
144
ps . Runspace = this . analysisRunspace ;
164
145
var ruleObjects = ps . AddCommand ( "Get-ScriptAnalyzerRule" ) . Invoke ( ) ;
165
- foreach ( var rule in ruleObjects )
146
+ foreach ( var rule in ruleObjects )
166
147
{
167
148
ruleNames . Add ( ( string ) rule . Members [ "RuleName" ] . Value ) ;
168
149
}
@@ -172,6 +153,19 @@ public IEnumerable<string> GetPSScriptAnalyzerRules()
172
153
return ruleNames ;
173
154
}
174
155
156
+ /// <summary>
157
+ /// Disposes the runspace being used by the analysis service.
158
+ /// </summary>
159
+ public void Dispose ( )
160
+ {
161
+ if ( this . analysisRunspace != null )
162
+ {
163
+ this . analysisRunspace . Close ( ) ;
164
+ this . analysisRunspace . Dispose ( ) ;
165
+ this . analysisRunspace = null ;
166
+ }
167
+ }
168
+
175
169
#endregion // public methods
176
170
177
171
#region Private Methods
@@ -280,7 +274,7 @@ private IEnumerable<PSObject> GetDiagnosticRecords(ScriptFile file)
280
274
}
281
275
else
282
276
{
283
- powerShell . AddParameter ( "IncludeRule" , activeRules . ToArray ( ) ) ;
277
+ powerShell . AddParameter ( "IncludeRule" , ActiveRules ) ;
284
278
}
285
279
286
280
diagnosticRecords = powerShell . Invoke ( ) ;
0 commit comments