Skip to content

Commit

Permalink
remove unneeded else
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrayner committed Oct 16, 2019
1 parent aeea36c commit 07825ce
Showing 1 changed file with 46 additions and 48 deletions.
94 changes: 46 additions & 48 deletions Rules/AvoidOverwritingBuiltInCmdlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,70 +72,68 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
return null;
}

else
{
var diagnosticRecords = new List<DiagnosticRecord>();
string versionTest = string.Join("", PowerShellVersion);

if (string.IsNullOrEmpty(versionTest))
var diagnosticRecords = new List<DiagnosticRecord>();
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<string, HashSet<string>> cmdletSet in _cmdletMap)
{
string functionName = functionDef.Name;
foreach (KeyValuePair<string, HashSet<string>> 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;
}


Expand Down

0 comments on commit 07825ce

Please sign in to comment.