File tree Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ engines:
14
14
15
15
## Configuration
16
16
17
- This engine accepts ` tags` and `cookbook_paths ` in its configuration. Both
18
- values are optional :
17
+ This engine accepts ` tags`, `cookbook_paths` and `include_rules ` in its
18
+ configuration. All values are optional :
19
19
20
20
` ` ` yml
21
21
engines:
@@ -28,6 +28,9 @@ engines:
28
28
cookbook_paths:
29
29
- libraries/mysql.rb
30
30
- libraries/docker.rb
31
+ include_rules:
32
+ - rules/my_custom_rule.rb
33
+ - rules/my_other_custom_rule.rb
31
34
` ` `
32
35
33
36
**NOTE**: `cookbook_paths`, when defined, are passed directly to Foodcritic and
Original file line number Diff line number Diff line change @@ -7,15 +7,16 @@ module Engine
7
7
def self . each_issue
8
8
rules = Rules . new
9
9
10
- get_warnings . each do |lint |
10
+ warnings . each do |lint |
11
11
yield Issue . new ( lint , rules )
12
12
end
13
13
end
14
14
15
- def self . get_warnings
15
+ def self . warnings
16
16
config = Config . new
17
17
options = {
18
18
cookbook_paths : config . cookbook_paths ,
19
+ include_rules : config . include_rules ,
19
20
progress : false ,
20
21
tags : config . tags ,
21
22
}
@@ -30,7 +31,7 @@ class Config
30
31
DEFAULT_TAGS = [ "~FC011" , "~FC033" ]
31
32
32
33
def initialize ( path = "/config.json" )
33
- if File . exists ?( path )
34
+ if File . exist ?( path )
34
35
@config = JSON . parse ( File . read ( path ) )
35
36
else
36
37
@config = { }
@@ -41,6 +42,10 @@ def cookbook_paths
41
42
engine_config . fetch ( "cookbook_paths" ) { expand_include_paths }
42
43
end
43
44
45
+ def include_rules
46
+ engine_config . fetch ( "include_rules" , [ ] )
47
+ end
48
+
44
49
def tags
45
50
engine_config . fetch ( "tags" , DEFAULT_TAGS )
46
51
end
@@ -69,7 +74,7 @@ def expand_include_paths
69
74
70
75
class Rules
71
76
def initialize ( path = "/rules.yml" )
72
- if File . exists ?( path )
77
+ if File . exist ?( path )
73
78
@config = YAML . load_file ( path )
74
79
else
75
80
@config = { }
Original file line number Diff line number Diff line change @@ -57,6 +57,23 @@ module CC
57
57
end
58
58
end
59
59
60
+ describe "#include_rules" do
61
+ it "provides a default" do
62
+ config = Engine ::Config . new
63
+ expect ( config . include_rules ) . to ( eq ( [ ] ) )
64
+ end
65
+
66
+ it "allows overrides via config" do
67
+ Tempfile . open ( "config.json" ) do |tmp |
68
+ tmp . write ( %{ {"config":{"include_rules":["some_rule.rb","some_other_rule.rb"]}} } )
69
+ tmp . rewind
70
+
71
+ config = Engine ::Config . new ( tmp . path )
72
+ expect ( config . include_rules ) . to eq %w[ some_rule.rb some_other_rule.rb ]
73
+ end
74
+ end
75
+ end
76
+
60
77
describe "#tags" do
61
78
it "has a sane default" do
62
79
config = Engine ::Config . new
You can’t perform that action at this time.
0 commit comments