cookstyle 6.16.4 → 6.16.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cookstyle/version.rb +1 -1
  3. data/lib/rubocop/cop/chef/correctness/invalid_default_action.rb +1 -0
  4. data/lib/rubocop/cop/chef/correctness/invalid_notification_timing.rb +1 -0
  5. data/lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb +1 -0
  6. data/lib/rubocop/cop/chef/correctness/invalid_platform_helper.rb +1 -0
  7. data/lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb +1 -0
  8. data/lib/rubocop/cop/chef/correctness/invalid_value_for_platform_family_helper.rb +1 -0
  9. data/lib/rubocop/cop/chef/correctness/invalid_value_for_platform_helper.rb +1 -0
  10. data/lib/rubocop/cop/chef/correctness/malformed_value_for_platform.rb +2 -2
  11. data/lib/rubocop/cop/chef/correctness/service_resource.rb +1 -0
  12. data/lib/rubocop/cop/chef/correctness/supports_must_be_float.rb +1 -0
  13. data/lib/rubocop/cop/chef/correctness/tmp_path.rb +1 -0
  14. data/lib/rubocop/cop/chef/deprecation/ use_automatic_resource_name.rb +1 -2
  15. data/lib/rubocop/cop/chef/deprecation/cb_depends_on_self.rb +1 -0
  16. data/lib/rubocop/cop/chef/deprecation/chef_handler_recipe.rb +1 -0
  17. data/lib/rubocop/cop/chef/deprecation/chef_rest.rb +1 -0
  18. data/lib/rubocop/cop/chef/deprecation/chef_rewind.rb +1 -0
  19. data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +2 -1
  20. data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +1 -0
  21. data/lib/rubocop/cop/chef/deprecation/depends_poise.rb +1 -0
  22. data/lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb +1 -0
  23. data/lib/rubocop/cop/chef/deprecation/deprecated_shellout_methods.rb +10 -11
  24. data/lib/rubocop/cop/chef/deprecation/deprecated_windows_version_check.rb +2 -1
  25. data/lib/rubocop/cop/chef/deprecation/easy_install.rb +2 -1
  26. data/lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb +1 -0
  27. data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +1 -1
  28. data/lib/rubocop/cop/chef/deprecation/erl_call.rb +2 -1
  29. data/lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb +1 -0
  30. data/lib/rubocop/cop/chef/deprecation/legacy_yum_cookbook_recipes.rb +1 -0
  31. data/lib/rubocop/cop/chef/deprecation/name_property_and_default.rb +1 -0
  32. data/lib/rubocop/cop/chef/deprecation/partial_search_helper_usage.rb +2 -1
  33. data/lib/rubocop/cop/chef/deprecation/poise_archive.rb +1 -0
  34. data/lib/rubocop/cop/chef/deprecation/require_recipe.rb +1 -0
  35. data/lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb +2 -3
  36. data/lib/rubocop/cop/chef/deprecation/resource_uses_dsl_name_method.rb +2 -1
  37. data/lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb +1 -0
  38. data/lib/rubocop/cop/chef/deprecation/resource_uses_provider_base_method.rb +2 -1
  39. data/lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb +1 -0
  40. data/lib/rubocop/cop/chef/deprecation/run_command_helper.rb +1 -0
  41. data/lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb +1 -0
  42. data/lib/rubocop/cop/chef/deprecation/use_inline_resources.rb +10 -11
  43. data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +1 -0
  44. data/lib/rubocop/cop/chef/deprecation/yum_dnf_compat_recipe.rb +1 -0
  45. data/lib/rubocop/cop/chef/effortless/data_bags.rb +2 -1
  46. data/lib/rubocop/cop/chef/effortless/node_environment.rb +2 -2
  47. data/lib/rubocop/cop/chef/effortless/node_policygroup.rb +2 -2
  48. data/lib/rubocop/cop/chef/effortless/node_roles.rb +2 -2
  49. data/lib/rubocop/cop/chef/effortless/search_for_environments_or_roles.rb +2 -2
  50. data/lib/rubocop/cop/chef/effortless/search_used.rb +2 -1
  51. data/lib/rubocop/cop/chef/modernize/apt_default_recipe.rb +1 -0
  52. data/lib/rubocop/cop/chef/modernize/berksfile_source.rb +1 -0
  53. data/lib/rubocop/cop/chef/modernize/build_essential.rb +1 -0
  54. data/lib/rubocop/cop/chef/modernize/chef_14_resources.rb +1 -0
  55. data/lib/rubocop/cop/chef/modernize/chef_gem_nokogiri.rb +1 -0
  56. data/lib/rubocop/cop/chef/modernize/conditional_using_test.rb +1 -0
  57. data/lib/rubocop/cop/chef/modernize/cron_manage_resource.rb +1 -1
  58. data/lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb +1 -0
  59. data/lib/rubocop/cop/chef/modernize/dsl_include_in_resource.rb +1 -0
  60. data/lib/rubocop/cop/chef/modernize/execute_apt_update.rb +1 -0
  61. data/lib/rubocop/cop/chef/modernize/execute_sc_exe.rb +2 -1
  62. data/lib/rubocop/cop/chef/modernize/execute_sleep.rb +2 -1
  63. data/lib/rubocop/cop/chef/modernize/execute_sysctl.rb +2 -1
  64. data/lib/rubocop/cop/chef/modernize/execute_tzutil.rb +1 -0
  65. data/lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb +1 -0
  66. data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +1 -0
  67. data/lib/rubocop/cop/chef/modernize/macos_user_defaults.rb +1 -1
  68. data/lib/rubocop/cop/chef/modernize/minitest_handler_usage.rb +1 -0
  69. data/lib/rubocop/cop/chef/modernize/ohai_default_recipe.rb +1 -0
  70. data/lib/rubocop/cop/chef/modernize/openssl_rsa_key_resource.rb +1 -1
  71. data/lib/rubocop/cop/chef/modernize/openssl_x509_resource.rb +1 -1
  72. data/lib/rubocop/cop/chef/modernize/osx_config_profile_resource.rb +1 -1
  73. data/lib/rubocop/cop/chef/modernize/property_with_name_attribute.rb +1 -0
  74. data/lib/rubocop/cop/chef/modernize/resource_set_or_return.rb +1 -1
  75. data/lib/rubocop/cop/chef/modernize/resource_with_attributes.rb +1 -0
  76. data/lib/rubocop/cop/chef/modernize/sc_windows_resource.rb +2 -1
  77. data/lib/rubocop/cop/chef/modernize/seven_zip_archive.rb +2 -1
  78. data/lib/rubocop/cop/chef/modernize/{systctl_param_resource.rb → sysctl_param_resource.rb} +1 -1
  79. data/lib/rubocop/cop/chef/modernize/unnecessary_mixlib_shellout_require.rb +1 -0
  80. data/lib/rubocop/cop/chef/modernize/use_require_relative.rb +1 -0
  81. data/lib/rubocop/cop/chef/modernize/windows_default_recipe.rb +1 -0
  82. data/lib/rubocop/cop/chef/modernize/windows_registry_uac.rb +2 -2
  83. data/lib/rubocop/cop/chef/modernize/windows_zipfile.rb +2 -1
  84. data/lib/rubocop/cop/chef/modernize/zipfile_resource.rb +1 -0
  85. data/lib/rubocop/cop/chef/modernize/zypper_repo.rb +1 -1
  86. data/lib/rubocop/cop/chef/redundant/attribute_metadata.rb +1 -1
  87. data/lib/rubocop/cop/chef/redundant/conflicts_metadata.rb +1 -1
  88. data/lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb +4 -9
  89. data/lib/rubocop/cop/chef/redundant/grouping_metadata.rb +1 -2
  90. data/lib/rubocop/cop/chef/redundant/long_description_metadata.rb +1 -2
  91. data/lib/rubocop/cop/chef/redundant/property_with_default_and_required.rb +1 -0
  92. data/lib/rubocop/cop/chef/redundant/provides_metadata.rb +1 -2
  93. data/lib/rubocop/cop/chef/redundant/recipe_metadata.rb +1 -2
  94. data/lib/rubocop/cop/chef/redundant/replaces_metadata.rb +1 -2
  95. data/lib/rubocop/cop/chef/redundant/sensitive_property_in_resource.rb +1 -0
  96. data/lib/rubocop/cop/chef/redundant/string_property_with_nil_default.rb +1 -0
  97. data/lib/rubocop/cop/chef/redundant/suggests_metadata.rb +1 -2
  98. data/lib/rubocop/cop/chef/redundant/unnecessary_desired_state.rb +1 -0
  99. data/lib/rubocop/cop/chef/redundant/unnecessary_name_property.rb +1 -0
  100. data/lib/rubocop/cop/chef/sharing/default_maintainer_metadata.rb +1 -0
  101. data/lib/rubocop/cop/chef/sharing/include_property_descriptions.rb +1 -0
  102. data/lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb +1 -0
  103. data/lib/rubocop/cop/chef/sharing/invalid_license_string.rb +1 -0
  104. data/lib/rubocop/cop/chef/style/file_mode.rb +1 -0
  105. data/lib/rubocop/cop/chef/style/immediate_notification_timing.rb +1 -0
  106. data/lib/rubocop/cop/chef/style/include_recipe_with_parentheses.rb +1 -0
  107. data/lib/rubocop/cop/chef/style/true_false_resource_properties.rb +2 -0
  108. metadata +3 -3
@@ -30,6 +30,7 @@ module RuboCop
30
30
  extend AutoCorrector
31
31
 
32
32
  MSG = 'Do not include the deprecated xml::ruby recipe to install the nokogiri gem. Chef Infra Client 12 and later ships with nokogiri included.'
33
+ RESTRICT_ON_SEND = [:include_recipe].freeze
33
34
 
34
35
  def_node_matcher :xml_ruby_recipe?, <<-PATTERN
35
36
  (send nil? :include_recipe (str "xml::ruby"))
@@ -32,6 +32,7 @@ module RuboCop
32
32
  extend AutoCorrector
33
33
 
34
34
  MSG = 'Do not include the deprecated yum::dnf_yum_compat default recipe to install yum on dnf systems. Chef Infra Client now includes built in support for DNF packages.'
35
+ RESTRICT_ON_SEND = [:include_recipe].freeze
35
36
 
36
37
  def_node_matcher :yum_dnf_compat_recipe_usage?, <<-PATTERN
37
38
  (send nil? :include_recipe (str "yum::dnf_yum_compat"))
@@ -28,9 +28,10 @@ module RuboCop
28
28
  # data_bag(data_bag_name)
29
29
  class CookbookUsesDatabags < Base
30
30
  MSG = 'Cookbook uses data bags, which cannot be used in the Effortless Infra pattern'
31
+ RESTRICT_ON_SEND = [:data_bag, :data_bag_item].freeze
31
32
 
32
33
  def on_send(node)
33
- add_offense(node, message: MSG, severity: :refactor) if %i(data_bag data_bag_item).include?(node.method_name)
34
+ add_offense(node, message: MSG, severity: :refactor)
34
35
  end
35
36
  end
36
37
  end
@@ -29,10 +29,10 @@ module RuboCop
29
29
  #
30
30
  class CookbookUsesEnvironments < Base
31
31
  MSG = 'Cookbook uses environments, which cannot be used in Policyfiles or Effortless Infra'
32
+ RESTRICT_ON_SEND = [:environment, :chef_environment].freeze
32
33
 
33
34
  def on_send(node)
34
- if %i(environment chef_environment).include?(node.method_name) &&
35
- node.receiver &&
35
+ if node.receiver &&
36
36
  node.receiver.send_type? &&
37
37
  node.receiver.method_name == :node
38
38
  add_offense(node, message: MSG, severity: :refactor)
@@ -28,10 +28,10 @@ module RuboCop
28
28
  #
29
29
  class CookbookUsesPolicygroups < Base
30
30
  MSG = 'Cookbook uses Policy Groups, which cannot be used with Effortless Infra'
31
+ RESTRICT_ON_SEND = [:policy_group].freeze
31
32
 
32
33
  def on_send(node)
33
- if node.method_name == :policy_group &&
34
- node.receiver &&
34
+ if node.receiver &&
35
35
  node.receiver.send_type? &&
36
36
  node.receiver.method_name == :node
37
37
  add_offense(node, message: MSG, severity: :refactor)
@@ -29,10 +29,10 @@ module RuboCop
29
29
  #
30
30
  class CookbookUsesRoles < Base
31
31
  MSG = 'Cookbook uses roles, which cannot be used in Policyfiles or Effortless Infra'
32
+ RESTRICT_ON_SEND = [:role?, :roles].freeze
32
33
 
33
34
  def on_send(node)
34
- if %i(role? roles).include?(node.method_name) &&
35
- node.receiver &&
35
+ if node.receiver &&
36
36
  node.receiver.send_type? &&
37
37
  node.receiver.method_name == :node
38
38
  add_offense(node, message: MSG, severity: :refactor)
@@ -29,10 +29,10 @@ module RuboCop
29
29
  #
30
30
  class SearchForEnvironmentsOrRoles < Base
31
31
  MSG = 'Cookbook uses search with a node query that looks for a role or environment'
32
+ RESTRICT_ON_SEND = [:search].freeze
32
33
 
33
34
  def on_send(node)
34
- if node.method_name == :search &&
35
- node.arguments[1]&.value&.match?(/chef_environment|role/)
35
+ if node.arguments[1]&.value&.match?(/chef_environment|role/)
36
36
  add_offense(node, message: MSG, severity: :refactor)
37
37
  end
38
38
  end
@@ -28,9 +28,10 @@ module RuboCop
28
28
  #
29
29
  class CookbookUsesSearch < Base
30
30
  MSG = 'Cookbook uses search, which cannot be used in the Effortless Infra pattern'
31
+ RESTRICT_ON_SEND = [:search].freeze
31
32
 
32
33
  def on_send(node)
33
- add_offense(node, message: MSG, severity: :refactor) if node.method_name == :search
34
+ add_offense(node, message: MSG, severity: :refactor)
34
35
  end
35
36
  end
36
37
  end
@@ -36,6 +36,7 @@ module RuboCop
36
36
  minimum_target_chef_version '12.7'
37
37
 
38
38
  MSG = 'Do not include the Apt default recipe to update package cache. Instead use the apt_update resource, which is built into Chef Infra Client 12.7 and later.'
39
+ RESTRICT_ON_SEND = [:include_recipe].freeze
39
40
 
40
41
  def_node_matcher :apt_recipe_usage?, <<-PATTERN
41
42
  (send nil? :include_recipe (str {"apt" "apt::default"}))
@@ -38,6 +38,7 @@ module RuboCop
38
38
  extend AutoCorrector
39
39
 
40
40
  MSG = 'Do not use legacy Berksfile community sources. Use Chef Supermarket instead.'
41
+ RESTRICT_ON_SEND = [:source, :site].freeze
41
42
 
42
43
  def_node_matcher :berksfile_site?, <<-PATTERN
43
44
  (send nil? :site (:sym _))
@@ -35,6 +35,7 @@ module RuboCop
35
35
  extend AutoCorrector
36
36
 
37
37
  MSG = 'Use the build_essential resource instead of the legacy build-essential recipe. This resource ships in the build-essential cookbook v5.0+ and is built into Chef Infra Client 14+'
38
+ RESTRICT_ON_SEND = [:include_recipe].freeze
38
39
 
39
40
  def_node_matcher :build_essential_recipe_usage?, <<-PATTERN
40
41
  (send nil? :include_recipe (str {"build-essential" "build-essential::default"}))
@@ -40,6 +40,7 @@ module RuboCop
40
40
  minimum_target_chef_version '14.0'
41
41
 
42
42
  MSG = "Don't depend on cookbooks made obsolete by Chef Infra Client 14+. These community cookbooks contain resources that are now included in Chef Infra Client itself."
43
+ RESTRICT_ON_SEND = [:depends].freeze
43
44
 
44
45
  def_node_matcher :legacy_depends?, <<-PATTERN
45
46
  (send nil? :depends (str {"build-essential" "chef_handler" "chef_hostname" "dmg" "mac_os_x" "swap" "sysctl"}) ... )
@@ -33,6 +33,7 @@ module RuboCop
33
33
  include RuboCop::Chef::CookbookHelpers
34
34
 
35
35
  MSG = 'The nokogiri gem ships in Chef Infra Client 12+ and does not need to be installed before being used.'
36
+ RESTRICT_ON_SEND = [:chef_gem].freeze
36
37
 
37
38
  def_node_matcher :nokogiri_install?, <<-PATTERN
38
39
  (send nil? :chef_gem (str "nokogiri"))
@@ -33,6 +33,7 @@ module RuboCop
33
33
  extend AutoCorrector
34
34
 
35
35
  MSG = "Use ::File.exist?('/foo/bar') instead of the slower 'test -f /foo/bar' which requires shelling out"
36
+ RESTRICT_ON_SEND = [:not_if, :only_if].freeze
36
37
 
37
38
  def_node_matcher :resource_conditional?, <<~PATTERN
38
39
  (send nil? {:not_if :only_if} $str )
@@ -36,10 +36,10 @@ module RuboCop
36
36
  minimum_target_chef_version '14.4'
37
37
 
38
38
  MSG = 'The cron_manage resource was renamed to cron_access in the 6.1 release of the cron cookbook and later shipped in Chef Infra Client 14.4. The new resource name should be used.'
39
+ RESTRICT_ON_SEND = [:cron_manage].freeze
39
40
 
40
41
  def on_send(node)
41
42
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
42
- return unless node.method_name == :cron_manage
43
43
  corrector.replace(node.loc.expression, node.source.gsub(/^cron_manage/, 'cron_access'))
44
44
  end
45
45
  end
@@ -34,6 +34,7 @@ module RuboCop
34
34
  minimum_target_chef_version '13.3'
35
35
 
36
36
  MSG = "Don't depend on the zypper cookbook as the zypper_repository resource is built into Chef Infra Client 13.3+"
37
+ RESTRICT_ON_SEND = [:depends].freeze
37
38
 
38
39
  def_node_matcher :zypper_depends?, <<-PATTERN
39
40
  (send nil? :depends (str "zypper"))
@@ -30,6 +30,7 @@ module RuboCop
30
30
  include RangeHelp
31
31
 
32
32
  MSG = 'Chef Infra Client 12.4+ includes the Chef::DSL::Recipe in the resource and provider classed by default so there is no need to include this DSL in your resources or providers.'
33
+ RESTRICT_ON_SEND = [:include].freeze
33
34
 
34
35
  def_node_matcher :dsl_include?, <<-PATTERN
35
36
  (send nil? :include
@@ -46,6 +46,7 @@ module RuboCop
46
46
  extend AutoCorrector
47
47
 
48
48
  MSG = 'Use the apt_update resource instead of the execute resource to run an apt-get update package cache update'
49
+ RESTRICT_ON_SEND = [:execute, :notifies, :subscribes, :command].freeze
49
50
 
50
51
  def_node_matcher :execute_apt_update?, <<-PATTERN
51
52
  (send nil? :execute (str { "apt-get update" "apt-get update -y" "apt-get -y update" }))
@@ -39,12 +39,13 @@ module RuboCop
39
39
  minimum_target_chef_version '14.0'
40
40
 
41
41
  MSG = 'Chef Infra Client 14.0 and later includes :create, :delete, and :configure actions with the full idempotency of the windows_service resource. See the windows_service documentation at https://docs.chef.io/resource_windows_service.html for additional details on creating services with the windows_service resource'
42
+ RESTRICT_ON_SEND = [:execute].freeze
42
43
 
43
44
  # non block execute resources
44
45
  def on_send(node)
45
46
  # use a regex on source instead of .value in case there's string interpolation which adds a complex dstr type
46
47
  # with a nested string and a begin. Source allows us to avoid a lot of defensive programming here
47
- return unless node&.arguments.first&.source&.match?(/^("|')sc.exe/) && node.method_name == :execute
48
+ return unless node&.arguments.first&.source&.match?(/^("|')sc.exe/)
48
49
 
49
50
  add_offense(node, message: MSG, severity: :refactor)
50
51
  end
@@ -43,12 +43,13 @@ module RuboCop
43
43
  minimum_target_chef_version '15.5'
44
44
 
45
45
  MSG = 'Chef Infra Client 15.5 and later include a chef_sleep resource that should be used to sleep between executing resources if necessary instead of using the bash or execute resources to run the sleep command.'
46
+ RESTRICT_ON_SEND = [:execute].freeze
46
47
 
47
48
  # non block execute resources
48
49
  def on_send(node)
49
50
  # use a regex on source instead of .value in case there's string interpolation which adds a complex dstr type
50
51
  # with a nested string and a begin. Source allows us to avoid a lot of defensive programming here
51
- return unless node.method_name == :execute && node&.arguments.first&.source&.match?(/^("|')sleep/)
52
+ return unless node&.arguments.first&.source&.match?(/^("|')sleep/)
52
53
  add_offense(node, message: MSG, severity: :refactor)
53
54
  end
54
55
 
@@ -43,12 +43,13 @@ module RuboCop
43
43
  minimum_target_chef_version '14.0'
44
44
 
45
45
  MSG = 'Chef Infra Client 14.0 and later includes a sysctl resource that should be used to idempotently load sysctl values instead of templating files and using execute to load them.'
46
+ RESTRICT_ON_SEND = [:execute].freeze
46
47
 
47
48
  # non block execute resources
48
49
  def on_send(node)
49
50
  # use a regex on source instead of .value in case there's string interpolation which adds a complex dstr type
50
51
  # with a nested string and a begin. Source allows us to avoid a lot of defensive programming here
51
- return unless node.method_name == :execute && node&.arguments.first&.source&.match?(/^("|')sysctl -p/)
52
+ return unless node&.arguments.first&.source&.match?(/^("|')sysctl -p/)
52
53
  add_offense(node, message: MSG, severity: :refactor)
53
54
  end
54
55
 
@@ -44,6 +44,7 @@ module RuboCop
44
44
  minimum_target_chef_version '14.6'
45
45
 
46
46
  MSG = 'Use the timezone resource included in Chef Infra Client 14.6+ instead of shelling out to tzutil'
47
+ RESTRICT_ON_SEND = [:execute].freeze
47
48
 
48
49
  def_node_matcher :execute_resource?, <<-PATTERN
49
50
  (send nil? :execute $str)
@@ -35,6 +35,7 @@ module RuboCop
35
35
  include RangeHelp
36
36
 
37
37
  MSG = 'There is no need to include Chef::Mixin::ShellOut or Chef::Mixin::PowershellOut in resources or providers as this is already done by Chef Infra Client 12.4+.'
38
+ RESTRICT_ON_SEND = [:include, :require].freeze
38
39
 
39
40
  def_node_matcher :include_shellout?, <<-PATTERN
40
41
  (send nil? :include (const (const (const nil? :Chef) :Mixin) {:ShellOut :PowershellOut}))
@@ -41,6 +41,7 @@ module RuboCop
41
41
  minimum_target_chef_version '15.0'
42
42
 
43
43
  MSG = 'Use the archive_file resource built into Chef Infra Client 15+ instead of the libarchive file resource'
44
+ RESTRICT_ON_SEND = [:libarchive_file, :notifies, :subscribes].freeze
44
45
 
45
46
  def_node_matcher :notification_property?, <<-PATTERN
46
47
  (send nil? {:notifies :subscribes} (sym _) $(...) (sym _))
@@ -43,9 +43,9 @@ module RuboCop
43
43
  minimum_target_chef_version '14.0'
44
44
 
45
45
  MSG = 'The mac_os_x_userdefaults resource was renamed to macos_userdefaults when it was added to Chef Infra Client 14.0. The new resource name should be used.'
46
+ RESTRICT_ON_SEND = [:mac_os_x_userdefaults].freeze
46
47
 
47
48
  def on_send(node)
48
- return unless node.method_name == :mac_os_x_userdefaults
49
49
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
50
50
  corrector.replace(node.loc.expression, node.source.gsub(/^mac_os_x_userdefaults/, 'macos_userdefaults'))
51
51
  end
@@ -31,6 +31,7 @@ module RuboCop
31
31
  include RangeHelp
32
32
 
33
33
  MSG = 'Use Chef InSpec for testing instead of the Minitest Handler cookbook pattern.'
34
+ RESTRICT_ON_SEND = [:depends].freeze
34
35
 
35
36
  def_node_matcher :minitest_depends?, <<-PATTERN
36
37
  (send nil? :depends (str "minitest-handler"))
@@ -31,6 +31,7 @@ module RuboCop
31
31
  #
32
32
  class IncludingOhaiDefaultRecipe < Base
33
33
  MSG = "Use the ohai_plugin resource to ship custom Ohai plugins instead of using the ohai::default recipe. If you're not shipping custom Ohai plugins, then you can remove this recipe entirely"
34
+ RESTRICT_ON_SEND = [:include_recipe].freeze
34
35
 
35
36
  def_node_matcher :ohai_recipe_usage?, <<-PATTERN
36
37
  (send nil? :include_recipe (str {"ohai" "ohai::default"}))
@@ -39,9 +39,9 @@ module RuboCop
39
39
  minimum_target_chef_version '14.0'
40
40
 
41
41
  MSG = 'The openssl_rsa_key resource was renamed to openssl_rsa_private_key in Chef Infra Client 14.0. The new resource name should be used.'
42
+ RESTRICT_ON_SEND = [:openssl_rsa_key].freeze
42
43
 
43
44
  def on_send(node)
44
- return unless node.method_name == :openssl_rsa_key
45
45
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
46
46
  corrector.replace(node.loc.expression, node.source.gsub(/^openssl_rsa_key/, 'openssl_rsa_private_key'))
47
47
  end
@@ -45,9 +45,9 @@ module RuboCop
45
45
  minimum_target_chef_version '14.4'
46
46
 
47
47
  MSG = 'The openssl_x509 resource was renamed to openssl_x509_certificate in Chef Infra Client 14.4. The new resource name should be used.'
48
+ RESTRICT_ON_SEND = [:openssl_x509].freeze
48
49
 
49
50
  def on_send(node)
50
- return unless node.method_name == :openssl_x509
51
51
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
52
52
  corrector.replace(node.loc.expression, node.source.gsub(/^openssl_x509/, 'openssl_x509_certificate'))
53
53
  end
@@ -36,9 +36,9 @@ module RuboCop
36
36
  extend AutoCorrector
37
37
 
38
38
  MSG = 'The osx_config_profile resource was renamed to osx_profile. The new resource name should be used.'
39
+ RESTRICT_ON_SEND = [:osx_config_profile].freeze
39
40
 
40
41
  def on_send(node)
41
- return unless node.method_name == :osx_config_profile
42
42
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
43
43
  corrector.replace(node.loc.expression, node.source.gsub(/^osx_config_profile/, 'osx_profile'))
44
44
  end
@@ -33,6 +33,7 @@ module RuboCop
33
33
  extend AutoCorrector
34
34
 
35
35
  MSG = 'Resource property sets name_attribute instead of name_property'
36
+ RESTRICT_ON_SEND = [:property].freeze
36
37
 
37
38
  # match on a property that has any name and any type and a hash that
38
39
  # contains name_attribute true. The hash pairs are wrapped in
@@ -40,9 +40,9 @@ module RuboCop
40
40
  #
41
41
  class SetOrReturnInResources < Base
42
42
  MSG = 'Do not use set_or_return within a method to define a property for a resource. Use the property method instead, which supports validation, reporting, and documentation functionality'
43
+ RESTRICT_ON_SEND = [:set_or_return].freeze
43
44
 
44
45
  def on_send(node)
45
- return unless node.method_name == :set_or_return
46
46
  add_offense(node, message: MSG, severity: :refactor)
47
47
  end
48
48
  end
@@ -44,6 +44,7 @@ module RuboCop
44
44
  extend AutoCorrector
45
45
 
46
46
  MSG = 'Custom Resources should contain properties not attributes'
47
+ RESTRICT_ON_SEND = [:attribute].freeze
47
48
 
48
49
  def_node_matcher :attribute?, <<-PATTERN
49
50
  (send nil? $:attribute ... )
@@ -39,9 +39,10 @@ module RuboCop
39
39
  minimum_target_chef_version '14.0'
40
40
 
41
41
  MSG = 'Chef Infra Client 14.0 and later includes :create, :delete, and :configure actions without the need for the sc cookbook dependency. See the windows_service documentation at https://docs.chef.io/resource_windows_service.html for additional details.'
42
+ RESTRICT_ON_SEND = [:sc_windows].freeze
42
43
 
43
44
  def on_send(node)
44
- add_offense(node, message: MSG, severity: :refactor) if node.method_name == :sc_windows
45
+ add_offense(node, message: MSG, severity: :refactor)
45
46
  end
46
47
  end
47
48
  end
@@ -35,9 +35,10 @@ module RuboCop
35
35
  minimum_target_chef_version '15.0'
36
36
 
37
37
  MSG = 'Use the archive_file resource built into Chef Infra Client 15+ instead of the seven_zip_archive'
38
+ RESTRICT_ON_SEND = [:seven_zip_archive].freeze
38
39
 
39
40
  def on_send(node)
40
- add_offense(node, message: MSG, severity: :refactor) if node.method_name == :seven_zip_archive
41
+ add_offense(node, message: MSG, severity: :refactor)
41
42
  end
42
43
  end
43
44
  end
@@ -39,9 +39,9 @@ module RuboCop
39
39
  minimum_target_chef_version '14.0'
40
40
 
41
41
  MSG = 'The sysctl_param resource was renamed to sysctl when it was added to Chef Infra Client 14.0. The new resource name should be used.'
42
+ RESTRICT_ON_SEND = [:sysctl_param].freeze
42
43
 
43
44
  def on_send(node)
44
- return unless node.method_name == :sysctl_param
45
45
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
46
46
  corrector.replace(node.loc.expression, node.source.gsub(/^sysctl_param/, 'sysctl'))
47
47
  end
@@ -32,6 +32,7 @@ module RuboCop
32
32
  include RangeHelp
33
33
 
34
34
  MSG = 'Chef Infra Client 12.4+ includes mixlib/shellout automatically in resources and providers.'
35
+ RESTRICT_ON_SEND = [:require].freeze
35
36
 
36
37
  def_node_matcher :require_mixlibshellout?, <<-PATTERN
37
38
  (send nil? :require ( str "mixlib/shellout"))
@@ -33,6 +33,7 @@ module RuboCop
33
33
  extend AutoCorrector
34
34
 
35
35
  MSG = 'Instead of using require with a File.expand_path and __FILE__ use the simpler require_relative method.'
36
+ RESTRICT_ON_SEND = [:require].freeze
36
37
 
37
38
  def_node_matcher :require_with_expand_path?, <<-PATTERN
38
39
  (send nil? :require
@@ -32,6 +32,7 @@ module RuboCop
32
32
  extend AutoCorrector
33
33
 
34
34
  MSG = 'Do not include the Windows default recipe, which only installs win32 gems already included in Chef Infra Client'
35
+ RESTRICT_ON_SEND = [:include_recipe].freeze
35
36
 
36
37
  def_node_matcher :windows_recipe_usage?, <<-PATTERN
37
38
  (send nil? :include_recipe (str {"windows" "windows::default"}))
@@ -44,11 +44,11 @@ module RuboCop
44
44
  minimum_target_chef_version '15.0'
45
45
 
46
46
  MSG = 'Chef Infra Client 15.0 and later includes a windows_uac resource that should be used to set Windows UAC values instead of setting registry keys directly.'
47
+ RESTRICT_ON_SEND = [:registry_key].freeze
47
48
 
48
49
  # non block execute resources
49
50
  def on_send(node)
50
- return unless node.method_name == :registry_key &&
51
- node&.arguments.first&.source.match?(/(HKLM|HKEY_LOCAL_MACHINE)\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System/i) &&
51
+ return unless node&.arguments.first&.source.match?(/(HKLM|HKEY_LOCAL_MACHINE)\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System/i) &&
52
52
  node.parent&.method_name != :describe
53
53
 
54
54
  # use source instead of .value in case there's string interpolation which adds a complex dstr type
@@ -34,9 +34,10 @@ module RuboCop
34
34
  minimum_target_chef_version '15.0'
35
35
 
36
36
  MSG = 'Use the archive_file resource built into Chef Infra Client 15+ instead of the windows_zipfile from the Windows cookbook'
37
+ RESTRICT_ON_SEND = [:windows_zipfile].freeze
37
38
 
38
39
  def on_send(node)
39
- add_offense(node, message: MSG, severity: :refactor) if node.method_name == :windows_zipfile
40
+ add_offense(node, message: MSG, severity: :refactor)
40
41
  end
41
42
  end
42
43
  end