Skip to content

Use a minimal set of Script Analyzer rules #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 37 additions & 23 deletions src/PowerShellEditorServices.Host/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,6 @@ class Program
[STAThread]
static void Main(string[] args)
{
#if DEBUG
// In the future, a more robust argument parser will be added here
bool waitForDebugger =
args.Any(
arg =>
string.Equals(
arg,
"/waitForDebugger",
StringComparison.InvariantCultureIgnoreCase));

// Should we wait for the debugger before starting?
if (waitForDebugger)
{
// Wait for 15 seconds and then continue
int waitCountdown = 15;
while (!Debugger.IsAttached && waitCountdown > 0)
{
Thread.Sleep(1000);
waitCountdown--;
}
}
#endif

string logPath = null;
string logPathArgument =
args.FirstOrDefault(
Expand Down Expand Up @@ -80,6 +57,43 @@ static void Main(string[] args)
// TODO: Set the level based on command line parameter
Logger.Initialize(logPath, LogLevel.Verbose);

#if DEBUG
bool waitForDebugger =
args.Any(
arg =>
string.Equals(
arg,
"/waitForDebugger",
StringComparison.InvariantCultureIgnoreCase));

// Should we wait for the debugger before starting?
if (waitForDebugger)
{
Logger.Write(LogLevel.Normal, "Waiting for debugger to attach before continuing...");

// Wait for 15 seconds and then continue
int waitCountdown = 15;
while (!Debugger.IsAttached && waitCountdown > 0)
{
Thread.Sleep(1000);
waitCountdown--;
}

if (Debugger.IsAttached)
{
Logger.Write(
LogLevel.Normal,
"Debugger attached, continuing startup sequence");
}
else if (waitCountdown == 0)
{
Logger.Write(
LogLevel.Normal,
"Timed out while waiting for debugger to attach, continuing startup sequence");
}
}
#endif

Logger.Write(LogLevel.Normal, "PowerShell Editor Services Host starting...");

// Start the server
Expand Down
20 changes: 16 additions & 4 deletions src/PowerShellEditorServices/Analysis/AnalysisService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ public class AnalysisService : IDisposable
private Runspace analysisRunspace;
private ScriptAnalyzer scriptAnalyzer;

/// <summary>
/// Defines the list of Script Analyzer rules to include by default.
/// In the future, a default rule set from Script Analyzer may be used.
/// </summary>
private static readonly string[] IncludedRules = new string[]
{
"PSUseApprovedVerbs",
"PSReservedCmdletChar",
"PSReservedParams",
"PSShouldProcess",
"PSMissingModuleManifestField",
"PSAvoidDefaultValueSwitchParameter",
"PSUseDeclaredVarsMoreThanAssigments"
};

#endregion

#region Constructors
Expand All @@ -32,8 +47,6 @@ public class AnalysisService : IDisposable
/// </summary>
public AnalysisService()
{
// TODO: Share runspace with PowerShellContext? Probably should always
// run analysis in a local session.
this.analysisRunspace = RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault2());
this.analysisRunspace.ApartmentState = ApartmentState.STA;
this.analysisRunspace.ThreadOptions = PSThreadOptions.ReuseThread;
Expand All @@ -44,8 +57,7 @@ public AnalysisService()
this.analysisRunspace,
new AnalysisOutputWriter(),
null,
null,
new string[] { "DscTestsPresent", "DscExamplesPresent" });
IncludedRules);
}

#endregion
Expand Down