cookstyle 6.18.8 → 6.19.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/config/cookstyle.yml +19 -0
  3. data/config/upstream.yml +14 -3
  4. data/lib/cookstyle.rb +0 -3
  5. data/lib/cookstyle/version.rb +2 -2
  6. data/lib/rubocop/cop/chef/correctness/block_guard_clause_string_only.rb +1 -1
  7. data/lib/rubocop/cop/chef/correctness/chef_application_fatal.rb +1 -1
  8. data/lib/rubocop/cop/chef/correctness/conditional_ruby_shellout.rb +1 -1
  9. data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +18 -37
  10. data/lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb +1 -1
  11. data/lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb +2 -2
  12. data/lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb +1 -1
  13. data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +1 -1
  14. data/lib/rubocop/cop/chef/correctness/lazy_in_resource_guard.rb +1 -1
  15. data/lib/rubocop/cop/chef/correctness/macos_userdefaults_invalid_type.rb +2 -2
  16. data/lib/rubocop/cop/chef/correctness/notifies_action_not_symbol.rb +1 -1
  17. data/lib/rubocop/cop/chef/correctness/resource_with_none_action.rb +1 -1
  18. data/lib/rubocop/cop/chef/correctness/scoped_file_exist.rb +1 -1
  19. data/lib/rubocop/cop/chef/correctness/supports_must_be_float.rb +2 -2
  20. data/lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb +1 -1
  21. data/lib/rubocop/cop/chef/deprecation/chef_rewind.rb +2 -2
  22. data/lib/rubocop/cop/chef/deprecation/chef_shellout.rb +1 -1
  23. data/lib/rubocop/cop/chef/deprecation/chef_windows_platform_helper.rb +1 -1
  24. data/lib/rubocop/cop/chef/deprecation/chefdk_generators.rb +1 -1
  25. data/lib/rubocop/cop/chef/deprecation/chefspec_coverage_report.rb +1 -1
  26. data/lib/rubocop/cop/chef/deprecation/chefspec_legacy_runner.rb +1 -1
  27. data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +1 -1
  28. data/lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb +1 -1
  29. data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +1 -1
  30. data/lib/rubocop/cop/chef/deprecation/execute_path_property.rb +1 -1
  31. data/lib/rubocop/cop/chef/deprecation/execute_relative_creates_without_cwd.rb +1 -1
  32. data/lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb +1 -1
  33. data/lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb +1 -1
  34. data/lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb +1 -1
  35. data/lib/rubocop/cop/chef/deprecation/powershell_cookbook_helpers.rb +1 -1
  36. data/lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb +2 -2
  37. data/lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb +2 -2
  38. data/lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb +1 -1
  39. data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +1 -1
  40. data/lib/rubocop/cop/chef/deprecation/windows_package_installer_type_string.rb +1 -1
  41. data/lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb +2 -2
  42. data/lib/rubocop/cop/chef/deprecation/windows_version_helpers.rb +4 -4
  43. data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +1 -1
  44. data/lib/rubocop/cop/chef/effortless/chef_vault_used.rb +89 -0
  45. data/lib/rubocop/cop/chef/effortless/depends_chef_vault.rb +49 -0
  46. data/lib/rubocop/cop/chef/modernize/action_method_in_resource.rb +2 -2
  47. data/lib/rubocop/cop/chef/modernize/berksfile_source.rb +2 -2
  48. data/lib/rubocop/cop/chef/modernize/build_essential.rb +1 -1
  49. data/lib/rubocop/cop/chef/modernize/conditional_using_test.rb +1 -1
  50. data/lib/rubocop/cop/chef/modernize/cron_manage_resource.rb +1 -1
  51. data/lib/rubocop/cop/chef/modernize/databag_helpers.rb +1 -1
  52. data/lib/rubocop/cop/chef/modernize/foodcritic_comments.rb +1 -1
  53. data/lib/rubocop/cop/chef/modernize/if_provides_default_action.rb +1 -1
  54. data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +2 -2
  55. data/lib/rubocop/cop/chef/modernize/macos_user_defaults.rb +1 -1
  56. data/lib/rubocop/cop/chef/modernize/node_init_package.rb +3 -3
  57. data/lib/rubocop/cop/chef/modernize/node_roles_include.rb +1 -1
  58. data/lib/rubocop/cop/chef/modernize/openssl_rsa_key_resource.rb +1 -1
  59. data/lib/rubocop/cop/chef/modernize/openssl_x509_resource.rb +1 -1
  60. data/lib/rubocop/cop/chef/modernize/osx_config_profile_resource.rb +1 -1
  61. data/lib/rubocop/cop/chef/modernize/property_with_name_attribute.rb +1 -1
  62. data/lib/rubocop/cop/chef/modernize/respond_to_compile_time.rb +1 -1
  63. data/lib/rubocop/cop/chef/modernize/respond_to_metadata.rb +5 -5
  64. data/lib/rubocop/cop/chef/modernize/respond_to_provides.rb +1 -1
  65. data/lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb +1 -1
  66. data/lib/rubocop/cop/chef/modernize/shell_out_helper.rb +1 -1
  67. data/lib/rubocop/cop/chef/modernize/simplify_apt_ppa_setup.rb +1 -1
  68. data/lib/rubocop/cop/chef/modernize/sysctl_param_resource.rb +1 -1
  69. data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +1 -1
  70. data/lib/rubocop/cop/chef/modernize/use_require_relative.rb +1 -1
  71. data/lib/rubocop/cop/chef/modernize/zypper_repo.rb +1 -1
  72. data/lib/rubocop/cop/chef/redundant/double_compile_time.rb +1 -1
  73. data/lib/rubocop/cop/chef/redundant/multiple_platform_checks.rb +1 -1
  74. data/lib/rubocop/cop/chef/redundant/ohai_attribute_to_string.rb +1 -1
  75. data/lib/rubocop/cop/chef/redundant/use_create_if_missing.rb +1 -1
  76. data/lib/rubocop/cop/chef/sharing/include_property_descriptions.rb +1 -1
  77. data/lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb +1 -1
  78. data/lib/rubocop/cop/chef/sharing/invalid_license_string.rb +1 -1
  79. data/lib/rubocop/cop/chef/style/attribute_keys.rb +1 -1
  80. data/lib/rubocop/cop/chef/style/chef_whaaat.rb +1 -1
  81. data/lib/rubocop/cop/chef/style/comment_sentence_spacing.rb +2 -2
  82. data/lib/rubocop/cop/chef/style/comments_copyright_format.rb +2 -2
  83. data/lib/rubocop/cop/chef/style/comments_default_copyright.rb +1 -1
  84. data/lib/rubocop/cop/chef/style/comments_format.rb +6 -13
  85. data/lib/rubocop/cop/chef/style/file_mode.rb +2 -2
  86. data/lib/rubocop/cop/chef/style/immediate_notification_timing.rb +2 -2
  87. data/lib/rubocop/cop/chef/style/include_recipe_with_parentheses.rb +2 -2
  88. data/lib/rubocop/cop/chef/style/negating_only_if.rb +2 -2
  89. data/lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb +2 -2
  90. data/lib/rubocop/cop/chef/style/simplify_platform_major_version_check.rb +1 -1
  91. data/lib/rubocop/cop/chef/style/true_false_resource_properties.rb +2 -2
  92. data/lib/rubocop/cop/chef/style/unnecessary_os_check.rb +4 -4
  93. data/lib/rubocop/cop/chef/style/unnecessary_platform_case_statement.rb +2 -2
  94. data/lib/rubocop/cop/chef/style/use_platform_helpers.rb +6 -6
  95. metadata +6 -5
  96. data/lib/rubocop/monkey_patches/rescue_ensure_alignment.rb +0 -22
@@ -40,7 +40,7 @@ module RuboCop
40
40
 
41
41
  def on_send(node)
42
42
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
43
- corrector.replace(node.loc.expression, node.source.gsub(/^osx_config_profile/, 'osx_profile'))
43
+ corrector.replace(node, node.source.gsub(/^osx_config_profile/, 'osx_profile'))
44
44
  end
45
45
  end
46
46
  end
@@ -45,7 +45,7 @@ module RuboCop
45
45
  def on_send(node)
46
46
  property_with_name_attribute?(node) do |name_attribute|
47
47
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
48
- corrector.replace(name_attribute.loc.expression, 'name_property: true')
48
+ corrector.replace(name_attribute, 'name_property: true')
49
49
  end
50
50
  end
51
51
  end
@@ -80,7 +80,7 @@ module RuboCop
80
80
  match_property_in_resource?(:chef_gem, 'compile_time', node) do |compile_time_property|
81
81
  compile_time_method_defined?(compile_time_property.parent) do |val|
82
82
  add_offense(compile_time_property.parent, message: MSG, severity: :refactor) do |corrector|
83
- corrector.replace(compile_time_property.parent.loc.expression, "compile_time #{val.source}")
83
+ corrector.replace(compile_time_property.parent, "compile_time #{val.source}")
84
84
  end
85
85
  end
86
86
  end
@@ -27,6 +27,7 @@ module RuboCop
27
27
  # # bad
28
28
  # chef_version '>= 13' if respond_to?(:chef_version)
29
29
  # chef_version '>= 13' if defined?(chef_version)
30
+ # chef_version '>= 13' unless defined?(Ridley::Chef::Cookbook::Metadata)
30
31
  # if defined(chef_version)
31
32
  # chef_version '>= 13'
32
33
  # end
@@ -40,7 +41,7 @@ module RuboCop
40
41
 
41
42
  minimum_target_chef_version '12.15'
42
43
 
43
- MSG = 'It is no longer necessary to use respond_to? or if_defined? in metadata.rb in Chef Infra Client 12.15 and later'
44
+ MSG = 'It is no longer necessary to use respond_to? or defined? in metadata.rb in Chef Infra Client 12.15 and later'
44
45
 
45
46
  def on_if(node)
46
47
  if_respond_to?(node) do
@@ -51,7 +52,7 @@ module RuboCop
51
52
  # is a block under the if statement and node.parent.if_branch can get us that block
52
53
  node = node.parent unless node.if_type?
53
54
 
54
- corrector.replace(node.loc.expression, node.if_branch.source)
55
+ corrector.replace(node, node.if_branch.source)
55
56
  end
56
57
  end
57
58
  end
@@ -61,10 +62,9 @@ module RuboCop
61
62
  # node.if_branch is the actual method call we want to extract.
62
63
  # If a series of metadata methods are wrapped in an if statement then the content we want
63
64
  # is a block under the if statement and node.parent.if_branch can get us that block
64
-
65
- node = node.parent if node.parent.if? && !node.if_type? # we want the whole if statement
65
+ node = node.parent if node.parent.conditional? # we want the whole conditional statement
66
66
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
67
- corrector.replace(node.loc.expression, node.if_branch.source)
67
+ corrector.replace(node, node.if_branch.source)
68
68
  end
69
69
  end
70
70
 
@@ -39,7 +39,7 @@ module RuboCop
39
39
  def on_if(node)
40
40
  if_respond_to_provides?(node) do
41
41
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
42
- corrector.replace(node.loc.expression, node.children[1].source)
42
+ corrector.replace(node, node.children[1].source)
43
43
  end
44
44
  end
45
45
  end
@@ -37,7 +37,7 @@ module RuboCop
37
37
  def on_if(node)
38
38
  if_respond_to_resource_name?(node) do
39
39
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
40
- corrector.replace(node.loc.expression, node.children[1].source)
40
+ corrector.replace(node, node.children[1].source)
41
41
  end
42
42
  end
43
43
  end
@@ -49,7 +49,7 @@ module RuboCop
49
49
  def on_send(node)
50
50
  mixlib_shellout_run_cmd?(node) do |cmd|
51
51
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
52
- corrector.replace(node.loc.expression, "shell_out(#{cmd.loc.expression.source})")
52
+ corrector.replace(node, "shell_out(#{cmd.source})")
53
53
  end
54
54
  end
55
55
  end
@@ -52,7 +52,7 @@ module RuboCop
52
52
  if %r{http(s)*://ppa.launchpad.net/(.*)/ubuntu$}.match?(uri.arguments&.first&.str_content)
53
53
  add_offense(uri, message: MSG, severity: :refactor) do |corrector|
54
54
  next unless (replacement_val = %r{http(s)*://ppa.launchpad.net/(.*)/ubuntu}.match(node.source)[2])
55
- corrector.replace(uri.loc.expression, "uri 'ppa:#{replacement_val}'")
55
+ corrector.replace(uri, "uri 'ppa:#{replacement_val}'")
56
56
  end
57
57
  end
58
58
  end
@@ -43,7 +43,7 @@ module RuboCop
43
43
 
44
44
  def on_send(node)
45
45
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
46
- corrector.replace(node.loc.expression, node.source.gsub(/^sysctl_param/, 'sysctl'))
46
+ corrector.replace(node, node.source.gsub(/^sysctl_param/, 'sysctl'))
47
47
  end
48
48
  end
49
49
  end
@@ -98,7 +98,7 @@ module RuboCop
98
98
  def check_offense(node)
99
99
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
100
100
  package_array_install?(node) do |vals|
101
- corrector.replace(node.loc.expression, "package #{vals.source}")
101
+ corrector.replace(node, "package #{vals.source}")
102
102
  end
103
103
  end
104
104
  end
@@ -49,7 +49,7 @@ module RuboCop
49
49
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
50
50
  corrected_value = file.value
51
51
  corrected_value.slice!(%r{^../}) # take the first ../ off the path
52
- corrector.replace(node.loc.expression, "require_relative '#{corrected_value}'")
52
+ corrector.replace(node, "require_relative '#{corrected_value}'")
53
53
  end
54
54
  end
55
55
  end
@@ -50,7 +50,7 @@ module RuboCop
50
50
 
51
51
  def on_send(node)
52
52
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
53
- corrector.replace(node.loc.expression, node.source.gsub(/^zypper_repo/, 'zypper_repository'))
53
+ corrector.replace(node, node.source.gsub(/^zypper_repo/, 'zypper_repository'))
54
54
  end
55
55
  end
56
56
  end
@@ -54,7 +54,7 @@ module RuboCop
54
54
  def on_send(node)
55
55
  compile_time_and_run_action?(node) do |resource, action, run_action|
56
56
  add_offense(node.loc.selector, message: MSG, severity: :refactor) do |corrector|
57
- corrector.replace(node.loc.expression, resource.source.gsub(action.to_s, run_action.to_s))
57
+ corrector.replace(node, resource.source.gsub(action.to_s, run_action.to_s))
58
58
  end
59
59
  end
60
60
  end
@@ -48,7 +48,7 @@ module RuboCop
48
48
 
49
49
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
50
50
  new_string = "#{helpers.first}(#{plats.map(&:source).join(', ')})"
51
- corrector.replace(node.loc.expression, new_string)
51
+ corrector.replace(node, new_string)
52
52
  end
53
53
  end
54
54
  end
@@ -54,7 +54,7 @@ module RuboCop
54
54
  def on_send(node)
55
55
  attribute_to_s?(node) do |method|
56
56
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
57
- corrector.replace(node.loc.expression, "node['#{method.value}']")
57
+ corrector.replace(node, "node['#{method.value}']")
58
58
  end
59
59
  end
60
60
  end
@@ -64,7 +64,7 @@ module RuboCop
64
64
  return unless props == resource_blk_name && create_action?(node.parent.parent).nil?
65
65
 
66
66
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
67
- corrector.replace(node.loc.expression, 'action :create_if_missing')
67
+ corrector.replace(node, 'action :create_if_missing')
68
68
  end
69
69
  end
70
70
  end
@@ -45,7 +45,7 @@ module RuboCop
45
45
 
46
46
  def on_send(node)
47
47
  property?(node) do
48
- add_offense(node.loc.expression, message: MSG, severity: :refactor) unless description_hash?(node)
48
+ add_offense(node, message: MSG, severity: :refactor) unless description_hash?(node)
49
49
  end
50
50
  end
51
51
  end
@@ -51,7 +51,7 @@ module RuboCop
51
51
  def on_send(node)
52
52
  insecure_cb_url?(node) do
53
53
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
54
- corrector.replace(node.loc.expression, node.source.gsub(%r{http://(www.)*}, 'https://'))
54
+ corrector.replace(node, node.source.gsub(%r{http://(www.)*}, 'https://'))
55
55
  end
56
56
  end
57
57
  end
@@ -467,7 +467,7 @@ module RuboCop
467
467
  return if valid_license?(license.str_content)
468
468
  add_offense(license, message: MSG, severity: :refactor) do |corrector|
469
469
  correct_string = autocorrect_license_string(license.str_content)
470
- corrector.replace(license.loc.expression, "'#{correct_string}'") if correct_string
470
+ corrector.replace(license, "'#{correct_string}'") if correct_string
471
471
  end
472
472
  end
473
473
  end
@@ -85,7 +85,7 @@ module RuboCop
85
85
  else # strings
86
86
  key_string.inspect
87
87
  end
88
- corrector.replace(node.loc.expression, key_replacement)
88
+ corrector.replace(node, key_replacement)
89
89
  end
90
90
  end
91
91
  end
@@ -40,7 +40,7 @@ module RuboCop
40
40
 
41
41
  processed_source.comments.each do |comment|
42
42
  next unless comment.text.match?(/Chef [a-z]/) # https://rubular.com/r/0YzfDAbwJrDHix
43
- add_offense(comment.loc.expression, message: MSG, severity: :refactor)
43
+ add_offense(comment, message: MSG, severity: :refactor)
44
44
  end
45
45
  end
46
46
  end
@@ -31,8 +31,8 @@ module RuboCop
31
31
 
32
32
  processed_source.comments.each do |comment|
33
33
  next unless comment.text.match?(/(.|\?)\s{2}/) # https://rubular.com/r/8o3SiDrQMJSzuU
34
- add_offense(comment, location: comment.loc.expression, message: MSG, severity: :refactor) do |corrector|
35
- corrector.replace(comment.loc.expression, comment.text.gsub('. ', '. ').gsub('? ', '? '))
34
+ add_offense(comment, location: comment, message: MSG, severity: :refactor) do |corrector|
35
+ corrector.replace(comment, comment.text.gsub('. ', '. ').gsub('? ', '? '))
36
36
  end
37
37
  end
38
38
  end
@@ -49,9 +49,9 @@ module RuboCop
49
49
  processed_source.comments.each do |comment|
50
50
  next unless comment.inline? && invalid_copyright_comment?(comment) # headers aren't in blocks
51
51
 
52
- add_offense(comment, location: comment.loc.expression, message: MSG, severity: :refactor) do |corrector|
52
+ add_offense(comment, location: comment, message: MSG, severity: :refactor) do |corrector|
53
53
  correct_comment = "# Copyright:: #{copyright_date_range(comment)}, #{copyright_holder(comment)}"
54
- corrector.replace(comment.loc.expression, correct_comment)
54
+ corrector.replace(comment, correct_comment)
55
55
  end
56
56
  end
57
57
  end
@@ -41,7 +41,7 @@ module RuboCop
41
41
  processed_source.comments.each do |comment|
42
42
  next unless comment.inline? && # headers aren't in blocks
43
43
  /# (?:Copyright\W*).*YOUR_(NAME|COMPANY_NAME)/.match?(comment.text)
44
- add_offense(comment.loc.expression, message: MSG, severity: :refactor)
44
+ add_offense(comment, message: MSG, severity: :refactor)
45
45
  end
46
46
  end
47
47
  end
@@ -44,34 +44,27 @@ module RuboCop
44
44
  extend AutoCorrector
45
45
 
46
46
  MSG = 'Properly format header comments'
47
+ VERBOSE_COMMENT_REGEX = /^#\s*([A-Za-z]+)\s?(?:Name|File)?(?:::)?\s(.*)/.freeze
48
+ CHEF_LIKE_COMMENT_REGEX = /^#\s*(Author|Cookbook|Library|Attribute|Copyright|Recipe|Resource|Definition|License)\s+/.freeze
47
49
 
48
50
  def on_new_investigation
49
51
  return unless processed_source.ast
50
52
 
51
53
  processed_source.comments.each do |comment|
52
54
  next if comment.loc.first_line > 10 # avoid false positives when we were checking further down the file
53
- next unless comment.inline? && invalid_comment?(comment) # headers aren't in blocks
55
+ next unless comment.inline? && CHEF_LIKE_COMMENT_REGEX.match?(comment.text) # headers aren't in blocks
54
56
 
55
- add_offense(comment.loc.expression, message: MSG, severity: :refactor) do |corrector|
57
+ add_offense(comment, message: MSG, severity: :refactor) do |corrector|
56
58
  # Extract the type and the actual value. Strip out "Name" or "File"
57
59
  # 'Cookbook Name' should be 'Cookbook'. Also skip a :: if present
58
60
  # https://rubular.com/r/Do9fpLWXlCmvdJ
59
- match = /^#\s*([A-Za-z]+)\s?(?:Name|File)?(?:::)?\s(.*)/.match(comment.text)
61
+ match = VERBOSE_COMMENT_REGEX.match(comment.text)
60
62
  comment_type, value = match.captures
61
63
  correct_comment = "# #{comment_type}:: #{value}"
62
- corrector.replace(comment.loc.expression, correct_comment)
64
+ corrector.replace(comment, correct_comment)
63
65
  end
64
66
  end
65
67
  end
66
-
67
- private
68
-
69
- def invalid_comment?(comment)
70
- comment_types = %w(Author Cookbook Library Attribute Copyright Recipe Resource Definition License)
71
- comment_types.any? do |comment_type|
72
- /^#\s*#{comment_type}\s+/.match(comment.text)
73
- end
74
- end
75
68
  end
76
69
  end
77
70
  end
@@ -63,14 +63,14 @@ module RuboCop
63
63
 
64
64
  def on_send(node)
65
65
  resource_mode?(node) do |mode_int|
66
- add_offense(mode_int.loc.expression, message: MSG, severity: :refactor) do |corrector|
66
+ add_offense(mode_int, message: MSG, severity: :refactor) do |corrector|
67
67
  # If it was an octal literal, make sure we write out the right number.
68
68
  replacement_base = octal?(mode_int) ? 8 : 10
69
69
  replacement_mode = mode_int.children.first.to_s(replacement_base)
70
70
 
71
71
  # we build our own escaped string instead of using .inspect because that way
72
72
  # we can use single quotes instead of the double quotes that .inspect adds
73
- corrector.replace(mode_int.loc.expression, "\'#{replacement_mode}\'")
73
+ corrector.replace(mode_int, "\'#{replacement_mode}\'")
74
74
  end
75
75
  end
76
76
  end
@@ -47,8 +47,8 @@ module RuboCop
47
47
 
48
48
  def on_send(node)
49
49
  immediate_notify?(node) do |timing|
50
- add_offense(timing.loc.expression, message: MSG, severity: :refactor) do |corrector|
51
- corrector.replace(timing.loc.expression, ':immediately')
50
+ add_offense(timing, message: MSG, severity: :refactor) do |corrector|
51
+ corrector.replace(timing, ':immediately')
52
52
  end
53
53
  end
54
54
  end
@@ -47,8 +47,8 @@ module RuboCop
47
47
  # avoid chefspec: expect(chef_run).to include_recipe('foo')
48
48
  return if node.parent&.send_type?
49
49
 
50
- add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
51
- corrector.replace(node.loc.expression, "include_recipe #{recipe.source}")
50
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
51
+ corrector.replace(node, "include_recipe #{recipe.source}")
52
52
  end
53
53
  end
54
54
  end
@@ -56,8 +56,8 @@ module RuboCop
56
56
  return if code.descendants.first.send_type? &&
57
57
  code.descendants.first.negation_method?
58
58
 
59
- add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
60
- corrector.replace(code.loc.expression, code.source.gsub(/^!/, ''))
59
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
60
+ corrector.replace(code, code.source.gsub(/^!/, ''))
61
61
  corrector.replace(only_if.source_range, 'not_if')
62
62
  end
63
63
  end
@@ -57,9 +57,9 @@ module RuboCop
57
57
  def on_block(node)
58
58
  supports_depends_array?(node) do |array, type|
59
59
  return unless array.values.count < 3
60
- add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
60
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
61
61
  corrected_value = array.values.map { |x| "#{type} '#{x.source}'" }
62
- corrector.replace(node.loc.expression, corrected_value.join("\n"))
62
+ corrector.replace(node, corrected_value.join("\n"))
63
63
  end
64
64
  end
65
65
  end
@@ -65,7 +65,7 @@ module RuboCop
65
65
  def add_offense_to_i_if_present(node)
66
66
  node = node.parent if parent_method_equals?(node, :to_i)
67
67
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
68
- corrector.replace(node.loc.expression, "node['platform_version'].to_i")
68
+ corrector.replace(node, "node['platform_version'].to_i")
69
69
  end
70
70
  end
71
71
 
@@ -41,8 +41,8 @@ module RuboCop
41
41
 
42
42
  def on_send(node)
43
43
  trueclass_falseclass_property?(node) do |types|
44
- add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
45
- corrector.replace(types.loc.expression, '[true, false]')
44
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
45
+ corrector.replace(types, '[true, false]')
46
46
  end
47
47
  end
48
48
  end
@@ -58,9 +58,9 @@ module RuboCop
58
58
  def on_send(node)
59
59
  os_equals?(node) do |operator, val|
60
60
  return unless UNNECESSARY_OS_VALUES.include?(val.value)
61
- add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
61
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
62
62
  corrected_string = (operator == :!= ? '!' : '') + "platform_family?('#{sanitized_platform(val.value)}')"
63
- corrector.replace(node.loc.expression, corrected_string)
63
+ corrector.replace(node, corrected_string)
64
64
  end
65
65
  end
66
66
 
@@ -68,7 +68,7 @@ module RuboCop
68
68
  return unless UNNECESSARY_OS_VALUES.include?(val.value)
69
69
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
70
70
  corrected_string = "platform_family?('#{sanitized_platform(val.value)}')"
71
- corrector.replace(node.loc.expression, corrected_string)
71
+ corrector.replace(node, corrected_string)
72
72
  end
73
73
  end
74
74
 
@@ -79,7 +79,7 @@ module RuboCop
79
79
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
80
80
  platforms = val.values.map { |x| x.str_type? ? "'#{sanitized_platform(x.value)}'" : x.source }
81
81
  corrected_string = "platform_family?(#{platforms.join(', ')})"
82
- corrector.replace(node.loc.expression, corrected_string)
82
+ corrector.replace(node, corrected_string)
83
83
  end
84
84
  end
85
85
  end
@@ -56,7 +56,7 @@ module RuboCop
56
56
  def on_case(node)
57
57
  platform_case?(node) do |node_, type|
58
58
  return unless node&.when_branches&.count == 1
59
- add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
59
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
60
60
  # we have at least one supermarket cookbook with an entirely empty platform case statement
61
61
  # we can't actually fix that so let's do nothing here.
62
62
  unless empty_case_statement?(node)
@@ -66,7 +66,7 @@ module RuboCop
66
66
  # while multi-line statements should just have the case and when bits replace with `if platform?('ubuntu')`
67
67
  if !node.else? && !node.when_branches.first.body.multiline?
68
68
  new_source = "#{node.when_branches.first.body.source} if #{type.value}?(#{condition_string})"
69
- corrector.replace(node.loc.expression, new_source)
69
+ corrector.replace(node, new_source)
70
70
  else
71
71
  # find the range from the beginning of the case to the end of the node['platform'] or node['platform_family']
72
72
  case_range = node.loc.keyword.join(node_.loc.expression.end)