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:
1414
1515## Configuration
1616
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 :
1919
2020` ` ` yml
2121engines:
@@ -28,6 +28,9 @@ engines:
2828 cookbook_paths:
2929 - libraries/mysql.rb
3030 - libraries/docker.rb
31+ include_rules:
32+ - rules/my_custom_rule.rb
33+ - rules/my_other_custom_rule.rb
3134` ` `
3235
3336**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
77 def self . each_issue
88 rules = Rules . new
99
10- get_warnings . each do |lint |
10+ warnings . each do |lint |
1111 yield Issue . new ( lint , rules )
1212 end
1313 end
1414
15- def self . get_warnings
15+ def self . warnings
1616 config = Config . new
1717 options = {
1818 cookbook_paths : config . cookbook_paths ,
19+ include_rules : config . include_rules ,
1920 progress : false ,
2021 tags : config . tags ,
2122 }
@@ -30,7 +31,7 @@ class Config
3031 DEFAULT_TAGS = [ "~FC011" , "~FC033" ]
3132
3233 def initialize ( path = "/config.json" )
33- if File . exists ?( path )
34+ if File . exist ?( path )
3435 @config = JSON . parse ( File . read ( path ) )
3536 else
3637 @config = { }
@@ -41,6 +42,10 @@ def cookbook_paths
4142 engine_config . fetch ( "cookbook_paths" ) { expand_include_paths }
4243 end
4344
45+ def include_rules
46+ engine_config . fetch ( "include_rules" , [ ] )
47+ end
48+
4449 def tags
4550 engine_config . fetch ( "tags" , DEFAULT_TAGS )
4651 end
@@ -69,7 +74,7 @@ def expand_include_paths
6974
7075 class Rules
7176 def initialize ( path = "/rules.yml" )
72- if File . exists ?( path )
77+ if File . exist ?( path )
7378 @config = YAML . load_file ( path )
7479 else
7580 @config = { }
Original file line number Diff line number Diff line change @@ -57,6 +57,23 @@ module CC
5757 end
5858 end
5959
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+
6077 describe "#tags" do
6178 it "has a sane default" do
6279 config = Engine ::Config . new
You can’t perform that action at this time.
0 commit comments