diff --git a/Engine/CommandInfoCache.cs b/Engine/CommandInfoCache.cs index dbcb41eda..71c37d83c 100644 --- a/Engine/CommandInfoCache.cs +++ b/Engine/CommandInfoCache.cs @@ -15,17 +15,15 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer internal class CommandInfoCache : IDisposable { private readonly ConcurrentDictionary> _commandInfoCache; - private readonly Helper _helperInstance; private readonly RunspacePool _runspacePool; private bool disposed = false; /// /// Create a fresh command info cache instance. /// - public CommandInfoCache(Helper pssaHelperInstance) + public CommandInfoCache() { _commandInfoCache = new ConcurrentDictionary>(); - _helperInstance = pssaHelperInstance; _runspacePool = RunspaceFactory.CreateRunspacePool(1, 10); _runspacePool.Open(); } diff --git a/Engine/Commands/GetScriptAnalyzerRuleCommand.cs b/Engine/Commands/GetScriptAnalyzerRuleCommand.cs index 7a9d50561..3219affa7 100644 --- a/Engine/Commands/GetScriptAnalyzerRuleCommand.cs +++ b/Engine/Commands/GetScriptAnalyzerRuleCommand.cs @@ -84,13 +84,12 @@ protected override void BeginProcessing() // Initialize helper Helper.Instance = new Helper( - SessionState.InvokeCommand, - this); + SessionState.InvokeCommand); Helper.Instance.Initialize(); string[] rulePaths = Helper.ProcessCustomRulePaths(customRulePath, this.SessionState, recurseCustomRulePath); - ScriptAnalyzer.Instance.Initialize(this, rulePaths, null, null, null, null == rulePaths ? true : false); + ScriptAnalyzer.Instance.Initialize(this, rulePaths, null, null, null, null == rulePaths); } /// diff --git a/Engine/Commands/InvokeFormatterCommand.cs b/Engine/Commands/InvokeFormatterCommand.cs index d08d8c817..25a2d364e 100644 --- a/Engine/Commands/InvokeFormatterCommand.cs +++ b/Engine/Commands/InvokeFormatterCommand.cs @@ -124,11 +124,5 @@ protected override void StopProcessing() ScriptAnalyzer.Instance.CleanUp(); base.StopProcessing(); } - - private void ValidateInputSettings() - { - // todo implement this - return; - } } } diff --git a/Engine/Commands/InvokeScriptAnalyzerCommand.cs b/Engine/Commands/InvokeScriptAnalyzerCommand.cs index 77364ac9c..3be9cd7fc 100644 --- a/Engine/Commands/InvokeScriptAnalyzerCommand.cs +++ b/Engine/Commands/InvokeScriptAnalyzerCommand.cs @@ -285,8 +285,7 @@ protected override void BeginProcessing() } #endif Helper.Instance = new Helper( - SessionState.InvokeCommand, - this); + SessionState.InvokeCommand); Helper.Instance.Initialize(); var psVersionTable = this.SessionState.PSVariable.GetValue("PSVersionTable") as Hashtable; diff --git a/Engine/Formatter.cs b/Engine/Formatter.cs index 3c1325a5d..dd9632582 100644 --- a/Engine/Formatter.cs +++ b/Engine/Formatter.cs @@ -32,7 +32,7 @@ public static string Format( ValidateNotNull(settings, "settings"); ValidateNotNull(cmdlet, "cmdlet"); - Helper.Instance = new Helper(cmdlet.SessionState.InvokeCommand, cmdlet); + Helper.Instance = new Helper(cmdlet.SessionState.InvokeCommand); Helper.Instance.Initialize(); var ruleOrder = new string[] diff --git a/Engine/Generic/ModuleDependencyHandler.cs b/Engine/Generic/ModuleDependencyHandler.cs index 347b9a9a1..31a43d6ca 100644 --- a/Engine/Generic/ModuleDependencyHandler.cs +++ b/Engine/Generic/ModuleDependencyHandler.cs @@ -22,7 +22,6 @@ public class ModuleDependencyHandler : IDisposable private string moduleRepository; private string tempPath; // path to the user temporary directory private string tempModulePath; // path to temp directory containing modules - Dictionary modulesFound; private string localAppdataPath; private string pssaAppDataPath; private const string symLinkName = "TempModuleDir"; @@ -271,8 +270,6 @@ public ModuleDependencyHandler( ? "PSScriptAnalyzer" : pssaAppDataPath); - modulesFound = new Dictionary(StringComparer.OrdinalIgnoreCase); - // TODO Add PSSA Version in the path symLinkPath = Path.Combine(pssaAppDataPath, symLinkName); SetupPSSAAppData(); diff --git a/Engine/Helper.cs b/Engine/Helper.cs index feea8a5ec..528a3fe88 100644 --- a/Engine/Helper.cs +++ b/Engine/Helper.cs @@ -24,7 +24,6 @@ public class Helper #region Private members private CommandInvocationIntrinsics invokeCommand; - private IOutputWriter outputWriter; private readonly static Version minSupportedPSVersion = new Version(3, 0); private Dictionary> ruleArguments; private PSVersionTable psVersionTable; @@ -115,7 +114,7 @@ internal set /// private Helper() { - _commandInfoCacheLazy = new Lazy(() => new CommandInfoCache(pssaHelperInstance: this)); + _commandInfoCacheLazy = new Lazy(() => new CommandInfoCache()); } /// @@ -125,16 +124,11 @@ private Helper() /// A CommandInvocationIntrinsics instance for use in gathering /// information about available commands and aliases. /// - /// - /// An IOutputWriter instance for use in writing output - /// to the PowerShell environment. - /// public Helper( - CommandInvocationIntrinsics invokeCommand, - IOutputWriter outputWriter) : this() + CommandInvocationIntrinsics invokeCommand + ): this() { this.invokeCommand = invokeCommand; - this.outputWriter = outputWriter; } #region Methods diff --git a/Engine/ScriptAnalyzer.cs b/Engine/ScriptAnalyzer.cs index d35ab7e0a..1a885eabe 100644 --- a/Engine/ScriptAnalyzer.cs +++ b/Engine/ScriptAnalyzer.cs @@ -168,8 +168,7 @@ public void Initialize( //initialize helper Helper.Instance = new Helper( - runspace.SessionStateProxy.InvokeCommand, - outputWriter); + runspace.SessionStateProxy.InvokeCommand); Helper.Instance.Initialize(); SuppressionPreference suppressionPreference = suppressedOnly diff --git a/Engine/Settings.cs b/Engine/Settings.cs index b13f9405b..a4931978c 100644 --- a/Engine/Settings.cs +++ b/Engine/Settings.cs @@ -285,17 +285,6 @@ private Dictionary GetDictionaryFromHashtable(Hashtable hashtabl return dictionary; } - private bool IsStringOrStringArray(object val) - { - if (val is string) - { - return true; - } - - var valArr = val as object[]; - return val == null ? false : valArr.All(x => x is string); - } - private List GetData(object val, string key) { // value must be either string or or an array of strings diff --git a/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PlatformInformationCollector.cs b/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PlatformInformationCollector.cs index 9a7eab952..26aa0ee7a 100644 --- a/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PlatformInformationCollector.cs +++ b/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PlatformInformationCollector.cs @@ -351,18 +351,6 @@ private Architecture GetOSArchitecture() #endif } - private DotnetRuntime GetDotnetRuntime() - { -#if CoreCLR - // Our CoreCLR is actuall .NET Standard, so we could be loaded into net47 - return RuntimeInformation.FrameworkDescription.StartsWith(".NET Core") - ? DotnetRuntime.Core - : DotnetRuntime.Framework; -#else - return DotnetRuntime.Framework; -#endif - } - /// /// Get the Windows SKU ID of the current PowerShell session. /// diff --git a/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Commands/CommandUtilities.cs b/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Commands/CommandUtilities.cs index 3e14494f1..6a957f7cc 100644 --- a/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Commands/CommandUtilities.cs +++ b/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Commands/CommandUtilities.cs @@ -13,8 +13,6 @@ namespace Microsoft.PowerShell.CrossCompatibility.Commands /// internal static class CommandUtilities { - private const string COMPATIBILITY_ERROR_ID = "CompatibilityAnalysisError"; - public const string MODULE_PREFIX = "PSCompatibility"; /// diff --git a/Rules/AvoidUserNameAndPasswordParams.cs b/Rules/AvoidUserNameAndPasswordParams.cs index 0609505fd..ced0c8ee1 100644 --- a/Rules/AvoidUserNameAndPasswordParams.cs +++ b/Rules/AvoidUserNameAndPasswordParams.cs @@ -86,7 +86,7 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) { yield return new DiagnosticRecord( String.Format(CultureInfo.CurrentCulture, Strings.AvoidUsernameAndPasswordParamsError, funcAst.Name), - GetExtent(usernameAst, passwordAst, ast), GetName(), DiagnosticSeverity.Error, fileName); + GetExtent(usernameAst, passwordAst), GetName(), DiagnosticSeverity.Error, fileName); } } } @@ -111,7 +111,7 @@ private bool IsAttributeOfType(AttributeBaseAst attributeAst, Type type) /// /// /// IScriptExtent - private IScriptExtent GetExtent(ParameterAst usernameAst, ParameterAst passwordAst, Ast scriptAst) + private IScriptExtent GetExtent(ParameterAst usernameAst, ParameterAst passwordAst) { var usrExt = usernameAst.Extent; var pwdExt = passwordAst.Extent; diff --git a/Rules/AvoidUsingDeprecatedManifestFields.cs b/Rules/AvoidUsingDeprecatedManifestFields.cs index 8856745d2..fd3431251 100644 --- a/Rules/AvoidUsingDeprecatedManifestFields.cs +++ b/Rules/AvoidUsingDeprecatedManifestFields.cs @@ -70,10 +70,9 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) if (value != null) { - Version psVersion = null; // get the version - if (Version.TryParse((value as StringConstantExpressionAst).Value, out psVersion)) + if (Version.TryParse((value as StringConstantExpressionAst).Value, out Version psVersion)) { // if version exists and version less than 3, don't raise rule if (psVersion.Major < 3) diff --git a/Rules/CompatibilityRules/UseCompatibleCommands.cs b/Rules/CompatibilityRules/UseCompatibleCommands.cs index 0f7cfadbf..bad708e2c 100644 --- a/Rules/CompatibilityRules/UseCompatibleCommands.cs +++ b/Rules/CompatibilityRules/UseCompatibleCommands.cs @@ -263,8 +263,7 @@ public static CommandCompatibilityDiagnostic CreateForParameter( PlatformData platform, IScriptExtent extent, string analyzedFileName, - IRule rule, - IEnumerable suggestedCorrections = null) + IRule rule) { string message = string.Format( CultureInfo.CurrentCulture, diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index da5cfb8a5..bbb12bd41 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -563,11 +563,6 @@ private static int ClipNegative(int x) return x > 0 ? x : 0; } - private int GetIndentationColumnNumber(int indentationLevel) - { - return GetIndentation(indentationLevel) + 1; - } - private int GetIndentation(int indentationLevel) { // todo if condition can be evaluated during rule configuration diff --git a/Rules/UseIdenticalMandatoryParametersDSC.cs b/Rules/UseIdenticalMandatoryParametersDSC.cs index 713b86814..56acb5b48 100644 --- a/Rules/UseIdenticalMandatoryParametersDSC.cs +++ b/Rules/UseIdenticalMandatoryParametersDSC.cs @@ -32,7 +32,6 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules public class UseIdenticalMandatoryParametersDSC : IDSCResourceRule { private bool isDSCClassCacheInitialized = false; - private Ast ast; private string fileName; private IDictionary propAttrDict; private IEnumerable resourceFunctions; @@ -94,7 +93,6 @@ public IEnumerable AnalyzeDSCResource(Ast ast, string fileName } // Get the keys in the corresponding mof file - this.ast = ast; this.fileName = fileName; this.propAttrDict = GetKeys(fileName); this.resourceFunctions = Helper.Instance.DscResourceFunctions(ast) diff --git a/Rules/UseToExportFieldsInManifest.cs b/Rules/UseToExportFieldsInManifest.cs index bfd99db9e..9bf612f83 100644 --- a/Rules/UseToExportFieldsInManifest.cs +++ b/Rules/UseToExportFieldsInManifest.cs @@ -69,7 +69,7 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) foreach(string field in manifestFields) { IScriptExtent extent; - if (!HasAcceptableExportField(field, hashtableAst, ast.Extent.Text, out extent) && extent != null) + if (!HasAcceptableExportField(field, hashtableAst, out extent) && extent != null) { yield return new DiagnosticRecord( GetError(field), @@ -200,10 +200,9 @@ private bool HasNullInExpression(Ast ast) /// /// /// - /// /// /// A boolean value indicating if the the ToExport fields are explicitly set to arrays or not. - private bool HasAcceptableExportField(string key, HashtableAst hast, string scriptText, out IScriptExtent extent) + private bool HasAcceptableExportField(string key, HashtableAst hast, out IScriptExtent extent) { extent = null; foreach (var pair in hast.KeyValuePairs)