Skip to content

Commit 46d2768

Browse files
author
Kapil Borle
committed
Add IncludeDefaultRules to settings file
1 parent 43fa8d4 commit 46d2768

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Engine/Settings.cs

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

39+
public bool IncludeDefaultRules => includeDefaultRules;
3840
public string FilePath => filePath;
3941
public IEnumerable<string> IncludeRules => includeRules;
4042
public IEnumerable<string> ExcludeRules => excludeRules;
@@ -406,6 +408,15 @@ private void parseSettingsHashtable(Hashtable settingsHashtable)
406408
customRulePath = GetData(val, key);
407409
break;
408410

411+
case "includedefaultrules":
412+
if (!(val is bool))
413+
{
414+
throw new InvalidDataException(string.Format(CultureInfo.CurrentCulture, "Not a boolean"));
415+
}
416+
417+
includeDefaultRules = (bool)val;
418+
break;
419+
409420
case "rules":
410421
try
411422
{

Tests/Engine/Settings.tests.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,32 @@ Describe "Settings Class" {
138138
0..($rulePaths.Count - 1) | ForEach-Object { $settings.CustomRulePath[$_] | Should be $rulePaths[$_] }
139139
}
140140
}
141+
142+
Context "When IncludeDefaultRules parameter is provided" {
143+
It "Should correctly set the value if a boolean is given - true" {
144+
$settingsHashtable = @{
145+
IncludeDefaultRules = $true
146+
}
147+
148+
$settings = New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable
149+
$settings.IncludeDefaultRules | Should Be $true
150+
}
151+
152+
It "Should correctly set the value if a boolean is given - false" {
153+
$settingsHashtable = @{
154+
IncludeDefaultRules = $false
155+
}
156+
157+
$settings = New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable
158+
$settings.IncludeDefaultRules | Should Be $false
159+
}
160+
161+
It "Should throw if a non-boolean value is given" {
162+
$settingsHashtable = @{
163+
IncludeDefaultRules = "some random string"
164+
}
165+
166+
{ New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable } | Should Throw
167+
}
168+
}
141169
}

0 commit comments

Comments
 (0)