Skip to content

Commit 2aeef95

Browse files
committed
Refactor settings handling in ScriptAnalyzer
- Added a new `HashtableSettingsConverter` to convert inline PowerShell hashtables into a strongly typed `SettingsData`. - Introduced `ISettingsParser` interface for different settings file formats. - Implemented `Psd1SettingsParser` for parsing PowerShell data files (.psd1) into `SettingsData`. - Created a new `Settings` class to centralize the logic for obtaining analyzer settings, supporting auto-discovery, presets, and inline hashtables. - Removed the old `Settings` class and its associated logic - Updated `Helper.cs` and `ScriptAnalyzer.cs` to accommodate changes in settings handling. - Added `SettingsData` class to represent fully parsed and normalized settings.
1 parent ca1e015 commit 2aeef95

File tree

10 files changed

+761
-574
lines changed

10 files changed

+761
-574
lines changed

Engine/Commands/InvokeFormatterCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands
1717
public class InvokeFormatterCommand : PSCmdlet, IOutputWriter
1818
{
1919
private const string defaultSettingsPreset = "CodeFormatting";
20-
private Settings inputSettings;
20+
private SettingsData inputSettings;
2121
private Range range;
2222

2323
/// <summary>

Engine/Formatter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Formatter
2323
/// <returns></returns>
2424
public static string Format<TCmdlet>(
2525
string scriptDefinition,
26-
Settings settings,
26+
SettingsData settings,
2727
Range range,
2828
TCmdlet cmdlet) where TCmdlet : PSCmdlet, IOutputWriter
2929
{
@@ -81,9 +81,9 @@ private static void ValidateNotNull<T>(T obj, string name)
8181
}
8282
}
8383

84-
private static Settings GetCurrentSettings(Settings settings, string rule)
84+
private static SettingsData GetCurrentSettings(SettingsData settings, string rule)
8585
{
86-
return new Settings(new Hashtable()
86+
return HashtableSettingsConverter.Convert(new Hashtable()
8787
{
8888
{"IncludeRules", new string[] {rule}},
8989
{"Rules", new Hashtable() { { rule, new Hashtable(settings.RuleArguments[rule]) } } }

Engine/Helper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,11 @@ public static string[] ProcessCustomRulePaths(string[] rulePaths, SessionState s
15011501
return null;
15021502
}
15031503

1504+
if (rulePaths.Length == 0)
1505+
{
1506+
return null;
1507+
}
1508+
15041509
Collection<PathInfo> pathInfo = new Collection<PathInfo>();
15051510
foreach (string rulePath in rulePaths)
15061511
{

Engine/ScriptAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public void CleanUp()
207207
/// Update includerules, excluderules, severity and rule arguments.
208208
/// </summary>
209209
/// <param name="settings">An object of type Settings</param>
210-
public void UpdateSettings(Settings settings)
210+
public void UpdateSettings(SettingsData settings)
211211
{
212212
if (settings == null)
213213
{

0 commit comments

Comments
 (0)