From 07825ce9bbcca8dfb0d5df65b8f1cd0d34d93d8c Mon Sep 17 00:00:00 2001 From: Thomas Rayner Date: Wed, 16 Oct 2019 14:05:25 -0700 Subject: [PATCH] remove unneeded else --- Rules/AvoidOverwritingBuiltInCmdlets.cs | 94 ++++++++++++------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/Rules/AvoidOverwritingBuiltInCmdlets.cs b/Rules/AvoidOverwritingBuiltInCmdlets.cs index 6b7f669c1..f131f3176 100644 --- a/Rules/AvoidOverwritingBuiltInCmdlets.cs +++ b/Rules/AvoidOverwritingBuiltInCmdlets.cs @@ -72,70 +72,68 @@ public override IEnumerable AnalyzeScript(Ast ast, string file return null; } - else - { - var diagnosticRecords = new List(); - string versionTest = string.Join("", PowerShellVersion); - if (string.IsNullOrEmpty(versionTest)) + var diagnosticRecords = new List(); + string versionTest = string.Join("", PowerShellVersion); + + if (string.IsNullOrEmpty(versionTest)) + { + // PowerShellVersion is not already set to one of the acceptable defaults + // Try launching `pwsh -v` to see if PowerShell 6+ is installed, and use those cmdlets + // as a default. If 6+ is not installed this will throw an error, which when caught will + // allow us to use the PowerShell 5 cmdlets as a default. + var testProcess = new Process(); + testProcess.StartInfo.FileName = "pwsh"; + testProcess.StartInfo.Arguments = "-v"; + testProcess.StartInfo.CreateNoWindow = true; + testProcess.StartInfo.UseShellExecute = false; + + try { - // PowerShellVersion is not already set to one of the acceptable defaults - // Try launching `pwsh -v` to see if PowerShell 6+ is installed, and use those cmdlets - // as a default. If 6+ is not installed this will throw an error, which when caught will - // allow us to use the PowerShell 5 cmdlets as a default. - var testProcess = new Process(); - testProcess.StartInfo.FileName = "pwsh"; - testProcess.StartInfo.Arguments = "-v"; - testProcess.StartInfo.CreateNoWindow = true; - testProcess.StartInfo.UseShellExecute = false; - - try - { - testProcess.Start(); - PowerShellVersion = new[] { "core-6.1.0-windows" }; - } - catch - { - PowerShellVersion = new[] { "desktop-5.1.14393.206-windows" }; - } - finally - { - testProcess.Dispose(); - } + testProcess.Start(); + PowerShellVersion = new[] { "core-6.1.0-windows" }; } - - var psVerList = PowerShellVersion; - string settingsPath = Settings.GetShippedSettingsDirectory(); - - foreach (string reference in psVerList) + catch { - if (settingsPath == null || !ContainsReferenceFile(settingsPath, reference)) - { - throw new ArgumentException(nameof(PowerShellVersion)); - } + PowerShellVersion = new[] { "desktop-5.1.14393.206-windows" }; } + finally + { + testProcess.Dispose(); + } + } - ProcessDirectory(settingsPath, psVerList); + var psVerList = PowerShellVersion; + string settingsPath = Settings.GetShippedSettingsDirectory(); - if (_cmdletMap.Keys.Count != psVerList.Count()) + foreach (string reference in psVerList) + { + if (settingsPath == null || !ContainsReferenceFile(settingsPath, reference)) { throw new ArgumentException(nameof(PowerShellVersion)); } + } + + ProcessDirectory(settingsPath, psVerList); - foreach (FunctionDefinitionAst functionDef in functionDefinitions) + if (_cmdletMap.Keys.Count != psVerList.Count()) + { + throw new ArgumentException(nameof(PowerShellVersion)); + } + + foreach (FunctionDefinitionAst functionDef in functionDefinitions) + { + string functionName = functionDef.Name; + foreach (KeyValuePair> cmdletSet in _cmdletMap) { - string functionName = functionDef.Name; - foreach (KeyValuePair> cmdletSet in _cmdletMap) + if (cmdletSet.Value.Contains(functionName)) { - if (cmdletSet.Value.Contains(functionName)) - { - diagnosticRecords.Add(CreateDiagnosticRecord(functionName, cmdletSet.Key, functionDef.Extent)); - } + diagnosticRecords.Add(CreateDiagnosticRecord(functionName, cmdletSet.Key, functionDef.Extent)); } } - - return diagnosticRecords; } + + return diagnosticRecords; }