cookstyle 6.16.4 → 6.17.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cookstyle +1 -1
  3. data/config/cookstyle.yml +47 -2
  4. data/config/upstream.yml +0 -1
  5. data/lib/cookstyle.rb +2 -2
  6. data/lib/cookstyle/version.rb +1 -1
  7. data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +2 -2
  8. data/lib/rubocop/cop/chef/correctness/invalid_default_action.rb +1 -0
  9. data/lib/rubocop/cop/chef/correctness/invalid_notification_timing.rb +1 -0
  10. data/lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb +1 -0
  11. data/lib/rubocop/cop/chef/correctness/invalid_platform_helper.rb +1 -0
  12. data/lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb +1 -0
  13. data/lib/rubocop/cop/chef/correctness/invalid_value_for_platform_family_helper.rb +1 -0
  14. data/lib/rubocop/cop/chef/correctness/invalid_value_for_platform_helper.rb +1 -0
  15. data/lib/rubocop/cop/chef/correctness/malformed_value_for_platform.rb +2 -2
  16. data/lib/rubocop/cop/chef/correctness/service_resource.rb +1 -0
  17. data/lib/rubocop/cop/chef/correctness/supports_must_be_float.rb +1 -0
  18. data/lib/rubocop/cop/chef/correctness/tmp_path.rb +1 -0
  19. data/lib/rubocop/cop/chef/deprecation/ use_automatic_resource_name.rb +1 -2
  20. data/lib/rubocop/cop/chef/deprecation/cb_depends_on_self.rb +1 -0
  21. data/lib/rubocop/cop/chef/deprecation/chef_handler_recipe.rb +1 -0
  22. data/lib/rubocop/cop/chef/deprecation/chef_rest.rb +1 -0
  23. data/lib/rubocop/cop/chef/deprecation/chef_rewind.rb +1 -0
  24. data/lib/rubocop/cop/chef/deprecation/chef_shellout.rb +86 -0
  25. data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +2 -1
  26. data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +1 -0
  27. data/lib/rubocop/cop/chef/deprecation/depends_poise.rb +1 -0
  28. data/lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb +1 -0
  29. data/lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb +8 -4
  30. data/lib/rubocop/cop/chef/deprecation/deprecated_shellout_methods.rb +10 -11
  31. data/lib/rubocop/cop/chef/deprecation/deprecated_windows_version_check.rb +2 -1
  32. data/lib/rubocop/cop/chef/deprecation/easy_install.rb +2 -1
  33. data/lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb +1 -0
  34. data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +1 -1
  35. data/lib/rubocop/cop/chef/deprecation/erl_call.rb +2 -1
  36. data/lib/rubocop/cop/chef/deprecation/execute_path_property.rb +51 -0
  37. data/lib/rubocop/cop/chef/deprecation/execute_relative_creates_without_cwd.rb +67 -0
  38. data/lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb +1 -0
  39. data/lib/rubocop/cop/chef/deprecation/legacy_yum_cookbook_recipes.rb +1 -0
  40. data/lib/rubocop/cop/chef/deprecation/name_property_and_default.rb +1 -0
  41. data/lib/rubocop/cop/chef/deprecation/partial_search_helper_usage.rb +2 -1
  42. data/lib/rubocop/cop/chef/deprecation/poise_archive.rb +1 -0
  43. data/lib/rubocop/cop/chef/deprecation/require_recipe.rb +1 -0
  44. data/lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb +3 -3
  45. data/lib/rubocop/cop/chef/deprecation/resource_uses_dsl_name_method.rb +2 -1
  46. data/lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb +1 -0
  47. data/lib/rubocop/cop/chef/deprecation/resource_uses_provider_base_method.rb +2 -1
  48. data/lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb +1 -0
  49. data/lib/rubocop/cop/chef/deprecation/run_command_helper.rb +1 -0
  50. data/lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb +5 -2
  51. data/lib/rubocop/cop/chef/deprecation/use_inline_resources.rb +10 -11
  52. data/lib/rubocop/cop/chef/deprecation/windows_feature_servermanagercmd.rb +1 -1
  53. data/lib/rubocop/cop/chef/deprecation/windows_package_installer_type_string.rb +61 -0
  54. data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +1 -0
  55. data/lib/rubocop/cop/chef/deprecation/yum_dnf_compat_recipe.rb +1 -0
  56. data/lib/rubocop/cop/chef/effortless/data_bags.rb +2 -1
  57. data/lib/rubocop/cop/chef/effortless/node_environment.rb +2 -2
  58. data/lib/rubocop/cop/chef/effortless/node_policygroup.rb +2 -2
  59. data/lib/rubocop/cop/chef/effortless/node_roles.rb +2 -2
  60. data/lib/rubocop/cop/chef/effortless/search_for_environments_or_roles.rb +2 -2
  61. data/lib/rubocop/cop/chef/effortless/search_used.rb +2 -1
  62. data/lib/rubocop/cop/chef/modernize/apt_default_recipe.rb +1 -0
  63. data/lib/rubocop/cop/chef/modernize/berksfile_source.rb +1 -0
  64. data/lib/rubocop/cop/chef/modernize/build_essential.rb +1 -0
  65. data/lib/rubocop/cop/chef/modernize/chef_14_resources.rb +1 -0
  66. data/lib/rubocop/cop/chef/modernize/chef_gem_nokogiri.rb +1 -0
  67. data/lib/rubocop/cop/chef/modernize/conditional_using_test.rb +1 -0
  68. data/lib/rubocop/cop/chef/modernize/cron_manage_resource.rb +1 -1
  69. data/lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb +1 -0
  70. data/lib/rubocop/cop/chef/modernize/dsl_include_in_resource.rb +1 -0
  71. data/lib/rubocop/cop/chef/modernize/execute_apt_update.rb +1 -0
  72. data/lib/rubocop/cop/chef/modernize/execute_sc_exe.rb +2 -1
  73. data/lib/rubocop/cop/chef/modernize/execute_sleep.rb +2 -1
  74. data/lib/rubocop/cop/chef/modernize/execute_sysctl.rb +2 -1
  75. data/lib/rubocop/cop/chef/modernize/execute_tzutil.rb +1 -0
  76. data/lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb +1 -0
  77. data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +1 -0
  78. data/lib/rubocop/cop/chef/modernize/macos_user_defaults.rb +1 -1
  79. data/lib/rubocop/cop/chef/modernize/minitest_handler_usage.rb +1 -0
  80. data/lib/rubocop/cop/chef/modernize/ohai_default_recipe.rb +1 -0
  81. data/lib/rubocop/cop/chef/modernize/openssl_rsa_key_resource.rb +1 -1
  82. data/lib/rubocop/cop/chef/modernize/openssl_x509_resource.rb +1 -1
  83. data/lib/rubocop/cop/chef/modernize/osx_config_profile_resource.rb +1 -1
  84. data/lib/rubocop/cop/chef/modernize/property_with_name_attribute.rb +1 -0
  85. data/lib/rubocop/cop/chef/modernize/resource_set_or_return.rb +1 -1
  86. data/lib/rubocop/cop/chef/modernize/resource_with_attributes.rb +1 -0
  87. data/lib/rubocop/cop/chef/modernize/sc_windows_resource.rb +2 -1
  88. data/lib/rubocop/cop/chef/modernize/seven_zip_archive.rb +2 -1
  89. data/lib/rubocop/cop/chef/modernize/{systctl_param_resource.rb → sysctl_param_resource.rb} +1 -1
  90. data/lib/rubocop/cop/chef/modernize/unnecessary_mixlib_shellout_require.rb +1 -0
  91. data/lib/rubocop/cop/chef/modernize/use_require_relative.rb +1 -0
  92. data/lib/rubocop/cop/chef/modernize/windows_default_recipe.rb +1 -0
  93. data/lib/rubocop/cop/chef/modernize/windows_registry_uac.rb +2 -2
  94. data/lib/rubocop/cop/chef/modernize/windows_zipfile.rb +2 -1
  95. data/lib/rubocop/cop/chef/modernize/zipfile_resource.rb +1 -0
  96. data/lib/rubocop/cop/chef/modernize/zypper_repo.rb +1 -1
  97. data/lib/rubocop/cop/chef/redundant/attribute_metadata.rb +1 -1
  98. data/lib/rubocop/cop/chef/redundant/conflicts_metadata.rb +1 -1
  99. data/lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb +7 -9
  100. data/lib/rubocop/cop/chef/redundant/grouping_metadata.rb +1 -2
  101. data/lib/rubocop/cop/chef/redundant/long_description_metadata.rb +1 -2
  102. data/lib/rubocop/cop/chef/redundant/property_with_default_and_required.rb +1 -0
  103. data/lib/rubocop/cop/chef/redundant/provides_metadata.rb +1 -2
  104. data/lib/rubocop/cop/chef/redundant/recipe_metadata.rb +1 -2
  105. data/lib/rubocop/cop/chef/redundant/replaces_metadata.rb +1 -2
  106. data/lib/rubocop/cop/chef/redundant/sensitive_property_in_resource.rb +1 -0
  107. data/lib/rubocop/cop/chef/redundant/string_property_with_nil_default.rb +1 -0
  108. data/lib/rubocop/cop/chef/redundant/suggests_metadata.rb +1 -2
  109. data/lib/rubocop/cop/chef/redundant/unnecessary_desired_state.rb +1 -0
  110. data/lib/rubocop/cop/chef/redundant/unnecessary_name_property.rb +1 -0
  111. data/lib/rubocop/cop/chef/sharing/default_maintainer_metadata.rb +1 -0
  112. data/lib/rubocop/cop/chef/sharing/include_property_descriptions.rb +1 -0
  113. data/lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb +1 -0
  114. data/lib/rubocop/cop/chef/sharing/invalid_license_string.rb +1 -0
  115. data/lib/rubocop/cop/chef/style/file_mode.rb +1 -0
  116. data/lib/rubocop/cop/chef/style/immediate_notification_timing.rb +1 -0
  117. data/lib/rubocop/cop/chef/style/include_recipe_with_parentheses.rb +1 -0
  118. data/lib/rubocop/cop/chef/style/true_false_resource_properties.rb +2 -0
  119. metadata +7 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c12050a348d700990dba93b33e7e15d0151ff5f2fef01aed90bb4f8014a6c04b
4
- data.tar.gz: 62577299c8994813248be5f8c73e27680fd9907d7c2088656e0cb03f035f5932
3
+ metadata.gz: ba71cee9089746fb000cf88734c03cd0017265baba00f7559ad9f31453ec8d78
4
+ data.tar.gz: 57599dee847f9240cd882bf777cdc5b6a45649851725f0520c9f2704ff181b14
5
5
  SHA512:
6
- metadata.gz: df19582100f6907be3fdb9d2fcd5f583c674b57538abce8d69d98e4112dab6232e65e3e298347479698a32dace5c41d6f99e6bd1ca83e48955c75f41ec982624
7
- data.tar.gz: 0ed13875d921f88edeb14a476b7bbd71342136e6d4f7a1b9ca83a17953951e949aa38ffc85e8792a4a48ecb774d3ad8387d4fe5aa48c757c0723830c06cb272c
6
+ metadata.gz: e54c382931bae26f96ddad4d54ed69f630d4ab02464dae8f5bbce300d0a0b552d765151dbc912456a34e8344b4517e98f520a839d20266d0f9a7e1d09b4eac0d
7
+ data.tar.gz: 2ed745d40e3538b0681cdce2e896a8ae1b99c29fd0ca7d74dd0c007ebf1b13458cbf39d383a26aa26a932289e1badf796e06ab6f145046f305c301b9b634a792
@@ -2,7 +2,7 @@
2
2
  # -*- encoding: utf-8 -*-
3
3
  # frozen_string_literal: true
4
4
 
5
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), %w(.. lib))
5
+ $LOAD_PATH.unshift File.join(__dir__, %w(.. lib))
6
6
 
7
7
  require 'cookstyle'
8
8
 
@@ -908,10 +908,11 @@ ChefDeprecations/RubyBlockCreateAction:
908
908
  - '**/Berksfile'
909
909
 
910
910
  ChefDeprecations/DeprecatedPlatformMethods:
911
- Description: Use provider_for_action instead of the deprecated Chef::Platform methods in resources.
911
+ Description: Use provider_for_action or provides instead of the deprecated Chef::Platform methods in resources.
912
912
  StyleGuide: '#chefdeprecationsdeprecatedplatformmethods'
913
913
  Enabled: true
914
914
  VersionAdded: '5.16.0'
915
+ VersionChanged: '6.17.0'
915
916
  Include:
916
917
  - '**/libraries/*.rb'
917
918
  - '**/resources/*.rb'
@@ -1062,6 +1063,46 @@ ChefDeprecations/CookbooksDependsOnSelf:
1062
1063
  Include:
1063
1064
  - '**/metadata.rb'
1064
1065
 
1066
+ ChefDeprecations/ChefShellout:
1067
+ Description: Don't use deprecated Chef::ShellOut which was removed in Chef Infra Client 13. Use Mixlib::ShellOut instead, which behaves identically.
1068
+ StyleGuide: '#chefdeprecationschefshellout'
1069
+ Enabled: true
1070
+ VersionAdded: '6.17.0'
1071
+ Exclude:
1072
+ - '**/metadata.rb'
1073
+ - '**/attributes/*.rb'
1074
+ - '**/Berksfile'
1075
+
1076
+ ChefDeprecations/ExecutePathProperty:
1077
+ Description: In Chef Infra Client 13 and later you must set path env vars in `execute` resources using the `environment` property not the legacy `path` property.
1078
+ StyleGuide: '#chefdeprecationsexecutepathproperty'
1079
+ Enabled: true
1080
+ VersionAdded: '6.17.0'
1081
+ Exclude:
1082
+ - '**/metadata.rb'
1083
+ - '**/attributes/*.rb'
1084
+ - '**/Berksfile'
1085
+
1086
+ ChefDeprecations/ExecuteRelativeCreatesWithoutCwd:
1087
+ Description: In Chef Infra Client 13 and later you must either specify an absolute path when using the `execute` resource's `creates` property or also use the `cwd` property.
1088
+ StyleGuide: '#chefdeprecationsexecuterelativecreateswithoutcwd'
1089
+ Enabled: true
1090
+ VersionAdded: '6.17.0'
1091
+ Exclude:
1092
+ - '**/metadata.rb'
1093
+ - '**/attributes/*.rb'
1094
+ - '**/Berksfile'
1095
+
1096
+ ChefDeprecations/WindowsPackageInstallerTypeString:
1097
+ Description: In Chef Infra Client 13 and later the `windows_package` resource's `installer_type` property must be a symbol.
1098
+ StyleGuide: '#chefdeprecationswindowspackageinstallertypestring'
1099
+ Enabled: true
1100
+ VersionAdded: '6.17.0'
1101
+ Exclude:
1102
+ - '**/metadata.rb'
1103
+ - '**/attributes/*.rb'
1104
+ - '**/Berksfile'
1105
+
1065
1106
  ###############################
1066
1107
  # ChefModernize: Cleaning up legacy code and using new built-in resources
1067
1108
  ###############################
@@ -2612,4 +2653,8 @@ Style/BisectedAttrAccessor:
2612
2653
 
2613
2654
  # avoid assignments that aren't needed
2614
2655
  Style/RedundantAssignment:
2615
- Enabled: true
2656
+ Enabled: true
2657
+
2658
+ # alert on invalid ruby
2659
+ Lint/Syntax:
2660
+ Enabled: true
@@ -1861,7 +1861,6 @@ Lint/Syntax:
1861
1861
  Enabled: true
1862
1862
  VersionAdded: '0.9'
1863
1863
 
1864
-
1865
1864
  Lint/ToJSON:
1866
1865
  Description: 'Ensure #to_json includes an optional argument.'
1867
1866
  Enabled: true
@@ -19,7 +19,7 @@ module RuboCop
19
19
  class ConfigLoader
20
20
  RUBOCOP_HOME.gsub!(
21
21
  /^.*$/,
22
- File.realpath(File.join(File.dirname(__FILE__), '..'))
22
+ File.realpath(File.join(__dir__, '..'))
23
23
  )
24
24
 
25
25
  DEFAULT_FILE.gsub!(
@@ -46,7 +46,7 @@ require_relative 'rubocop/chef/cookbook_only'
46
46
  require_relative 'rubocop/cop/target_chef_version'
47
47
 
48
48
  # Chef Infra specific cops
49
- Dir.glob(File.dirname(__FILE__) + '/rubocop/cop/chef/**/*.rb') do |file|
49
+ Dir.glob(__dir__ + '/rubocop/cop/chef/**/*.rb') do |file|
50
50
  next if File.directory?(file)
51
51
 
52
52
  require_relative file # not actually relative but require_relative is faster
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Cookstyle
3
- VERSION = "6.16.4" # rubocop: disable Style/StringLiterals
3
+ VERSION = "6.17.6" # rubocop: disable Style/StringLiterals
4
4
  RUBOCOP_VERSION = '0.90.0'
5
5
  end
@@ -38,11 +38,11 @@ module RuboCop
38
38
  MSG = 'Libraries should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes directly.'
39
39
 
40
40
  def_node_matcher :legacy_class_sends?, <<-PATTERN
41
- (send (const (const (cbase) :Chef) {:Recipe :Provider}) :send (sym :include) ... )
41
+ (send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :send (sym :include) ... )
42
42
  PATTERN
43
43
 
44
44
  def_node_matcher :legacy_class_includes?, <<-PATTERN
45
- (send (const (const (cbase) :Chef) {:Recipe :Provider}) :include ... )
45
+ (send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :include ... )
46
46
  PATTERN
47
47
 
48
48
  def on_send(node)
@@ -32,6 +32,7 @@ module RuboCop
32
32
  module ChefCorrectness
33
33
  class InvalidDefaultAction < Base
34
34
  MSG = 'Default actions in resources should be symbols or an array of symbols.'
35
+ RESTRICT_ON_SEND = [:default_action].freeze
35
36
 
36
37
  def_node_matcher :default_action?, '(send nil? :default_action $_)'
37
38
 
@@ -37,6 +37,7 @@ module RuboCop
37
37
  #
38
38
  class InvalidNotificationTiming < Base
39
39
  MSG = 'Valid notification timings are :immediately, :immediate (alias for :immediately), :delayed, and :before.'
40
+ RESTRICT_ON_SEND = [:notifies, :subscribes].freeze
40
41
 
41
42
  def_node_matcher :notification_with_timing?, <<-PATTERN
42
43
  (send nil? {:notifies :subscribes} (sym _) (...) $(sym _))
@@ -37,6 +37,7 @@ module RuboCop
37
37
  extend AutoCorrector
38
38
 
39
39
  MSG = 'Pass valid platform families to the platform_family? helper.'
40
+ RESTRICT_ON_SEND = [:platform_family?].freeze
40
41
 
41
42
  def_node_matcher :platform_family_helper?, <<-PATTERN
42
43
  (send nil? :platform_family? $str*)
@@ -36,6 +36,7 @@ module RuboCop
36
36
  include ::RuboCop::Chef::PlatformHelpers
37
37
 
38
38
  MSG = 'Pass valid platforms to the platform? helper.'
39
+ RESTRICT_ON_SEND = [:platform?].freeze
39
40
 
40
41
  def_node_matcher :platform_helper?, <<-PATTERN
41
42
  (send nil? :platform? $str*)
@@ -37,6 +37,7 @@ module RuboCop
37
37
  include ::RuboCop::Chef::PlatformHelpers
38
38
 
39
39
  MSG = 'metadata.rb "supports" platform is invalid'
40
+ RESTRICT_ON_SEND = [:supports].freeze
40
41
 
41
42
  def_node_matcher :supports?, '(send nil? :supports $str ...)'
42
43
 
@@ -39,6 +39,7 @@ module RuboCop
39
39
  include ::RuboCop::Chef::PlatformHelpers
40
40
 
41
41
  MSG = 'Pass valid platform families to the value_for_platform_family helper.'
42
+ RESTRICT_ON_SEND = [:value_for_platform_family].freeze
42
43
 
43
44
  def_node_matcher :value_for_platform_family?, <<-PATTERN
44
45
  (send nil? :value_for_platform_family
@@ -38,6 +38,7 @@ module RuboCop
38
38
  include ::RuboCop::Chef::PlatformHelpers
39
39
 
40
40
  MSG = 'Pass valid platforms to the value_for_platform helper.'
41
+ RESTRICT_ON_SEND = [:value_for_platform].freeze
41
42
 
42
43
  def_node_matcher :value_for_platform?, <<-PATTERN
43
44
  (send nil? :value_for_platform
@@ -45,9 +45,9 @@ module RuboCop
45
45
  # )
46
46
  #
47
47
  class MalformedPlatformValueForPlatformHelper < Base
48
- def on_send(node)
49
- return unless node.method_name == :value_for_platform
48
+ RESTRICT_ON_SEND = [:value_for_platform].freeze
50
49
 
50
+ def on_send(node)
51
51
  if node.arguments.count > 1
52
52
  msg = 'Malformed value_for_platform helper argument. The value_for_platform helper takes a single hash of platforms as an argument.'
53
53
  add_offense(node, message: msg, severity: :refactor)
@@ -29,6 +29,7 @@ module RuboCop
29
29
  #
30
30
  class ServiceResource < Base
31
31
  MSG = 'Use a service resource to start and stop services'
32
+ RESTRICT_ON_SEND = [:command].freeze
32
33
 
33
34
  def_node_matcher :execute_command?, <<-PATTERN
34
35
  (send nil? :command $str)
@@ -34,6 +34,7 @@ module RuboCop
34
34
  extend RuboCop::Cop::AutoCorrector
35
35
 
36
36
  MSG = 'Versions used in metadata.rb supports calls should be floats not integers.'
37
+ RESTRICT_ON_SEND = [:supports].freeze
37
38
 
38
39
  def_node_matcher :supports_with_constraint?, '(send nil? :supports str $str)'
39
40
 
@@ -32,6 +32,7 @@ module RuboCop
32
32
  #
33
33
  class TmpPath < Base
34
34
  MSG = 'Use file_cache_path rather than hard-coding tmp paths'
35
+ RESTRICT_ON_SEND = [:remote_file].freeze
35
36
 
36
37
  def_node_matcher :remote_file?, <<-PATTERN
37
38
  (send nil? :remote_file $str)
@@ -37,10 +37,9 @@ module RuboCop
37
37
  include RangeHelp
38
38
 
39
39
  MSG = 'The use_automatic_resource_name method was removed in Chef Infra Client 16. The resource name/provides should be set explicitly instead.'
40
+ RESTRICT_ON_SEND = [:use_automatic_resource_name].freeze
40
41
 
41
42
  def on_send(node)
42
- return unless node.method_name == :use_automatic_resource_name
43
-
44
43
  add_offense(node.loc.selector, message: MSG, severity: :warning) do |corrector|
45
44
  corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
46
45
  end
@@ -36,6 +36,7 @@ module RuboCop
36
36
  include RangeHelp
37
37
 
38
38
  MSG = 'A cookbook cannot depend on itself. This will fail on Chef Infra Client 13+'
39
+ RESTRICT_ON_SEND = [:name].freeze
39
40
 
40
41
  def_node_search :dependencies, '(send nil? :depends str ...)'
41
42
  def_node_matcher :cb_name?, '(send nil? :name str ...)'
@@ -33,6 +33,7 @@ module RuboCop
33
33
  extend AutoCorrector
34
34
 
35
35
  MSG = 'There is no need to include the empty and deprecated chef_handler::default recipe in order to use the chef_handler resource'
36
+ RESTRICT_ON_SEND = [:include_recipe].freeze
36
37
 
37
38
  def_node_matcher :chef_handler_recipe?, <<-PATTERN
38
39
  (send nil? :include_recipe (str {"chef_handler" "chef_handler::default"}))
@@ -30,6 +30,7 @@ module RuboCop
30
30
  #
31
31
  class UsesChefRESTHelpers < Base
32
32
  MSG = "Don't use the helpers in Chef::REST which were removed in Chef Infra Client 13"
33
+ RESTRICT_ON_SEND = [:require].freeze
33
34
 
34
35
  def_node_matcher :require_rest?, <<-PATTERN
35
36
  (send nil? :require ( str "chef/rest"))
@@ -49,6 +49,7 @@ module RuboCop
49
49
  }.freeze
50
50
 
51
51
  MSG = 'Use delete_resource / edit_resource introduced in Chef Infra Client 12.10 instead of functionality in the deprecated chef-rewind gem'
52
+ RESTRICT_ON_SEND = [:chef_gem, :require, :rewind, :unwind].freeze
52
53
 
53
54
  def_node_matcher :rewind_gem_install?, <<-PATTERN
54
55
  (send nil? :chef_gem (str "chef-rewind"))
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2020, Chef Software Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ module RuboCop
20
+ module Cop
21
+ module Chef
22
+ module ChefDeprecations
23
+ # Don't use deprecated Chef::ShellOut which was removed in Chef Infra Client 13.
24
+ # Use Mixlib::ShellOut instead, which behaves identically or convert to the shell_out
25
+ # helper provided in chef-utils.
26
+ #
27
+ # @example
28
+ #
29
+ # # bad
30
+ # include Chef::ShellOut
31
+ # require 'chef/shellout'
32
+ # Chef::ShellOut.new('some_command')
33
+ #
34
+ # # good
35
+ # include Mixlib::ShellOut
36
+ # require 'mixlib/shellout'
37
+ # Mixlib::ShellOut.new('some_command')
38
+ #
39
+ class ChefShellout < Base
40
+ include RangeHelp
41
+ extend AutoCorrector
42
+
43
+ MSG = "Don't use deprecated Chef::ShellOut which was removed in Chef Infra Client 13. Use Mixlib::ShellOut instead, which behaves identically."
44
+ # RESTRICT_ON_SEND = [:new, :require, :include].freeze
45
+
46
+ def_node_matcher :include_shellout?, <<-PATTERN
47
+ (send nil? :include
48
+ (const
49
+ (const nil? :Chef) :ShellOut))
50
+ PATTERN
51
+
52
+ def_node_matcher :require_shellout?, <<-PATTERN
53
+ (send nil? :require (str "chef/shellout"))
54
+ PATTERN
55
+
56
+ def_node_matcher :shellout_new?, <<-PATTERN
57
+ (send
58
+ (const
59
+ (const nil? :Chef) :ShellOut) :new
60
+ ... )
61
+ PATTERN
62
+
63
+ def on_send(node)
64
+ include_shellout?(node) do
65
+ add_offense(node, message: MSG, severity: :warning) do |corrector|
66
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
67
+ end
68
+ end
69
+
70
+ require_shellout?(node) do
71
+ add_offense(node, message: MSG, severity: :warning) do |corrector|
72
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
73
+ end
74
+ end
75
+
76
+ shellout_new?(node) do
77
+ add_offense(node, message: MSG, severity: :warning) do |corrector|
78
+ corrector.replace(node.loc.expression, node.source.gsub('Chef::ShellOut', 'Mixlib::ShellOut'))
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -29,16 +29,17 @@ module RuboCop
29
29
  class CookbookDependsOnCompatResource < Base
30
30
  include RangeHelp
31
31
  extend TargetChefVersion
32
+ extend AutoCorrector
32
33
 
33
34
  minimum_target_chef_version '12.19'
34
35
 
35
36
  MSG = "Don't depend on the deprecated compat_resource cookbook made obsolete by Chef 12.19+"
37
+ RESTRICT_ON_SEND = [:depends].freeze
36
38
 
37
39
  def_node_matcher :depends_compat_resource?, <<-PATTERN
38
40
  (send nil? :depends (str {"compat_resource"}))
39
41
  PATTERN
40
42
 
41
- extend AutoCorrector
42
43
  def on_send(node)
43
44
  depends_compat_resource?(node) do
44
45
  add_offense(node, message: MSG, severity: :warning) do |corrector|
@@ -32,6 +32,7 @@ module RuboCop
32
32
  minimum_target_chef_version '13.0'
33
33
 
34
34
  MSG = "Don't depend on the deprecated partial_search cookbook made obsolete by Chef 13"
35
+ RESTRICT_ON_SEND = [:depends].freeze
35
36
 
36
37
  def_node_matcher :depends_partial_search?, <<-PATTERN
37
38
  (send nil? :depends (str "partial_search"))
@@ -29,6 +29,7 @@ module RuboCop
29
29
  #
30
30
  class CookbookDependsOnPoise < Base
31
31
  MSG = 'Cookbooks should not depend on the deprecated Poise framework'
32
+ RESTRICT_ON_SEND = [:depends].freeze
32
33
 
33
34
  def_node_matcher :depends_method?, <<-PATTERN
34
35
  (send nil? :depends $str)
@@ -39,6 +39,7 @@ module RuboCop
39
39
  extend AutoCorrector
40
40
 
41
41
  MSG = "Don't use deprecated Mixins no longer included in Chef Infra Client 14 and later."
42
+ RESTRICT_ON_SEND = [:include, :require].freeze
42
43
 
43
44
  def_node_matcher :deprecated_mixin?, <<-PATTERN
44
45
  (send nil? :include (const (const (const nil? :Chef) :Mixin) { :Language :LanguageIncludeAttribute :RecipeDefinitionDSLCore :LanguageIncludeRecipe }))
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
- # Copyright:: 2019, Chef Software Inc.
3
+ # Copyright:: 2019-2020, Chef Software Inc.
4
4
  # Author:: Tim Smith (<tsmith@chef.io>)
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +20,7 @@ module RuboCop
20
20
  module Cop
21
21
  module Chef
22
22
  module ChefDeprecations
23
- # Use provider_for_action instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.
23
+ # Use provider_for_action or provides instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.
24
24
  #
25
25
  # @example
26
26
  #
@@ -34,15 +34,19 @@ module RuboCop
34
34
  # resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
35
35
  # provider = Chef::Platform.find_provider_for_node(node, resource)
36
36
  #
37
+ # Chef::Platform.set :platform => :mac_os_x, :resource => :package, :provider => Chef::Provider::Package::Homebrew
38
+ #
37
39
  # # good
38
40
  # resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
39
41
  # provider = resource.provider_for_action(:create)
40
42
  #
43
+ # # provides :package, platform_family: 'mac_os_x'
44
+
41
45
  class DeprecatedPlatformMethods < Base
42
- MSG = 'Use provider_for_action instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.'
46
+ MSG = 'Use provider_for_action or provides instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.'
43
47
 
44
48
  def_node_matcher :platform_method?, <<-PATTERN
45
- (send (const (const nil? :Chef) :Platform) {:provider_for_resource :find_provider :find_provider_for_node} ... )
49
+ (send (const (const nil? :Chef) :Platform) {:provider_for_resource :find_provider :find_provider_for_node :set} ... )
46
50
  PATTERN
47
51
 
48
52
  def on_send(node)