Skip to content

Commit bd79460

Browse files
authored
Remove dead code and simplify (#1856)
* Remove unused variables * simplify code and remove unused method * remove unused member * more cleanup * more cleanup * more * more
1 parent 85ad15b commit bd79460

17 files changed

+15
-70
lines changed

Engine/CommandInfoCache.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
1515
internal class CommandInfoCache : IDisposable
1616
{
1717
private readonly ConcurrentDictionary<CommandLookupKey, Lazy<CommandInfo>> _commandInfoCache;
18-
private readonly Helper _helperInstance;
1918
private readonly RunspacePool _runspacePool;
2019
private bool disposed = false;
2120

2221
/// <summary>
2322
/// Create a fresh command info cache instance.
2423
/// </summary>
25-
public CommandInfoCache(Helper pssaHelperInstance)
24+
public CommandInfoCache()
2625
{
2726
_commandInfoCache = new ConcurrentDictionary<CommandLookupKey, Lazy<CommandInfo>>();
28-
_helperInstance = pssaHelperInstance;
2927
_runspacePool = RunspaceFactory.CreateRunspacePool(1, 10);
3028
_runspacePool.Open();
3129
}

Engine/Commands/GetScriptAnalyzerRuleCommand.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,12 @@ protected override void BeginProcessing()
8484

8585
// Initialize helper
8686
Helper.Instance = new Helper(
87-
SessionState.InvokeCommand,
88-
this);
87+
SessionState.InvokeCommand);
8988
Helper.Instance.Initialize();
9089

9190
string[] rulePaths = Helper.ProcessCustomRulePaths(customRulePath,
9291
this.SessionState, recurseCustomRulePath);
93-
ScriptAnalyzer.Instance.Initialize(this, rulePaths, null, null, null, null == rulePaths ? true : false);
92+
ScriptAnalyzer.Instance.Initialize(this, rulePaths, null, null, null, null == rulePaths);
9493
}
9594

9695
/// <summary>

Engine/Commands/InvokeFormatterCommand.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,5 @@ protected override void StopProcessing()
124124
ScriptAnalyzer.Instance.CleanUp();
125125
base.StopProcessing();
126126
}
127-
128-
private void ValidateInputSettings()
129-
{
130-
// todo implement this
131-
return;
132-
}
133127
}
134128
}

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ protected override void BeginProcessing()
285285
}
286286
#endif
287287
Helper.Instance = new Helper(
288-
SessionState.InvokeCommand,
289-
this);
288+
SessionState.InvokeCommand);
290289
Helper.Instance.Initialize();
291290

292291
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
@@ -32,7 +32,7 @@ public static string Format<TCmdlet>(
3232
ValidateNotNull(settings, "settings");
3333
ValidateNotNull(cmdlet, "cmdlet");
3434

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

3838
var ruleOrder = new string[]

Engine/Generic/ModuleDependencyHandler.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public class ModuleDependencyHandler : IDisposable
2222
private string moduleRepository;
2323
private string tempPath; // path to the user temporary directory
2424
private string tempModulePath; // path to temp directory containing modules
25-
Dictionary<string, PSObject> modulesFound;
2625
private string localAppdataPath;
2726
private string pssaAppDataPath;
2827
private const string symLinkName = "TempModuleDir";
@@ -271,8 +270,6 @@ public ModuleDependencyHandler(
271270
? "PSScriptAnalyzer"
272271
: pssaAppDataPath);
273272

274-
modulesFound = new Dictionary<string, PSObject>(StringComparer.OrdinalIgnoreCase);
275-
276273
// TODO Add PSSA Version in the path
277274
symLinkPath = Path.Combine(pssaAppDataPath, symLinkName);
278275
SetupPSSAAppData();

Engine/Helper.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public class Helper
2424
#region Private members
2525

2626
private CommandInvocationIntrinsics invokeCommand;
27-
private IOutputWriter outputWriter;
2827
private readonly static Version minSupportedPSVersion = new Version(3, 0);
2928
private Dictionary<string, Dictionary<string, object>> ruleArguments;
3029
private PSVersionTable psVersionTable;
@@ -115,7 +114,7 @@ internal set
115114
/// </summary>
116115
private Helper()
117116
{
118-
_commandInfoCacheLazy = new Lazy<CommandInfoCache>(() => new CommandInfoCache(pssaHelperInstance: this));
117+
_commandInfoCacheLazy = new Lazy<CommandInfoCache>(() => new CommandInfoCache());
119118
}
120119

121120
/// <summary>
@@ -125,16 +124,11 @@ private Helper()
125124
/// A CommandInvocationIntrinsics instance for use in gathering
126125
/// information about available commands and aliases.
127126
/// </param>
128-
/// <param name="outputWriter">
129-
/// An IOutputWriter instance for use in writing output
130-
/// to the PowerShell environment.
131-
/// </param>
132127
public Helper(
133-
CommandInvocationIntrinsics invokeCommand,
134-
IOutputWriter outputWriter) : this()
128+
CommandInvocationIntrinsics invokeCommand
129+
): this()
135130
{
136131
this.invokeCommand = invokeCommand;
137-
this.outputWriter = outputWriter;
138132
}
139133

140134
#region Methods

Engine/ScriptAnalyzer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ public void Initialize(
168168

169169
//initialize helper
170170
Helper.Instance = new Helper(
171-
runspace.SessionStateProxy.InvokeCommand,
172-
outputWriter);
171+
runspace.SessionStateProxy.InvokeCommand);
173172
Helper.Instance.Initialize();
174173

175174
SuppressionPreference suppressionPreference = suppressedOnly

Engine/Settings.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,6 @@ private Dictionary<string, object> GetDictionaryFromHashtable(Hashtable hashtabl
285285
return dictionary;
286286
}
287287

288-
private bool IsStringOrStringArray(object val)
289-
{
290-
if (val is string)
291-
{
292-
return true;
293-
}
294-
295-
var valArr = val as object[];
296-
return val == null ? false : valArr.All(x => x is string);
297-
}
298-
299288
private List<string> GetData(object val, string key)
300289
{
301290
// value must be either string or or an array of strings

PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PlatformInformationCollector.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -351,18 +351,6 @@ private Architecture GetOSArchitecture()
351351
#endif
352352
}
353353

354-
private DotnetRuntime GetDotnetRuntime()
355-
{
356-
#if CoreCLR
357-
// Our CoreCLR is actuall .NET Standard, so we could be loaded into net47
358-
return RuntimeInformation.FrameworkDescription.StartsWith(".NET Core")
359-
? DotnetRuntime.Core
360-
: DotnetRuntime.Framework;
361-
#else
362-
return DotnetRuntime.Framework;
363-
#endif
364-
}
365-
366354
/// <summary>
367355
/// Get the Windows SKU ID of the current PowerShell session.
368356
/// </summary>

0 commit comments

Comments
 (0)