diff --git a/features/007_check_for_undeclared_recipe_dependencies.feature b/features/007_check_for_undeclared_recipe_dependencies.feature index 96a1a9b1..6783e11c 100644 --- a/features/007_check_for_undeclared_recipe_dependencies.feature +++ b/features/007_check_for_undeclared_recipe_dependencies.feature @@ -52,3 +52,8 @@ Feature: Check for undeclared recipe dependencies Given a cookbook that does not have defined metadata When I check the cookbook Then the undeclared dependency warning 007 should not be displayed + + Scenario: Cookbook uses the include_recipe shorthand syntax + Given a cookbook that uses the include_recipe shorthand syntax + When I check the cookbook + Then the undeclared dependency warning 007 should not be displayed diff --git a/features/step_definitions/cookbook_steps.rb b/features/step_definitions/cookbook_steps.rb index f641069b..9aeb9b7b 100644 --- a/features/step_definitions/cookbook_steps.rb +++ b/features/step_definitions/cookbook_steps.rb @@ -509,6 +509,12 @@ } end +Given "a cookbook that uses the include_recipe shorthand syntax" do + write_recipe %q{ + include_recipe "::some_recipe" + } +end + Given /^a cookbook recipe that includes several declared recipe dependencies - (brace|block)$/ do |brace_or_block| cookbook_declares_dependencies(brace_or_block.to_sym) end diff --git a/lib/foodcritic/rules/fc007.rb b/lib/foodcritic/rules/fc007.rb index 0ed10df9..4e31f51f 100644 --- a/lib/foodcritic/rules/fc007.rb +++ b/lib/foodcritic/rules/fc007.rb @@ -6,8 +6,8 @@ next unless File.exist? metadata_path actual_included = included_recipes(ast, with_partial_names: false) undeclared = actual_included.keys.map do |recipe| - recipe.split("::").first - end - [cookbook_name(filename)] - + recipe.split("::").first unless recipe =~ /^::/ # skip shorthand included recipes. They're local + end.compact - [cookbook_name(filename)] - declared_dependencies(read_ast(metadata_path)) actual_included.map do |recipe, include_stmts| if undeclared.include?(recipe) ||