Skip to content

Commit f496209

Browse files
committed
Refactor Script Analyzer to work as .NET library
This change refactors the existing codebase to move all logic into the ScriptAnalyzer class.
1 parent 3485d15 commit f496209

6 files changed

+673
-552
lines changed

Engine/Commands/GetScriptAnalyzerRuleCommand.cs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands
2424
/// GetScriptAnalyzerRuleCommand: Cmdlet to list all the analyzer rule names and descriptions.
2525
/// </summary>
2626
[Cmdlet(VerbsCommon.Get, "ScriptAnalyzerRule", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=525913")]
27-
public class GetScriptAnalyzerRuleCommand : PSCmdlet
27+
public class GetScriptAnalyzerRuleCommand : PSCmdlet, IOutputWriter
2828
{
2929
#region Parameters
3030
/// <summary>
@@ -82,43 +82,7 @@ public string[] Severity
8282
/// </summary>
8383
protected override void BeginProcessing()
8484
{
85-
#region Set PSCmdlet property of Helper
86-
87-
Helper.Instance.MyCmdlet = this;
88-
89-
#endregion
90-
// Verifies rule extensions
91-
if (customizedRulePath != null)
92-
{
93-
validationResults = ScriptAnalyzer.Instance.CheckRuleExtension(customizedRulePath, this);
94-
foreach (string extension in validationResults["InvalidPaths"])
95-
{
96-
WriteWarning(string.Format(CultureInfo.CurrentCulture,Strings.MissingRuleExtension, extension));
97-
}
98-
}
99-
else
100-
{
101-
validationResults.Add("InvalidPaths", new List<string>());
102-
validationResults.Add("ValidModPaths", new List<string>());
103-
validationResults.Add("ValidDllPaths", new List<string>());
104-
}
105-
106-
try
107-
{
108-
if (validationResults["ValidDllPaths"].Count == 0)
109-
{
110-
ScriptAnalyzer.Instance.Initialize();
111-
}
112-
else
113-
{
114-
ScriptAnalyzer.Instance.Initilaize(validationResults);
115-
}
116-
}
117-
catch (Exception ex)
118-
{
119-
ThrowTerminatingError(new ErrorRecord(ex, ex.HResult.ToString("X", CultureInfo.CurrentCulture),
120-
ErrorCategory.NotSpecified, this));
121-
}
85+
ScriptAnalyzer.Instance.Initialize(this, customizedRulePath);
12286
}
12387

12488
/// <summary>

0 commit comments

Comments
 (0)