Skip to content

Commit 2670587

Browse files
committed
Restore default PSScriptAnalyzer rule list
This change restores the default set of rules that we previously used in our PSScriptAnalyzer integration. This list got removed inadvertently when we changed our design to consume PSScriptAnalyzer as a module rather than a C# API. Related to PowerShell/vscode-powershell#246
1 parent 0c4176c commit 2670587

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/PowerShellEditorServices/Analysis/AnalysisService.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ private void FindPSScriptAnalyzer()
130130
using (var ps = System.Management.Automation.PowerShell.Create())
131131
{
132132
ps.Runspace = this.analysisRunspace;
133+
133134
var modules = ps.AddCommand("Get-Module")
134135
.AddParameter("List")
135136
.AddParameter("Name", "PSScriptAnalyzer")
136137
.Invoke();
138+
137139
var psModule = modules == null ? null : modules.FirstOrDefault();
138140
if (psModule != null)
139141
{
@@ -160,10 +162,12 @@ private void ImportPSScriptAnalyzer()
160162
using (var ps = System.Management.Automation.PowerShell.Create())
161163
{
162164
ps.Runspace = this.analysisRunspace;
163-
var module = ps.AddCommand("Import-Module").
164-
AddParameter("ModuleInfo", scriptAnalyzerModuleInfo)
165+
166+
var module = ps.AddCommand("Import-Module")
167+
.AddParameter("ModuleInfo", scriptAnalyzerModuleInfo)
165168
.AddParameter("PassThru")
166169
.Invoke();
170+
167171
if (module == null)
168172
{
169173
this.scriptAnalyzerModuleInfo = null;
@@ -186,13 +190,16 @@ private void EnumeratePSScriptAnalyzerRules()
186190
using (var ps = System.Management.Automation.PowerShell.Create())
187191
{
188192
ps.Runspace = this.analysisRunspace;
193+
189194
var rules = ps.AddCommand("Get-ScriptAnalyzerRule").Invoke();
190195
var sb = new StringBuilder();
191196
sb.AppendLine("Available PSScriptAnalyzer Rules:");
197+
192198
foreach (var rule in rules)
193199
{
194200
sb.AppendLine((string)rule.Members["RuleName"].Value);
195201
}
202+
196203
Logger.Write(LogLevel.Verbose, sb.ToString());
197204
}
198205
}
@@ -209,6 +216,7 @@ private void InitializePSScriptAnalyzer()
209216
private IEnumerable<PSObject> GetDiagnosticRecords(ScriptFile file)
210217
{
211218
IEnumerable<PSObject> diagnosticRecords = Enumerable.Empty<PSObject>();
219+
212220
if (this.scriptAnalyzerModuleInfo != null)
213221
{
214222
using (var ps = System.Management.Automation.PowerShell.Create())
@@ -218,15 +226,17 @@ private IEnumerable<PSObject> GetDiagnosticRecords(ScriptFile file)
218226
LogLevel.Verbose,
219227
String.Format("Running PSScriptAnalyzer against {0}", file.FilePath));
220228

221-
// currently not working with include rules
222229
diagnosticRecords = ps.AddCommand("Invoke-ScriptAnalyzer")
223230
.AddParameter("ScriptDefinition", file.Contents)
231+
.AddParameter("IncludeRule", IncludedRules)
224232
.Invoke();
225233
}
226234
}
235+
227236
Logger.Write(
228237
LogLevel.Verbose,
229238
String.Format("Found {0} violations", diagnosticRecords.Count()));
239+
230240
return diagnosticRecords;
231241
}
232242

0 commit comments

Comments
 (0)