Skip to content

Commit 4397b4a

Browse files
committed
Merge pull request #70 from PowerShell/daviwil/minimal-analysis-rules
Use a minimal set of Script Analyzer rules
2 parents 443641c + ba69936 commit 4397b4a

File tree

2 files changed

+53
-27
lines changed

2 files changed

+53
-27
lines changed

src/PowerShellEditorServices.Host/Program.cs

+37-23
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,6 @@ class Program
1717
[STAThread]
1818
static void Main(string[] args)
1919
{
20-
#if DEBUG
21-
// In the future, a more robust argument parser will be added here
22-
bool waitForDebugger =
23-
args.Any(
24-
arg =>
25-
string.Equals(
26-
arg,
27-
"/waitForDebugger",
28-
StringComparison.InvariantCultureIgnoreCase));
29-
30-
// Should we wait for the debugger before starting?
31-
if (waitForDebugger)
32-
{
33-
// Wait for 15 seconds and then continue
34-
int waitCountdown = 15;
35-
while (!Debugger.IsAttached && waitCountdown > 0)
36-
{
37-
Thread.Sleep(1000);
38-
waitCountdown--;
39-
}
40-
}
41-
#endif
42-
4320
string logPath = null;
4421
string logPathArgument =
4522
args.FirstOrDefault(
@@ -80,6 +57,43 @@ static void Main(string[] args)
8057
// TODO: Set the level based on command line parameter
8158
Logger.Initialize(logPath, LogLevel.Verbose);
8259

60+
#if DEBUG
61+
bool waitForDebugger =
62+
args.Any(
63+
arg =>
64+
string.Equals(
65+
arg,
66+
"/waitForDebugger",
67+
StringComparison.InvariantCultureIgnoreCase));
68+
69+
// Should we wait for the debugger before starting?
70+
if (waitForDebugger)
71+
{
72+
Logger.Write(LogLevel.Normal, "Waiting for debugger to attach before continuing...");
73+
74+
// Wait for 15 seconds and then continue
75+
int waitCountdown = 15;
76+
while (!Debugger.IsAttached && waitCountdown > 0)
77+
{
78+
Thread.Sleep(1000);
79+
waitCountdown--;
80+
}
81+
82+
if (Debugger.IsAttached)
83+
{
84+
Logger.Write(
85+
LogLevel.Normal,
86+
"Debugger attached, continuing startup sequence");
87+
}
88+
else if (waitCountdown == 0)
89+
{
90+
Logger.Write(
91+
LogLevel.Normal,
92+
"Timed out while waiting for debugger to attach, continuing startup sequence");
93+
}
94+
}
95+
#endif
96+
8397
Logger.Write(LogLevel.Normal, "PowerShell Editor Services Host starting...");
8498

8599
// Start the server

src/PowerShellEditorServices/Analysis/AnalysisService.cs

+16-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ public class AnalysisService : IDisposable
2323
private Runspace analysisRunspace;
2424
private ScriptAnalyzer scriptAnalyzer;
2525

26+
/// <summary>
27+
/// Defines the list of Script Analyzer rules to include by default.
28+
/// In the future, a default rule set from Script Analyzer may be used.
29+
/// </summary>
30+
private static readonly string[] IncludedRules = new string[]
31+
{
32+
"PSUseApprovedVerbs",
33+
"PSReservedCmdletChar",
34+
"PSReservedParams",
35+
"PSShouldProcess",
36+
"PSMissingModuleManifestField",
37+
"PSAvoidDefaultValueSwitchParameter",
38+
"PSUseDeclaredVarsMoreThanAssigments"
39+
};
40+
2641
#endregion
2742

2843
#region Constructors
@@ -32,8 +47,6 @@ public class AnalysisService : IDisposable
3247
/// </summary>
3348
public AnalysisService()
3449
{
35-
// TODO: Share runspace with PowerShellContext? Probably should always
36-
// run analysis in a local session.
3750
this.analysisRunspace = RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault2());
3851
this.analysisRunspace.ApartmentState = ApartmentState.STA;
3952
this.analysisRunspace.ThreadOptions = PSThreadOptions.ReuseThread;
@@ -44,8 +57,7 @@ public AnalysisService()
4457
this.analysisRunspace,
4558
new AnalysisOutputWriter(),
4659
null,
47-
null,
48-
new string[] { "DscTestsPresent", "DscExamplesPresent" });
60+
IncludedRules);
4961
}
5062

5163
#endregion

0 commit comments

Comments
 (0)