Skip to content

Commit d027b4e

Browse files
author
Kapil Borle
committed
Move GetShippedSettingsDirectory to helper
1 parent 853c3d8 commit d027b4e

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

Engine/Helper.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic;
2222
using System.Management.Automation.Runspaces;
2323
using System.Collections;
24+
using System.Reflection;
2425

2526
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
2627
{
@@ -172,6 +173,35 @@ public void Initialize()
172173
}
173174
}
174175

176+
/// <summary>
177+
/// Retrieves the Settings directory from the Module directory structure
178+
/// </summary>
179+
public static string GetShippedSettingsDirectory()
180+
{
181+
// Find the compatibility files in Settings folder
182+
var path = typeof(Helper).GetTypeInfo().Assembly.Location;
183+
if (String.IsNullOrWhiteSpace(path))
184+
{
185+
return null;
186+
}
187+
188+
var settingsPath = Path.Combine(Path.GetDirectoryName(path), "Settings");
189+
if (!Directory.Exists(settingsPath))
190+
{
191+
// try one level down as the PSScriptAnalyzer module structure is not consistent
192+
// CORECLR binaries are in PSScriptAnalyzer/coreclr/, PowerShell v3 binaries are in PSScriptAnalyzer/PSv3/
193+
// and PowerShell v5 binaries are in PSScriptAnalyzer/
194+
settingsPath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(path)), "Settings");
195+
if (!Directory.Exists(settingsPath))
196+
{
197+
return null;
198+
}
199+
}
200+
201+
return settingsPath;
202+
}
203+
204+
175205
/// <summary>
176206
/// Returns all the rule arguments
177207
/// </summary>

Rules/UseCompatibleCmdlets.cs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ private void SetupCmdletsDictionary()
306306
return;
307307
}
308308

309-
string settingsPath;
310-
settingsPath = GetShippedSettingsDirectory();
309+
string settingsPath = Helper.GetShippedSettingsDirectory();
311310
#if DEBUG
312311
object modeObject;
313312
if (ruleArgs.TryGetValue("mode", out modeObject))
@@ -381,34 +380,6 @@ private void ResetCurCmdletCompatibilityMap()
381380
}
382381
}
383382

384-
/// <summary>
385-
/// Retrieves the Settings directory from the Module directory structure
386-
/// </summary>
387-
private string GetShippedSettingsDirectory()
388-
{
389-
// Find the compatibility files in Settings folder
390-
var path = this.GetType().GetTypeInfo().Assembly.Location;
391-
if (String.IsNullOrWhiteSpace(path))
392-
{
393-
return null;
394-
}
395-
396-
var settingsPath = Path.Combine(Path.GetDirectoryName(path), "Settings");
397-
if (!Directory.Exists(settingsPath))
398-
{
399-
// try one level down as the PSScriptAnalyzer module structure is not consistent
400-
// CORECLR binaries are in PSScriptAnalyzer/coreclr/, PowerShell v3 binaries are in PSScriptAnalyzer/PSv3/
401-
// and PowerShell v5 binaries are in PSScriptAnalyzer/
402-
settingsPath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(path)), "Settings");
403-
if (!Directory.Exists(settingsPath))
404-
{
405-
return null;
406-
}
407-
}
408-
409-
return settingsPath;
410-
}
411-
412383
private bool IsValidPlatformString(string fileNameWithoutExt)
413384
{
414385
string psedition, psversion, os;

0 commit comments

Comments
 (0)