Skip to content

Commit b6de244

Browse files
author
Kapil Borle
committed
Add RecurseCustomRulePath to settings file
1 parent e2cc1f5 commit b6de244

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

Engine/Settings.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ internal enum SettingsMode { None = 0, Auto, File, Hashtable, Preset };
2828
/// </summary>
2929
public class Settings
3030
{
31-
private bool includeDefaultRules;
31+
private bool recurseCustomRulePath = false;
32+
private bool includeDefaultRules = false;
3233
private string filePath;
3334
private List<string> includeRules;
3435
private List<string> excludeRules;
3536
private List<string> severities;
3637
private List<string> customRulePath;
3738
private Dictionary<string, Dictionary<string, object>> ruleArguments;
3839

40+
public bool RecurseCustomRulePath => recurseCustomRulePath;
3941
public bool IncludeDefaultRules => includeDefaultRules;
4042
public string FilePath => filePath;
4143
public IEnumerable<string> IncludeRules => includeRules;
@@ -409,12 +411,19 @@ private void parseSettingsHashtable(Hashtable settingsHashtable)
409411
break;
410412

411413
case "includedefaultrules":
414+
case "recursecustomrulepath":
415+
// todo localize
412416
if (!(val is bool))
413417
{
414418
throw new InvalidDataException(string.Format(CultureInfo.CurrentCulture, "Not a boolean"));
415419
}
416420

417-
includeDefaultRules = (bool)val;
421+
var booleanVal = (bool)val;
422+
var thisType = this.GetType();
423+
var field = this.GetType().GetField(
424+
key,
425+
BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.NonPublic);
426+
field.SetValue(this, booleanVal);
418427
break;
419428

420429
case "rules":

Tests/Engine/Settings.tests.ps1

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -146,37 +146,37 @@ Describe "Settings Class" {
146146
}
147147
}
148148

149-
Context "When IncludeDefaultRules parameter is provided" {
150-
It "Should correctly set the value if a boolean is given - true" {
151-
$settingsHashtable = @{
152-
IncludeDefaultRules = $true
149+
@("IncludeDefaultRules", "RecurseCustomRulePath") | ForEach-Object {
150+
$paramName = $_
151+
Context "When $paramName parameter is provided" {
152+
It "Should correctly set the value if a boolean is given - true" {
153+
$settingsHashtable = @{}
154+
$settingsHashtable.Add($paramName, $true)
155+
156+
$settings = New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable
157+
$settings."$paramName" | Should Be $true
153158
}
154159

155-
$settings = New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable
156-
$settings.IncludeDefaultRules | Should Be $true
157-
}
160+
It "Should correctly set the value if a boolean is given - false" {
161+
$settingsHashtable = @{}
162+
$settingsHashtable.Add($paramName, $false)
158163

159-
It "Should correctly set the value if a boolean is given - false" {
160-
$settingsHashtable = @{
161-
IncludeDefaultRules = $false
164+
$settings = New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable
165+
$settings."$paramName" | Should Be $false
162166
}
163167

164-
$settings = New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable
165-
$settings.IncludeDefaultRules | Should Be $false
166-
}
168+
It "Should throw if a non-boolean value is given" {
169+
$settingsHashtable = @{}
170+
$settingsHashtable.Add($paramName, "some random string")
167171

168-
It "Should throw if a non-boolean value is given" {
169-
$settingsHashtable = @{
170-
IncludeDefaultRules = "some random string"
172+
{ New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable } | Should Throw
171173
}
172174

173-
{ New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable } | Should Throw
174-
}
175-
176-
It "Should detect the parameter in a settings file" {
177-
$settings = New-Object -TypeName $settingsTypeName `
178-
-ArgumentList ([System.IO.Path]::Combine($project1Root, "CustomRulePathSettings.psd1"))
179-
$settings.IncludeDefaultRules | Should Be $true
175+
It "Should detect the parameter in a settings file" {
176+
$settings = New-Object -TypeName $settingsTypeName `
177+
-ArgumentList ([System.IO.Path]::Combine($project1Root, "CustomRulePathSettings.psd1"))
178+
$settings."$paramName" | Should Be $true
179+
}
180180
}
181181
}
182182
}

0 commit comments

Comments
 (0)