foodcritic 11.1.0 → 11.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -1
  3. data/README.md +18 -0
  4. data/chef_dsl_metadata/{chef_12.8.1.json → chef_13.1.31.json} +4377 -1784
  5. data/features/009_check_for_unrecognised_resource_attributes.feature +0 -9
  6. data/features/038_check_for_invalid_action.feature +0 -9
  7. data/features/step_definitions/cookbook_steps.rb +6 -124
  8. data/lib/foodcritic/command_line.rb +1 -1
  9. data/lib/foodcritic/linter.rb +1 -1
  10. data/lib/foodcritic/rules/fc091.rb +10 -0
  11. data/lib/foodcritic/rules/fc092.rb +10 -0
  12. data/lib/foodcritic/version.rb +1 -1
  13. data/spec/functional/fc008_spec.rb +6 -6
  14. data/spec/functional/fc009_spec.rb +27 -0
  15. data/spec/functional/fc010_spec.rb +32 -0
  16. data/spec/functional/fc011_spec.rb +3 -3
  17. data/spec/functional/fc012_spec.rb +3 -3
  18. data/spec/functional/fc013_spec.rb +4 -4
  19. data/spec/functional/fc015_spec.rb +19 -0
  20. data/spec/functional/fc016_spec.rb +5 -5
  21. data/spec/functional/fc028_spec.rb +18 -18
  22. data/spec/functional/fc029_spec.rb +6 -6
  23. data/spec/functional/fc031_spec.rb +2 -2
  24. data/spec/functional/fc038_spec.rb +23 -0
  25. data/spec/functional/fc042_spec.rb +2 -2
  26. data/spec/functional/fc043_spec.rb +28 -0
  27. data/spec/functional/fc045_spec.rb +3 -3
  28. data/spec/functional/fc052_spec.rb +2 -2
  29. data/spec/functional/fc053_spec.rb +2 -2
  30. data/spec/functional/fc055_spec.rb +3 -3
  31. data/spec/functional/fc056_spec.rb +3 -3
  32. data/spec/functional/fc057_spec.rb +62 -0
  33. data/spec/functional/fc058_spec.rb +102 -0
  34. data/spec/functional/fc059_spec.rb +27 -0
  35. data/spec/functional/fc060_spec.rb +45 -0
  36. data/spec/functional/fc061_spec.rb +9 -9
  37. data/spec/functional/fc062_spec.rb +2 -2
  38. data/spec/functional/fc063_spec.rb +3 -3
  39. data/spec/functional/fc064_spec.rb +2 -2
  40. data/spec/functional/fc065_spec.rb +2 -2
  41. data/spec/functional/fc066_spec.rb +6 -6
  42. data/spec/functional/fc067_spec.rb +2 -2
  43. data/spec/functional/fc068_spec.rb +2 -2
  44. data/spec/functional/fc069_spec.rb +5 -5
  45. data/spec/functional/fc070_spec.rb +9 -9
  46. data/spec/functional/fc071_spec.rb +6 -6
  47. data/spec/functional/fc072_spec.rb +2 -2
  48. data/spec/functional/fc073_spec.rb +9 -9
  49. data/spec/functional/fc074_spec.rb +3 -3
  50. data/spec/functional/fc075_spec.rb +5 -5
  51. data/spec/functional/fc091_spec.rb +38 -0
  52. data/spec/functional/fc092_spec.rb +31 -0
  53. data/spec/regression/expected/aix.txt +1 -0
  54. data/spec/regression/expected/build-essential.txt +1 -0
  55. data/spec/regression/expected/drbd.txt +1 -0
  56. data/spec/regression/expected/perl.txt +1 -0
  57. data/spec/regression/expected/sudo.txt +1 -0
  58. data/spec/regression/expected/users.txt +1 -0
  59. data/spec/spec_helper.rb +8 -0
  60. data/spec/unit/linter_spec.rb +1 -1
  61. metadata +18 -14
  62. data/chef_dsl_metadata/chef_12.6.0.json +0 -15760
  63. data/chef_dsl_metadata/chef_12.7.2.json +0 -16673
  64. data/features/010_check_search_syntax.feature +0 -20
  65. data/features/015_check_for_definitions.feature +0 -20
  66. data/features/043_check_for_old_notification_style.feature +0 -28
  67. data/features/057_check_for_library_provider_without_use_inline_resources.feature +0 -20
  68. data/features/058_check_for_library_provider_bad_action_methods.feature +0 -25
  69. data/features/059_check_for_lwrp_provider_without_use_inline_resources.feature +0 -15
  70. data/features/060_check_for_lwrp_provider_bad_action_methods.feature +0 -25
@@ -53,12 +53,3 @@ Feature: Check for unrecognised resource attributes
53
53
  Given a recipe that declares a resource with an attribute value set to the result of a method call
54
54
  When I check the cookbook
55
55
  Then the unrecognised attribute warning 009 should not be displayed
56
-
57
- Scenario Outline: Create raid array with mdadm specifying layout
58
- Given a recipe that creates a raid array with mdadm specifying layout
59
- When I check the cookbook specifying <version> as the Chef version
60
- Then the unrecognised attribute warning 009 should be <shown>
61
- Examples:
62
- | version | shown |
63
- | 12.6.0 | true |
64
- | 12.11.18 | false |
@@ -37,12 +37,3 @@ Feature: Check for invalid resource actions
37
37
  | service | enable, start | should not |
38
38
  | service | enble, start | should |
39
39
  | foo | energize, revitalize | should not |
40
-
41
- Scenario Outline: Try to mask a systemd service
42
- Given a recipe that tries to mask a systemd service
43
- When I check the cookbook specifying <version> as the Chef version
44
- Then the invalid resource action warning 038 should be <shown>
45
- Examples:
46
- | version | shown |
47
- | 12.8.1 | false |
48
- | 12.7.2 | true |
@@ -255,7 +255,7 @@ Given /^a cookbook recipe that declares a resource with a (.*)$/ do |conditional
255
255
  }
256
256
  end
257
257
 
258
- Given /^a cookbook recipe (?:that declares a resource with no conditions at all|with no notifications)$/ do
258
+ Given "a cookbook recipe that declares a resource with no conditions at all" do
259
259
  write_recipe %q{
260
260
  service "apache" do
261
261
  action :enable
@@ -650,14 +650,6 @@ Given /^a cookbook recipe with a resource that (notifies|subscribes) a ([^ ]+) t
650
650
  }
651
651
  end
652
652
 
653
- Given "a cookbook recipe with a resource that uses the old notification syntax" do
654
- write_recipe %q{
655
- template "/etc/www/configures-apache.conf" do
656
- notifies :restart, resources(:service => "apache")
657
- end
658
- }
659
- end
660
-
661
653
  Given /^a cookbook recipe with a '([^']+)' condition for flavours (.*)$/ do |type, flavours|
662
654
  platforms = %Q{"#{flavours.split(',').join('","')}"}
663
655
  if type == "case"
@@ -765,17 +757,6 @@ Given /^a cookbook that contains a (short|long) ruby block$/ do |length|
765
757
  recipe_with_ruby_block(length.to_sym)
766
758
  end
767
759
 
768
- Given "a cookbook that contains a definition" do
769
- write_definition("apache_site", %q{
770
- define :apache_site, :enable => true do
771
- log "I am a definition"
772
- end
773
- })
774
- write_recipe %q{
775
- apache_site "default"
776
- }
777
- end
778
-
779
760
  Given /^a cookbook that contains a LWRP (?:with a single notification|that uses the current notification syntax)$/ do
780
761
  cookbook_with_lwrp({ :notifies => :does_notify })
781
762
  end
@@ -880,13 +861,6 @@ Given /^a cookbook that declares ([a-z]+) attributes via symbols$/ do |attribute
880
861
  attributes_with_symbols(attribute_type)
881
862
  end
882
863
 
883
- Given /^a cookbook that does not contain a definition and has (no|a) definitions directory$/ do |has_dir|
884
- create_directory "cookbooks/example/definitions/" unless has_dir == "no"
885
- write_recipe %q{
886
- log "A defining characteristic of this cookbook is that it has no definitions"
887
- }
888
- end
889
-
890
864
  Given /^a cookbook that has ([^ ]+) problems$/ do |problems|
891
865
  cookbook_that_matches_rules(
892
866
  problems.split(",").map do |problem|
@@ -1397,21 +1371,12 @@ Given "unit tests under a top-level test directory" do
1397
1371
  minitest_spec_attributes
1398
1372
  end
1399
1373
 
1400
- Given "a recipe that creates a raid array with mdadm specifying layout" do
1374
+ Given "a recipe that includes dsc_resource with the module_version attribute" do
1401
1375
  write_recipe %q{
1402
- mdadm '/dev/md0' do
1403
- devices [ '/dev/sda', '/dev/sdb', '/dev/sdc', '/dev/sdd' ]
1404
- level 5
1405
- layout 'left-asymmetric'
1406
- action [ :create, :assemble ]
1407
- end
1408
- }
1409
- end
1410
-
1411
- Given "a recipe that tries to mask a systemd service" do
1412
- write_recipe %q{
1413
- service 'foo' do
1414
- action :mask
1376
+ dsc_resource 'foo' do
1377
+ resource :something
1378
+ module_name 'foo'
1379
+ module_version '1.0.0.0'
1415
1380
  end
1416
1381
  }
1417
1382
  end
@@ -1869,10 +1834,6 @@ Then /^the unrecognised attribute warning 009 should be (true|false)$/ do |shown
1869
1834
  shown == "true" ? expect_warning("FC009") : expect_no_warning("FC009")
1870
1835
  end
1871
1836
 
1872
- Then /^the invalid resource action warning 038 should be (true|false)$/ do |shown|
1873
- shown == "true" ? expect_warning("FC038") : expect_no_warning("FC038")
1874
- end
1875
-
1876
1837
  Then "the unrecognised attribute warning 009 should be displayed against the correct resource" do
1877
1838
  expect_warning("FC009", :line => 7)
1878
1839
  end
@@ -1912,82 +1873,3 @@ Given(/^a cookbook with an? (.*) file with an interpolated name$/) do |file_type
1912
1873
  write_definition "apache_site", content if file_type == "definition"
1913
1874
  write_library "lib", content if file_type == "library"
1914
1875
  end
1915
-
1916
- Given /^a cookbook that contains a LWRP provider (with|without) use_inline_resources( and uses def action_create)?$/ do |with_use_inline_resources, uses_def|
1917
- write_resource("site", %q{
1918
- actions :create
1919
- attribute :name, :kind_of => String, :name_attribute => true
1920
- })
1921
- provider_file = ""
1922
- if with_use_inline_resources == "with"
1923
- provider_file += %q{
1924
- use_inline_resources
1925
- }
1926
- end
1927
- if uses_def
1928
- provider_file += %q{
1929
- def action_create
1930
- }
1931
- else
1932
- provider_file += %q{
1933
- action :create do
1934
- }
1935
- end
1936
- provider_file += %q{
1937
- file "/tmp/foo.txt"
1938
- end
1939
- }
1940
- write_provider("site", provider_file)
1941
- end
1942
-
1943
- Given /^a cookbook that contains a library provider (with|without) use_inline_resources( and uses def action_create)?$/ do |with_use_inline_resources, uses_def|
1944
- library_file = %q{
1945
- class MyResources
1946
- class Site < Chef::Resource::LWRPBase
1947
- provides :site
1948
- resource_name :site
1949
- actions :create
1950
- attribute :name, :kind_of => String, :name_attribute => true
1951
- end
1952
- end
1953
-
1954
- class MyProviders
1955
- class Site < Chef::Provider::LWRPBase
1956
- provides :site
1957
- }
1958
- if with_use_inline_resources == "with"
1959
- library_file += %q{
1960
- use_inline_resources
1961
- }
1962
- end
1963
- if uses_def
1964
- library_file += %q{
1965
- def action_create
1966
- }
1967
- else
1968
- library_file += %q{
1969
- action :create do
1970
- }
1971
- end
1972
- library_file += %q{
1973
- file "/tmp/foo.txt"
1974
- end
1975
- end
1976
- end
1977
- }
1978
- write_library("lib", library_file)
1979
- end
1980
-
1981
- Given /^a cookbook that contains a library resource$/ do
1982
- library_file = %q{
1983
- class MyResources
1984
- class Site < Chef::Resource::LWRPBase
1985
- provides :site
1986
- resource_name :site
1987
- actions :create
1988
- attribute :name, :kind_of => String, :name_attribute => true
1989
- end
1990
- end
1991
- }
1992
- write_library("lib", library_file)
1993
- end
@@ -16,7 +16,7 @@ module FoodCritic
16
16
  @args = args
17
17
  @original_args = args.dup
18
18
  @options = {
19
- fail_tags: ["any"],
19
+ fail_tags: ["~opensource"],
20
20
  tags: [],
21
21
  include_rules: [],
22
22
  cookbook_paths: [],
@@ -9,7 +9,7 @@ module FoodCritic
9
9
 
10
10
  # The default version that will be used to determine relevant rules. This
11
11
  # can be over-ridden at the command line with the `--chef-version` option.
12
- DEFAULT_CHEF_VERSION = "12.20.3"
12
+ DEFAULT_CHEF_VERSION = "13.1.31"
13
13
  attr_reader :chef_version
14
14
 
15
15
  # Perform a lint check. This method is intended for use by the command-line
@@ -0,0 +1,10 @@
1
+ rule "FC091", "Use property not attribute in custom resources" do
2
+ tags %w{correctness}
3
+
4
+ resource do |ast|
5
+ # Make sure we're in a custom resource not an LWRP
6
+ if ast.xpath("//command/ident/@value='action'")
7
+ ast.xpath("//command[ident/@value='attribute']")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ rule "FC092", "Custom resources should not define actions" do
2
+ tags %w{correctness}
3
+
4
+ resource do |ast|
5
+ # Make sure we're in a custom resource not an LWRP
6
+ if ast.xpath("//command/ident/@value='action'")
7
+ ast.xpath("//command[ident/@value='actions']")
8
+ end
9
+ end
10
+ end
@@ -1,4 +1,4 @@
1
1
  module FoodCritic
2
2
  # The current version of foodcritic
3
- VERSION = "11.1.0"
3
+ VERSION = "11.2.0"
4
4
  end
@@ -3,31 +3,31 @@ require "spec_helper"
3
3
  describe "FC008" do
4
4
  context "with a cookbook with a metadata file containing boilerplate maintainer from knife CLI" do
5
5
  metadata_file "maintainer 'YOUR_COMPANY_NAME'"
6
- it { is_expected.to violate_rule("FC008") }
6
+ it { is_expected.to violate_rule }
7
7
  end
8
8
 
9
9
  context "with a cookbook with a metadata file containing boilerplate maintainer from chef CLI" do
10
10
  metadata_file "maintainer 'The Authors'"
11
- it { is_expected.to violate_rule("FC008") }
11
+ it { is_expected.to violate_rule }
12
12
  end
13
13
 
14
14
  context "with a cookbook with a metadata file containing boilerplate maintainer_email from knife CLI" do
15
15
  metadata_file "maintainer_email 'YOUR_EMAIL'"
16
- it { is_expected.to violate_rule("FC008") }
16
+ it { is_expected.to violate_rule }
17
17
  end
18
18
 
19
19
  context "with a cookbook with a metadata file containing boilerplate maintainer_email from chef CLI" do
20
20
  metadata_file "maintainer_email 'you@example.com'"
21
- it { is_expected.to violate_rule("FC008") }
21
+ it { is_expected.to violate_rule }
22
22
  end
23
23
 
24
24
  context "with a cookbook with a metadata file containing non-boilerplate maintainer and maintainer_email" do
25
25
  metadata_file "maintainer 'John Smith'\nmaintainer_email 'john@smith.com'"
26
- it { is_expected.not_to violate_rule("FC008") }
26
+ it { is_expected.not_to violate_rule }
27
27
  end
28
28
 
29
29
  context "with a cookbook with a metadata file not containing maintainer or maintainer_email" do
30
30
  metadata_file
31
- it { is_expected.not_to violate_rule("FC008") }
31
+ it { is_expected.not_to violate_rule }
32
32
  end
33
33
  end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC009" do
4
+ context "on chef 13.0.133 with a cookbook that new dsc_resource attributes" do
5
+ foodcritic_command("--chef-version", "13.0.133", "--no-progress", ".")
6
+ recipe_file <<-EOH
7
+ dsc_resource 'foo' do
8
+ resource :something
9
+ module_name 'foo'
10
+ module_version '1.0.0.0'
11
+ end
12
+ EOH
13
+ it { is_expected.not_to violate_rule }
14
+ end
15
+
16
+ context "on chef 12.18.31 with a cookbook that new dsc_resource attributes" do
17
+ foodcritic_command("--chef-version", "12.18.31", "--no-progress", ".")
18
+ recipe_file <<-EOH
19
+ dsc_resource 'foo' do
20
+ resource :something
21
+ module_name 'foo'
22
+ module_version '1.0.0.0'
23
+ end
24
+ EOH
25
+ it { is_expected.to violate_rule }
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC010" do
4
+ context "with a cookbook with a recipe that attempts to perform a search with invalid syntax" do
5
+ recipe_file <<-EOH
6
+ search(:node, 'run_list:recipe[foo::bar]') do |matching_node|
7
+ puts matching_node.to_s
8
+ end
9
+ EOH
10
+ it { is_expected.to violate_rule }
11
+ end
12
+
13
+ context "with a cookbook with a recipe that attempts to perform a search with valid syntax" do
14
+ recipe_file <<-EOH
15
+ search(:node, 'run_list:recipe\\[foo\\:\\:bar\\]') do |matching_node|
16
+ puts matching_node.to_s
17
+ end
18
+ EOH
19
+
20
+ it { is_expected.not_to violate_rule }
21
+ end
22
+
23
+ context "with a cookbook with a recipe that attempts to perform a search with a subexpression" do
24
+ recipe_file <<-EOH
25
+ search(:node, "roles:\#{node['foo']['role']}") do |matching_node|
26
+ puts matching_node.to_s
27
+ end
28
+ EOH
29
+
30
+ it { is_expected.not_to violate_rule }
31
+ end
32
+ end
@@ -4,17 +4,17 @@ describe "FC011" do
4
4
  context "with a cookbook with a README.md file" do
5
5
  metadata_file "name 'mycookbook'"
6
6
  file("README.md")
7
- it { is_expected.not_to violate_rule("FC011") }
7
+ it { is_expected.not_to violate_rule }
8
8
  end
9
9
 
10
10
  context "with a cookbook without a README.md file" do
11
11
  metadata_file "name 'mycookbook'"
12
- it { is_expected.to violate_rule("FC011") }
12
+ it { is_expected.to violate_rule }
13
13
  end
14
14
 
15
15
  context "with a cookbook with a README.rdoc file" do
16
16
  metadata_file "name 'mycookbook'"
17
17
  file("README.rdoc")
18
- it { is_expected.to violate_rule("FC011") }
18
+ it { is_expected.to violate_rule }
19
19
  end
20
20
  end
@@ -4,17 +4,17 @@ describe "FC012" do
4
4
  context "with a cookbook with a README.md file" do
5
5
  metadata_file "name 'mycookbook'"
6
6
  file("README.md")
7
- it { is_expected.not_to violate_rule("FC012") }
7
+ it { is_expected.not_to violate_rule }
8
8
  end
9
9
 
10
10
  context "with a cookbook without a README file" do
11
11
  metadata_file "name 'mycookbook'"
12
- it { is_expected.not_to violate_rule("FC012") }
12
+ it { is_expected.not_to violate_rule }
13
13
  end
14
14
 
15
15
  context "with a cookbook with a README.rdoc file" do
16
16
  metadata_file "name 'mycookbook'"
17
17
  file("README.rdoc")
18
- it { is_expected.to violate_rule("FC012") }
18
+ it { is_expected.to violate_rule }
19
19
  end
20
20
  end
@@ -7,7 +7,7 @@ describe "FC013" do
7
7
  source "http://www.example.org/large-file.tar.gz"
8
8
  end
9
9
  EOH
10
- it { is_expected.to violate_rule("FC013") }
10
+ it { is_expected.to violate_rule }
11
11
  end
12
12
 
13
13
  context "with a cookbook that downloads a file to /tmp with an expression" do
@@ -16,7 +16,7 @@ describe "FC013" do
16
16
  source "http://www.example.org/large-file.tar.gz"
17
17
  end
18
18
  EOH
19
- it { is_expected.to violate_rule("FC013") }
19
+ it { is_expected.to violate_rule }
20
20
  end
21
21
 
22
22
  context "with a cookbook that downloads a file to a users home directory" do
@@ -25,7 +25,7 @@ describe "FC013" do
25
25
  source "http://www.example.org/large-file.tar.gz"
26
26
  end
27
27
  EOH
28
- it { is_expected.not_to violate_rule("FC013") }
28
+ it { is_expected.not_to violate_rule }
29
29
  end
30
30
 
31
31
  context "with a cookbook that downloads a file to the Chef file cache" do
@@ -34,6 +34,6 @@ describe "FC013" do
34
34
  source "http://www.example.org/large-file.tar.gz"
35
35
  end
36
36
  EOH
37
- it { is_expected.not_to violate_rule("FC013") }
37
+ it { is_expected.not_to violate_rule }
38
38
  end
39
39
  end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC015" do
4
+ context "with a cookbook that contains a definition" do
5
+ definition_file <<-EOH
6
+ define :apache_site, :enable => true do
7
+ log "I am a definition"
8
+ end
9
+ EOH
10
+ it { is_expected.to violate_rule }
11
+ end
12
+
13
+ context "with a cookbook that does not contain a definition" do
14
+ recipe_file <<-EOH
15
+ cookbook_file "/etc/foo"
16
+ EOH
17
+ it { is_expected.not_to violate_rule }
18
+ end
19
+ end