Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #309 from acrmp/lcg/avoid-recommends-suggests-meta…
Browse files Browse the repository at this point in the history
…data

add warnings for use of recommends/suggests
  • Loading branch information
odcinek committed Mar 20, 2015
2 parents 279a052 + aa554ce commit be13544
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
15 changes: 15 additions & 0 deletions features/052_check_for_metadata_using_suggests_keyword.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: Check for metadata using suggests keyword

In order to ensure that recipe metadata is stable
As a developer
I want to identify metadata that is using unimplemented features whose definitions may change in the future

Scenario: Metadata with the suggests keyword
Given a cookbook with metadata that includes a suggests keyword
When I check the cookbook
Then the metadata using suggests warning 052 should be shown against the metadata file

Scenario: Metadata without the suggests keyword
Given a cookbook with metadata that does not include a suggests keyword
When I check the cookbook
Then the metadata using suggests warning 052 should be not shown against the metadata file
15 changes: 15 additions & 0 deletions features/053_check_for_metadata_using_recommends_keyword.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: Check for metadata using recommends keyword

In order to ensure that recipe metadata is stable
As a developer
I want to identify metadata that is using unimplemented features whose definitions may change in the future

Scenario: Metadata with the recommends keyword
Given a cookbook with metadata that includes a recommends keyword
When I check the cookbook
Then the metadata using recommends warning 053 should be shown against the metadata file

Scenario: Metadata without the recommends keyword
Given a cookbook with metadata that does not include a recommends keyword
When I check the cookbook
Then the metadata using recommends warning 053 should be not shown against the metadata file
22 changes: 22 additions & 0 deletions features/step_definitions/cookbook_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,20 @@ def in_tier?(*tier)
}
end

Given /^a cookbook with metadata that (includes|does not include) a recommends keyword$/ do |includes|
write_metadata %Q{
depends "bar"
#{"recommends 'foo'" if includes == 'includes'}
}
end

Given /^a cookbook with metadata that (includes|does not include) a suggests keyword$/ do |includes|
write_metadata %Q{
depends "bar"
#{"suggests 'foo'" if includes == 'includes'}
}
end

Given /^a directory that contains a role file ([^ ]+) in (json|ruby) that defines role name (.*)$/ do |file_name, format, role_name|
role(:role_name => %Q{"#{role_name}"}, :file_name => file_name, :format => format.to_sym)
end
Expand Down Expand Up @@ -2273,3 +2287,11 @@ def search(bag_name, query=nil, sort=nil, start=0, rows=1000, &block)
write_definition "apache_site", content if file_type == "definition"
write_library "lib", content if file_type == "library"
end

Then /^the metadata using suggests warning 052 should be (shown|not shown) against the metadata file$/ do |show_warning|
expect_warning('FC052', :file => "metadata.rb", :line => 2, :expect_warning => show_warning == 'shown')
end

Then /^the metadata using recommends warning 053 should be (shown|not shown) against the metadata file$/ do |show_warning|
expect_warning('FC053', :file => "metadata.rb", :line => 2, :expect_warning => show_warning == 'shown')
end
2 changes: 2 additions & 0 deletions features/support/command_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def assertions
'FC049' => 'Role name does not match containing file name',
'FC050' => 'Name includes invalid characters',
'FC051' => 'Template partials loop indefinitely',
'FC052' => 'Metadata uses the unimplemented "suggests" keyword',
'FC053' => 'Metadata uses the unimplemented "recommends" keyword',
'FCTEST001' => 'Test Rule'
}

Expand Down
14 changes: 14 additions & 0 deletions lib/foodcritic/rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -755,3 +755,17 @@ def invalid_name(ast)
end.map { |t| file_match(t) }
end
end

rule 'FC052', 'Metadata uses the unimplemented "suggests" keyword' do
tags %w(style metadata)
metadata do |ast, filename|
ast.xpath(%Q(//command[ident/@value='suggests']))
end
end

rule 'FC053', 'Metadata uses the unimplemented "recommends" keyword' do
tags %w(style metadata)
metadata do |ast, filename|
ast.xpath(%Q(//command[ident/@value='recommends']))
end
end

0 comments on commit be13544

Please sign in to comment.