Skip to content

Commit 03fc2bd

Browse files
author
Robert Holt
committed
Code cleanup
1 parent b4f5867 commit 03fc2bd

File tree

5 files changed

+17
-33
lines changed

5 files changed

+17
-33
lines changed

Engine/Commands/GetScriptAnalyzerRuleCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ protected override void BeginProcessing()
8383
{
8484

8585
// Initialize helper
86-
Helper.Instance = new Helper(
87-
SessionState.InvokeCommand,
88-
this);
86+
Helper.Instance = new Helper(SessionState.InvokeCommand);
8987
Helper.Instance.Initialize();
9088

9189
string[] rulePaths = Helper.ProcessCustomRulePaths(customRulePath,

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@ protected override void BeginProcessing()
265265
}
266266
}
267267
#endif
268-
Helper.Instance = new Helper(
269-
SessionState.InvokeCommand,
270-
this);
268+
Helper.Instance = new Helper(SessionState.InvokeCommand);
271269
Helper.Instance.Initialize();
272270

273271
var psVersionTable = this.SessionState.PSVariable.GetValue("PSVersionTable") as Hashtable;

Engine/Formatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static string Format<TCmdlet>(
3131
ValidateNotNull(settings, "settings");
3232
ValidateNotNull(cmdlet, "cmdlet");
3333

34-
Helper.Instance = new Helper(cmdlet.SessionState.InvokeCommand, cmdlet);
34+
Helper.Instance = new Helper(cmdlet.SessionState.InvokeCommand);
3535
Helper.Instance.Initialize();
3636

3737
var ruleOrder = new string[]

Engine/Helper.cs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public class Helper
2828

2929
private readonly CommandInvocationIntrinsics _invokeCommand;
3030

31-
private readonly IOutputWriter _outputWriter;
32-
3331
private Dictionary<string, Dictionary<string, object>> _ruleArguments;
3432

3533
private PSVersionTable _psVersionTable;
@@ -125,16 +123,15 @@ private Helper()
125123
/// A CommandInvocationIntrinsics instance for use in gathering
126124
/// information about available commands and aliases.
127125
/// </param>
128-
/// <param name="outputWriter">
129-
/// An IOutputWriter instance for use in writing output
130-
/// to the PowerShell environment.
131-
/// </param>
132-
public Helper(
133-
CommandInvocationIntrinsics invokeCommand,
134-
IOutputWriter outputWriter)
126+
public Helper(CommandInvocationIntrinsics invokeCommand)
135127
{
136-
this._invokeCommand = invokeCommand;
137-
this._outputWriter = outputWriter;
128+
_invokeCommand = invokeCommand;
129+
_ruleArguments = new Dictionary<string, Dictionary<string, object>>(StringComparer.OrdinalIgnoreCase);
130+
_commandInfoCache = new Lazy<CommandInfoCache>(() => new CommandInfoCache());
131+
CmdletToAliasDictionary = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
132+
AliasToCmdletDictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
133+
KeywordBlockDictionary = new Dictionary<string, List<Tuple<int, int>>>(StringComparer.OrdinalIgnoreCase);
134+
VariableAnalysisDictionary = new Dictionary<Ast, VariableAnalysis>();
138135
}
139136

140137
#region Methods
@@ -143,20 +140,13 @@ public Helper(
143140
/// </summary>
144141
public void Initialize()
145142
{
146-
CmdletToAliasDictionary = new Dictionary<String, List<String>>(StringComparer.OrdinalIgnoreCase);
147-
AliasToCmdletDictionary = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
148-
KeywordBlockDictionary = new Dictionary<String, List<Tuple<int, int>>>(StringComparer.OrdinalIgnoreCase);
149-
VariableAnalysisDictionary = new Dictionary<Ast, VariableAnalysis>();
150-
_ruleArguments = new Dictionary<string, Dictionary<string, object>>(StringComparer.OrdinalIgnoreCase);
151-
_commandInfoCache = new Lazy<CommandInfoCache>(() => new CommandInfoCache());
152-
153-
IEnumerable<CommandInfo> aliases = this._invokeCommand.GetCommands("*", CommandTypes.Alias, true);
143+
IEnumerable<CommandInfo> aliases = _invokeCommand.GetCommands("*", CommandTypes.Alias, nameIsPattern: true);
154144

155145
foreach (AliasInfo aliasInfo in aliases)
156146
{
157147
if (!CmdletToAliasDictionary.ContainsKey(aliasInfo.Definition))
158148
{
159-
CmdletToAliasDictionary.Add(aliasInfo.Definition, new List<String>() { aliasInfo.Name });
149+
CmdletToAliasDictionary.Add(aliasInfo.Definition, new List<string>() { aliasInfo.Name });
160150
}
161151
else
162152
{
@@ -1600,7 +1590,7 @@ public NamedAttributeArgumentAst GetShouldProcessAttributeAst(IEnumerable<Attrib
16001590
{
16011591
throw new ArgumentNullException("attributeAsts");
16021592
}
1603-
var cmdletBindingAttributeAst = this.GetCmdletBindingAttributeAst(attributeAsts);
1593+
var cmdletBindingAttributeAst = GetCmdletBindingAttributeAst(attributeAsts);
16041594
if (cmdletBindingAttributeAst == null
16051595
|| cmdletBindingAttributeAst.NamedArguments == null)
16061596
{
@@ -1883,7 +1873,7 @@ public void SetPSVersionTable(Hashtable psVersionTable)
18831873
throw new ArgumentNullException("psVersionTable");
18841874
}
18851875

1886-
this._psVersionTable = new PSVersionTable(psVersionTable);
1876+
_psVersionTable = new PSVersionTable(psVersionTable);
18871877
}
18881878

18891879
#if CORECLR
@@ -1892,7 +1882,7 @@ public SemanticVersion GetPSVersion()
18921882
public Version GetPSVersion()
18931883
#endif
18941884
{
1895-
return _psVersionTable == null ? null : _psVersionTable.PSVersion;
1885+
return _psVersionTable?.PSVersion;
18961886
}
18971887

18981888
#endregion Methods

Engine/ScriptAnalyzer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ public void Initialize(
158158
}
159159

160160
//initialize helper
161-
Helper.Instance = new Helper(
162-
runspace.SessionStateProxy.InvokeCommand,
163-
outputWriter);
161+
Helper.Instance = new Helper(runspace.SessionStateProxy.InvokeCommand);
164162
Helper.Instance.Initialize();
165163

166164

0 commit comments

Comments
 (0)