Skip to content

Refactor Script Analyzer to be used as a .NET library #262

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
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
52 changes: 3 additions & 49 deletions Engine/Commands/GetScriptAnalyzerRuleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands
/// GetScriptAnalyzerRuleCommand: Cmdlet to list all the analyzer rule names and descriptions.
/// </summary>
[Cmdlet(VerbsCommon.Get, "ScriptAnalyzerRule", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=525913")]
public class GetScriptAnalyzerRuleCommand : PSCmdlet
public class GetScriptAnalyzerRuleCommand : PSCmdlet, IOutputWriter
{
#region Parameters
/// <summary>
Expand Down Expand Up @@ -69,68 +69,22 @@ public string[] Severity

#endregion Parameters

#region Private Members

Dictionary<string, List<string>> validationResults = new Dictionary<string, List<string>>();

#endregion

#region Overrides

/// <summary>
/// BeginProcessing : TBD
/// </summary>
protected override void BeginProcessing()
{
#region Set PSCmdlet property of Helper

Helper.Instance.MyCmdlet = this;

#endregion
// Verifies rule extensions
if (customizedRulePath != null)
{
validationResults = ScriptAnalyzer.Instance.CheckRuleExtension(customizedRulePath, this);
foreach (string extension in validationResults["InvalidPaths"])
{
WriteWarning(string.Format(CultureInfo.CurrentCulture,Strings.MissingRuleExtension, extension));
}
}
else
{
validationResults.Add("InvalidPaths", new List<string>());
validationResults.Add("ValidModPaths", new List<string>());
validationResults.Add("ValidDllPaths", new List<string>());
}

try
{
if (validationResults["ValidDllPaths"].Count == 0)
{
ScriptAnalyzer.Instance.Initialize();
}
else
{
ScriptAnalyzer.Instance.Initilaize(validationResults);
}
}
catch (Exception ex)
{
ThrowTerminatingError(new ErrorRecord(ex, ex.HResult.ToString("X", CultureInfo.CurrentCulture),
ErrorCategory.NotSpecified, this));
}
ScriptAnalyzer.Instance.Initialize(this, customizedRulePath);
}

/// <summary>
/// ProcessRecord : TBD
/// </summary>
protected override void ProcessRecord()
{
string[] modNames = null;
if (validationResults["ValidModPaths"].Count > 0)
{
modNames = validationResults["ValidModPaths"].ToArray<string>();
}
string[] modNames = ScriptAnalyzer.Instance.GetValidModulePaths();

IEnumerable<IRule> rules = ScriptAnalyzer.Instance.GetRule(modNames, name);
if (rules == null)
Expand Down
Loading