rubocop 1.54.1 → 1.64.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (297) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +5 -4
  4. data/assets/output.css.erb +159 -0
  5. data/assets/output.html.erb +1 -160
  6. data/config/default.yml +155 -26
  7. data/config/obsoletion.yml +5 -0
  8. data/lib/rubocop/cached_data.rb +11 -3
  9. data/lib/rubocop/cli/command/auto_generate_config.rb +22 -8
  10. data/lib/rubocop/cli/command/lsp.rb +2 -2
  11. data/lib/rubocop/cli/command/show_docs_url.rb +2 -2
  12. data/lib/rubocop/cli.rb +11 -2
  13. data/lib/rubocop/config.rb +36 -12
  14. data/lib/rubocop/config_finder.rb +14 -4
  15. data/lib/rubocop/config_loader.rb +0 -1
  16. data/lib/rubocop/config_obsoletion/parameter_rule.rb +9 -1
  17. data/lib/rubocop/config_obsoletion.rb +11 -8
  18. data/lib/rubocop/config_validator.rb +14 -7
  19. data/lib/rubocop/cop/autocorrect_logic.rb +9 -2
  20. data/lib/rubocop/cop/base.rb +64 -17
  21. data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -0
  22. data/lib/rubocop/cop/bundler/duplicated_group.rb +127 -0
  23. data/lib/rubocop/cop/bundler/gem_comment.rb +2 -2
  24. data/lib/rubocop/cop/bundler/gem_version.rb +3 -5
  25. data/lib/rubocop/cop/bundler/ordered_gems.rb +9 -1
  26. data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +4 -8
  27. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +5 -13
  28. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +7 -4
  29. data/lib/rubocop/cop/documentation.rb +16 -6
  30. data/lib/rubocop/cop/exclude_limit.rb +1 -1
  31. data/lib/rubocop/cop/force.rb +12 -0
  32. data/lib/rubocop/cop/gemspec/dependency_version.rb +3 -5
  33. data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +2 -2
  34. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +9 -1
  35. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +5 -1
  36. data/lib/rubocop/cop/generator/require_file_injector.rb +1 -1
  37. data/lib/rubocop/cop/internal_affairs/example_description.rb +46 -24
  38. data/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +8 -6
  39. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +19 -20
  40. data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +53 -0
  41. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +123 -29
  42. data/lib/rubocop/cop/internal_affairs/redundant_expect_offense_arguments.rb +34 -0
  43. data/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb +11 -2
  44. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -0
  45. data/lib/rubocop/cop/internal_affairs.rb +2 -0
  46. data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
  47. data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
  48. data/lib/rubocop/cop/layout/dot_position.rb +1 -5
  49. data/lib/rubocop/cop/layout/empty_comment.rb +3 -1
  50. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +42 -9
  51. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +14 -7
  52. data/lib/rubocop/cop/layout/end_alignment.rb +15 -3
  53. data/lib/rubocop/cop/layout/extra_spacing.rb +4 -10
  54. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +24 -7
  55. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
  56. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
  57. data/lib/rubocop/cop/layout/heredoc_indentation.rb +4 -1
  58. data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
  59. data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
  60. data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +17 -9
  61. data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -1
  62. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +18 -3
  63. data/lib/rubocop/cop/layout/redundant_line_break.rb +29 -6
  64. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +4 -4
  65. data/lib/rubocop/cop/layout/single_line_block_chain.rb +5 -0
  66. data/lib/rubocop/cop/layout/space_after_not.rb +1 -1
  67. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +2 -2
  68. data/lib/rubocop/cop/layout/space_around_operators.rb +50 -20
  69. data/lib/rubocop/cop/layout/space_before_block_braces.rb +19 -10
  70. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +1 -1
  71. data/lib/rubocop/cop/layout/space_inside_parens.rb +1 -1
  72. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +3 -4
  73. data/lib/rubocop/cop/layout/trailing_empty_lines.rb +5 -0
  74. data/lib/rubocop/cop/lint/assignment_in_condition.rb +6 -6
  75. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +2 -2
  76. data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +1 -1
  77. data/lib/rubocop/cop/lint/debugger.rb +38 -3
  78. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
  79. data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -1
  80. data/lib/rubocop/cop/lint/empty_block.rb +1 -1
  81. data/lib/rubocop/cop/lint/empty_conditional_body.rb +2 -2
  82. data/lib/rubocop/cop/lint/erb_new_arguments.rb +24 -17
  83. data/lib/rubocop/cop/lint/float_comparison.rb +10 -0
  84. data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +2 -1
  85. data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +56 -0
  86. data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +85 -0
  87. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  88. data/lib/rubocop/cop/lint/mixed_case_range.rb +10 -5
  89. data/lib/rubocop/cop/lint/next_without_accumulator.rb +6 -21
  90. data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +10 -7
  91. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +3 -5
  92. data/lib/rubocop/cop/lint/number_conversion.rb +9 -4
  93. data/lib/rubocop/cop/lint/redundant_require_statement.rb +4 -0
  94. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +72 -8
  95. data/lib/rubocop/cop/lint/redundant_with_index.rb +6 -2
  96. data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
  97. data/lib/rubocop/cop/lint/rescue_type.rb +1 -3
  98. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +14 -8
  99. data/lib/rubocop/cop/lint/script_permission.rb +3 -3
  100. data/lib/rubocop/cop/lint/self_assignment.rb +38 -0
  101. data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
  102. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +7 -1
  103. data/lib/rubocop/cop/lint/struct_new_override.rb +12 -12
  104. data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
  105. data/lib/rubocop/cop/lint/symbol_conversion.rb +7 -2
  106. data/lib/rubocop/cop/lint/syntax.rb +6 -3
  107. data/lib/rubocop/cop/lint/to_enum_arguments.rb +12 -5
  108. data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -1
  109. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +2 -2
  110. data/lib/rubocop/cop/lint/unreachable_code.rb +4 -2
  111. data/lib/rubocop/cop/lint/unreachable_loop.rb +8 -2
  112. data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -2
  113. data/lib/rubocop/cop/lint/useless_assignment.rb +38 -12
  114. data/lib/rubocop/cop/lint/useless_times.rb +2 -2
  115. data/lib/rubocop/cop/lint/void.rb +48 -12
  116. data/lib/rubocop/cop/metrics/abc_size.rb +3 -3
  117. data/lib/rubocop/cop/metrics/block_length.rb +1 -1
  118. data/lib/rubocop/cop/metrics/class_length.rb +8 -3
  119. data/lib/rubocop/cop/metrics/method_length.rb +1 -1
  120. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +7 -7
  121. data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
  122. data/lib/rubocop/cop/mixin/code_length.rb +12 -1
  123. data/lib/rubocop/cop/mixin/comments_help.rb +16 -12
  124. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -0
  125. data/lib/rubocop/cop/mixin/def_node.rb +1 -1
  126. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +23 -13
  127. data/lib/rubocop/cop/mixin/method_complexity.rb +15 -6
  128. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +4 -3
  129. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +6 -8
  130. data/lib/rubocop/cop/mixin/safe_assignment.rb +1 -1
  131. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
  132. data/lib/rubocop/cop/mixin/string_help.rb +4 -2
  133. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  134. data/lib/rubocop/cop/naming/block_forwarding.rb +34 -7
  135. data/lib/rubocop/cop/naming/constant_name.rb +1 -2
  136. data/lib/rubocop/cop/naming/file_name.rb +3 -3
  137. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +3 -1
  138. data/lib/rubocop/cop/naming/inclusive_language.rb +1 -2
  139. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
  140. data/lib/rubocop/cop/naming/predicate_name.rb +2 -2
  141. data/lib/rubocop/cop/registry.rb +1 -1
  142. data/lib/rubocop/cop/security/compound_hash.rb +2 -2
  143. data/lib/rubocop/cop/security/open.rb +2 -2
  144. data/lib/rubocop/cop/style/access_modifier_declarations.rb +52 -2
  145. data/lib/rubocop/cop/style/accessor_grouping.rb +1 -1
  146. data/lib/rubocop/cop/style/alias.rb +10 -8
  147. data/lib/rubocop/cop/style/arguments_forwarding.rb +414 -63
  148. data/lib/rubocop/cop/style/array_first_last.rb +64 -0
  149. data/lib/rubocop/cop/style/array_intersect.rb +13 -5
  150. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +21 -14
  151. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +2 -2
  152. data/lib/rubocop/cop/style/block_delimiters.rb +2 -1
  153. data/lib/rubocop/cop/style/case_like_if.rb +5 -5
  154. data/lib/rubocop/cop/style/class_check.rb +1 -0
  155. data/lib/rubocop/cop/style/class_equality_comparison.rb +7 -0
  156. data/lib/rubocop/cop/style/class_vars.rb +3 -3
  157. data/lib/rubocop/cop/style/collection_compact.rb +21 -11
  158. data/lib/rubocop/cop/style/collection_methods.rb +2 -0
  159. data/lib/rubocop/cop/style/combinable_loops.rb +17 -9
  160. data/lib/rubocop/cop/style/commented_keyword.rb +5 -2
  161. data/lib/rubocop/cop/style/concat_array_literals.rb +2 -1
  162. data/lib/rubocop/cop/style/conditional_assignment.rb +7 -8
  163. data/lib/rubocop/cop/style/copyright.rb +31 -21
  164. data/lib/rubocop/cop/style/date_time.rb +5 -4
  165. data/lib/rubocop/cop/style/documentation.rb +24 -24
  166. data/lib/rubocop/cop/style/documentation_method.rb +20 -0
  167. data/lib/rubocop/cop/style/each_for_simple_loop.rb +7 -7
  168. data/lib/rubocop/cop/style/each_with_object.rb +2 -2
  169. data/lib/rubocop/cop/style/empty_case_condition.rb +6 -1
  170. data/lib/rubocop/cop/style/empty_literal.rb +1 -1
  171. data/lib/rubocop/cop/style/eval_with_location.rb +6 -15
  172. data/lib/rubocop/cop/style/exact_regexp_match.rb +4 -2
  173. data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -2
  174. data/lib/rubocop/cop/style/for.rb +3 -1
  175. data/lib/rubocop/cop/style/format_string.rb +33 -12
  176. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -1
  177. data/lib/rubocop/cop/style/guard_clause.rb +26 -0
  178. data/lib/rubocop/cop/style/hash_conversion.rb +10 -0
  179. data/lib/rubocop/cop/style/hash_each_methods.rb +105 -11
  180. data/lib/rubocop/cop/style/hash_except.rb +2 -1
  181. data/lib/rubocop/cop/style/hash_syntax.rb +24 -2
  182. data/lib/rubocop/cop/style/identical_conditional_branches.rb +28 -3
  183. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +5 -3
  184. data/lib/rubocop/cop/style/inverse_methods.rb +14 -13
  185. data/lib/rubocop/cop/style/invertible_unless_condition.rb +44 -2
  186. data/lib/rubocop/cop/style/lambda_call.rb +5 -0
  187. data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +8 -10
  188. data/lib/rubocop/cop/style/map_into_array.rb +175 -0
  189. data/lib/rubocop/cop/style/map_to_hash.rb +18 -8
  190. data/lib/rubocop/cop/style/map_to_set.rb +1 -1
  191. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +22 -6
  192. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -4
  193. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +20 -0
  194. data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
  195. data/lib/rubocop/cop/style/missing_respond_to_missing.rb +2 -2
  196. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  197. data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
  198. data/lib/rubocop/cop/style/multiline_method_signature.rb +10 -1
  199. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +6 -4
  200. data/lib/rubocop/cop/style/nested_ternary_operator.rb +3 -11
  201. data/lib/rubocop/cop/style/next.rb +1 -1
  202. data/lib/rubocop/cop/style/nil_comparison.rb +2 -0
  203. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
  204. data/lib/rubocop/cop/style/numeric_predicate.rb +10 -2
  205. data/lib/rubocop/cop/style/object_then.rb +5 -3
  206. data/lib/rubocop/cop/style/one_line_conditional.rb +1 -1
  207. data/lib/rubocop/cop/style/open_struct_use.rb +1 -1
  208. data/lib/rubocop/cop/style/operator_method_call.rb +8 -2
  209. data/lib/rubocop/cop/style/parallel_assignment.rb +3 -5
  210. data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -0
  211. data/lib/rubocop/cop/style/raise_args.rb +4 -1
  212. data/lib/rubocop/cop/style/redundant_argument.rb +33 -4
  213. data/lib/rubocop/cop/style/redundant_assignment.rb +10 -2
  214. data/lib/rubocop/cop/style/redundant_begin.rb +9 -1
  215. data/lib/rubocop/cop/style/redundant_conditional.rb +1 -9
  216. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +5 -4
  217. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +93 -5
  218. data/lib/rubocop/cop/style/redundant_each.rb +7 -4
  219. data/lib/rubocop/cop/style/redundant_exception.rb +32 -12
  220. data/lib/rubocop/cop/style/redundant_fetch_block.rb +3 -3
  221. data/lib/rubocop/cop/style/redundant_filter_chain.rb +23 -6
  222. data/lib/rubocop/cop/style/redundant_line_continuation.rb +19 -2
  223. data/lib/rubocop/cop/style/redundant_parentheses.rb +71 -22
  224. data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
  225. data/lib/rubocop/cop/style/redundant_return.rb +14 -3
  226. data/lib/rubocop/cop/style/redundant_self.rb +17 -2
  227. data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +5 -0
  228. data/lib/rubocop/cop/style/redundant_sort.rb +9 -8
  229. data/lib/rubocop/cop/style/redundant_sort_by.rb +2 -2
  230. data/lib/rubocop/cop/style/redundant_string_escape.rb +1 -1
  231. data/lib/rubocop/cop/style/require_order.rb +1 -1
  232. data/lib/rubocop/cop/style/return_nil.rb +6 -2
  233. data/lib/rubocop/cop/style/return_nil_in_predicate_method_definition.rb +23 -9
  234. data/lib/rubocop/cop/style/sample.rb +3 -4
  235. data/lib/rubocop/cop/style/select_by_regexp.rb +7 -6
  236. data/lib/rubocop/cop/style/self_assignment.rb +1 -1
  237. data/lib/rubocop/cop/style/semicolon.rb +8 -3
  238. data/lib/rubocop/cop/style/send.rb +4 -4
  239. data/lib/rubocop/cop/style/send_with_literal_method_name.rb +90 -0
  240. data/lib/rubocop/cop/style/single_argument_dig.rb +7 -3
  241. data/lib/rubocop/cop/style/single_line_do_end_block.rb +67 -0
  242. data/lib/rubocop/cop/style/slicing_with_range.rb +76 -10
  243. data/lib/rubocop/cop/style/sole_nested_conditional.rb +3 -1
  244. data/lib/rubocop/cop/style/special_global_vars.rb +1 -2
  245. data/lib/rubocop/cop/style/string_chars.rb +1 -0
  246. data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +30 -5
  247. data/lib/rubocop/cop/style/strip.rb +7 -4
  248. data/lib/rubocop/cop/style/super_arguments.rb +156 -0
  249. data/lib/rubocop/cop/style/super_with_args_parentheses.rb +35 -0
  250. data/lib/rubocop/cop/style/symbol_array.rb +35 -15
  251. data/lib/rubocop/cop/style/symbol_proc.rb +68 -5
  252. data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -1
  253. data/lib/rubocop/cop/style/unpack_first.rb +11 -14
  254. data/lib/rubocop/cop/style/yoda_expression.rb +8 -7
  255. data/lib/rubocop/cop/team.rb +5 -0
  256. data/lib/rubocop/cop/utils/regexp_ranges.rb +27 -14
  257. data/lib/rubocop/cop/variable_force/assignment.rb +1 -3
  258. data/lib/rubocop/cops_documentation_generator.rb +15 -3
  259. data/lib/rubocop/directive_comment.rb +10 -8
  260. data/lib/rubocop/ext/regexp_node.rb +9 -4
  261. data/lib/rubocop/file_finder.rb +4 -7
  262. data/lib/rubocop/formatter/clang_style_formatter.rb +3 -7
  263. data/lib/rubocop/formatter/disabled_config_formatter.rb +23 -8
  264. data/lib/rubocop/formatter/formatter_set.rb +7 -1
  265. data/lib/rubocop/formatter/html_formatter.rb +35 -14
  266. data/lib/rubocop/formatter/json_formatter.rb +0 -1
  267. data/lib/rubocop/formatter/junit_formatter.rb +1 -1
  268. data/lib/rubocop/formatter/offense_count_formatter.rb +12 -2
  269. data/lib/rubocop/formatter/tap_formatter.rb +3 -7
  270. data/lib/rubocop/formatter.rb +1 -1
  271. data/lib/rubocop/lockfile.rb +56 -7
  272. data/lib/rubocop/lsp/logger.rb +1 -1
  273. data/lib/rubocop/lsp/routes.rb +43 -31
  274. data/lib/rubocop/lsp/runtime.rb +21 -4
  275. data/lib/rubocop/lsp/server.rb +13 -6
  276. data/lib/rubocop/lsp/severity.rb +1 -1
  277. data/lib/rubocop/lsp.rb +36 -0
  278. data/lib/rubocop/magic_comment.rb +13 -11
  279. data/lib/rubocop/options.rb +14 -11
  280. data/lib/rubocop/path_util.rb +6 -2
  281. data/lib/rubocop/rake_task.rb +1 -1
  282. data/lib/rubocop/result_cache.rb +4 -1
  283. data/lib/rubocop/rspec/cop_helper.rb +8 -2
  284. data/lib/rubocop/rspec/expect_offense.rb +16 -8
  285. data/lib/rubocop/rspec/shared_contexts.rb +55 -19
  286. data/lib/rubocop/rspec/support.rb +2 -0
  287. data/lib/rubocop/runner.rb +19 -6
  288. data/lib/rubocop/server/cache.rb +1 -1
  289. data/lib/rubocop/server/client_command/exec.rb +1 -2
  290. data/lib/rubocop/server/server_command/exec.rb +0 -1
  291. data/lib/rubocop/string_interpreter.rb +3 -3
  292. data/lib/rubocop/target_finder.rb +91 -81
  293. data/lib/rubocop/target_ruby.rb +82 -76
  294. data/lib/rubocop/version.rb +19 -4
  295. data/lib/rubocop.rb +9 -0
  296. metadata +29 -16
  297. /data/lib/rubocop/formatter/{git_hub_actions_formatter.rb → github_actions_formatter.rb} +0 -0
@@ -25,8 +25,7 @@ module RuboCop
25
25
  include RangeHelp
26
26
  extend AutoCorrector
27
27
 
28
- NO_SPACE_MSG = 'Space inside string interpolation detected.'
29
- SPACE_MSG = 'Missing space inside string interpolation detected.'
28
+ MSG = '%<command>s space inside string interpolation.'
30
29
 
31
30
  def on_interpolation(begin_node)
32
31
  return if begin_node.multiline?
@@ -36,9 +35,9 @@ module RuboCop
36
35
  return if empty_brackets?(left, right, tokens: tokens)
37
36
 
38
37
  if style == :no_space
39
- no_space_offenses(begin_node, left, right, NO_SPACE_MSG)
38
+ no_space_offenses(begin_node, left, right, MSG)
40
39
  else
41
- space_offenses(begin_node, left, right, SPACE_MSG)
40
+ space_offenses(begin_node, left, right, MSG)
42
41
  end
43
42
  end
44
43
 
@@ -51,6 +51,7 @@ module RuboCop
51
51
  # there could be good reasons why it needs to end with a certain
52
52
  # number of newlines.
53
53
  return if ends_in_end?(processed_source)
54
+ return if end_with_percent_blank_string?(processed_source)
54
55
 
55
56
  whitespace_at_end = buffer.source[/\s*\Z/]
56
57
  blank_lines = whitespace_at_end.count("\n") - 1
@@ -86,6 +87,10 @@ module RuboCop
86
87
  extra&.strip&.start_with?('__END__')
87
88
  end
88
89
 
90
+ def end_with_percent_blank_string?(processed_source)
91
+ processed_source.buffer.source.end_with?("%\n\n")
92
+ end
93
+
89
94
  def message(wanted_blank_lines, blank_lines)
90
95
  case blank_lines
91
96
  when -1
@@ -17,24 +17,24 @@ module RuboCop
17
17
  #
18
18
  # @example
19
19
  # # bad
20
- # if some_var = true
20
+ # if some_var = value
21
21
  # do_something
22
22
  # end
23
23
  #
24
24
  # # good
25
- # if some_var == true
25
+ # if some_var == value
26
26
  # do_something
27
27
  # end
28
28
  #
29
29
  # @example AllowSafeAssignment: true (default)
30
30
  # # good
31
- # if (some_var = true)
31
+ # if (some_var = value)
32
32
  # do_something
33
33
  # end
34
34
  #
35
35
  # @example AllowSafeAssignment: false
36
36
  # # bad
37
- # if (some_var = true)
37
+ # if (some_var = value)
38
38
  # do_something
39
39
  # end
40
40
  #
@@ -50,7 +50,7 @@ module RuboCop
50
50
  MSG_WITHOUT_SAFE_ASSIGNMENT_ALLOWED =
51
51
  'Use `==` if you meant to do a comparison or move the assignment ' \
52
52
  'up out of the condition.'
53
- ASGN_TYPES = [:begin, *AST::Node::EQUALS_ASSIGNMENTS, :send].freeze
53
+ ASGN_TYPES = [:begin, *AST::Node::EQUALS_ASSIGNMENTS, :send, :csend].freeze
54
54
 
55
55
  def on_if(node)
56
56
  return if node.condition.block_type?
@@ -88,7 +88,7 @@ module RuboCop
88
88
  end
89
89
 
90
90
  def skip_children?(asgn_node)
91
- (asgn_node.send_type? && !asgn_node.assignment_method?) ||
91
+ (asgn_node.call_type? && !asgn_node.assignment_method?) ||
92
92
  empty_condition?(asgn_node) ||
93
93
  (safe_assignment_allowed? && safe_assignment?(asgn_node))
94
94
  end
@@ -6,10 +6,10 @@ module RuboCop
6
6
  # Checks for places where binary operator has identical operands.
7
7
  #
8
8
  # It covers arithmetic operators: `-`, `/`, `%`;
9
- # comparison operators: `==`, `===`, `=~`, `>`, `>=`, `<`, `<=`;
9
+ # comparison operators: `==`, `===`, `=~`, `>`, `>=`, `<`, ``<=``;
10
10
  # bitwise operators: `|`, `^`, `&`;
11
11
  # boolean operators: `&&`, `||`
12
- # and "spaceship" operator - `<=>`.
12
+ # and "spaceship" operator - ``<=>``.
13
13
  #
14
14
  # Simple arithmetic operations are allowed by this cop: `+`, `*`, `**`, `<<` and `>>`.
15
15
  # Although these can be rewritten in a different way, it should not be necessary to
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Lint
6
- # Checks for overwriting an exception with an exception result by use `rescue =>`.
6
+ # Checks for overwriting an exception with an exception result by use ``rescue =>``.
7
7
  #
8
8
  # You intended to write as `rescue StandardError`.
9
9
  # However, you have written `rescue => StandardError`.
@@ -29,6 +29,11 @@ module RuboCop
29
29
  # MyDebugger.debug_this
30
30
  # ----
31
31
  #
32
+ # Some gems also ship files that will start a debugging session when required,
33
+ # for example `require 'debug/start'` from `ruby/debug`. These requires can
34
+ # be configured through `DebuggerRequires`. It has the same structure as
35
+ # `DebuggerMethods`, which you can read about above.
36
+ #
32
37
  # @example
33
38
  #
34
39
  # # bad (ok during development)
@@ -64,13 +69,20 @@ module RuboCop
64
69
  # def some_method
65
70
  # my_debugger
66
71
  # end
72
+ #
73
+ # @example DebuggerRequires: [my_debugger/start]
74
+ #
75
+ # # bad (ok during development)
76
+ #
77
+ # require 'my_debugger/start'
67
78
  class Debugger < Base
68
79
  MSG = 'Remove debugger entry point `%<source>s`.'
80
+ BLOCK_TYPES = %i[block numblock kwbegin].freeze
69
81
 
70
82
  def on_send(node)
71
- return if !debugger_method?(node) || assumed_usage_context?(node)
83
+ return if assumed_usage_context?(node)
72
84
 
73
- add_offense(node)
85
+ add_offense(node) if debugger_method?(node) || debugger_require?(node)
74
86
  end
75
87
 
76
88
  private
@@ -86,17 +98,34 @@ module RuboCop
86
98
  end
87
99
  end
88
100
 
101
+ def debugger_requires
102
+ @debugger_requires ||= begin
103
+ config = cop_config.fetch('DebuggerRequires', [])
104
+ config.is_a?(Array) ? config : config.values.flatten
105
+ end
106
+ end
107
+
89
108
  def debugger_method?(send_node)
90
109
  return false if send_node.parent&.send_type? && send_node.parent.receiver == send_node
91
110
 
92
111
  debugger_methods.include?(chained_method_name(send_node))
93
112
  end
94
113
 
114
+ def debugger_require?(send_node)
115
+ return false unless send_node.method?(:require) && send_node.arguments.one?
116
+ return false unless (argument = send_node.first_argument).str_type?
117
+
118
+ debugger_requires.include?(argument.value)
119
+ end
120
+
95
121
  def assumed_usage_context?(node)
96
122
  # Basically, debugger methods are not used as a method argument without arguments.
97
123
  return false unless node.arguments.empty? && node.each_ancestor(:send, :csend).any?
124
+ return true if assumed_argument?(node)
98
125
 
99
- node.each_ancestor.none?(&:lambda_or_proc?)
126
+ node.each_ancestor.none? do |ancestor|
127
+ BLOCK_TYPES.include?(ancestor.type) || ancestor.lambda_or_proc?
128
+ end
100
129
  end
101
130
 
102
131
  def chained_method_name(send_node)
@@ -109,6 +138,12 @@ module RuboCop
109
138
  end
110
139
  chained_method_name
111
140
  end
141
+
142
+ def assumed_argument?(node)
143
+ parent = node.parent
144
+
145
+ parent.call_type? || parent.literal? || parent.pair_type?
146
+ end
112
147
  end
113
148
  end
114
149
  end
@@ -52,7 +52,7 @@ module RuboCop
52
52
  # @!method deprecated_class_method?(node)
53
53
  def_node_matcher :deprecated_class_method?, <<~PATTERN
54
54
  {
55
- (send (const {cbase nil?} {:ENV}) {:clone :dup :freeze})
55
+ (send (const {cbase nil?} :ENV) {:clone :dup :freeze})
56
56
  (send (const {cbase nil?} {:File :Dir}) :exists? _)
57
57
  (send (const {cbase nil?} :Socket) {:gethostbyaddr :gethostbyname} ...)
58
58
  (send nil? :attr _ boolean)
@@ -253,7 +253,7 @@ module RuboCop
253
253
  # Assume that if a method definition is inside any block call which
254
254
  # we can't identify, it could be a DSL
255
255
  node.each_ancestor(:block).any? do |ancestor|
256
- ancestor.method_name != :class_eval && !ancestor.class_constructor?
256
+ !ancestor.method?(:class_eval) && !ancestor.class_constructor?
257
257
  end
258
258
  end
259
259
 
@@ -5,7 +5,7 @@ module RuboCop
5
5
  module Lint
6
6
  # Checks for blocks without a body.
7
7
  # Such empty blocks are typically an oversight or we should provide a comment
8
- # be clearer what we're aiming for.
8
+ # to clarify what we're aiming for.
9
9
  #
10
10
  # Empty lambdas and procs are ignored by default.
11
11
  #
@@ -104,7 +104,7 @@ module RuboCop
104
104
  def correct_other_branches(corrector, node)
105
105
  return unless require_other_branches_correction?(node)
106
106
 
107
- if node.else_branch&.if_type?
107
+ if node.else_branch&.if_type? && !node.else_branch.modifier_form?
108
108
  # Replace an orphaned `elsif` with `if`
109
109
  corrector.replace(node.else_branch.loc.keyword, 'if')
110
110
  else
@@ -146,7 +146,7 @@ module RuboCop
146
146
  node.source_range.with(end_pos: node.condition.source_range.end_pos)
147
147
  elsif all_branches_body_missing?(node)
148
148
  if_node = node.ancestors.detect(&:if?)
149
- node.source_range.with(end_pos: if_node.loc.end.end_pos)
149
+ node.source_range.join(if_node.loc.end.end)
150
150
  else
151
151
  node.source_range
152
152
  end
@@ -65,17 +65,15 @@ module RuboCop
65
65
 
66
66
  minimum_target_ruby_version 2.6
67
67
 
68
- MESSAGES = [
69
- 'Passing safe_level with the 2nd argument of `ERB.new` is ' \
70
- 'deprecated. Do not use it, and specify other arguments as ' \
71
- 'keyword arguments.',
72
- 'Passing trim_mode with the 3rd argument of `ERB.new` is ' \
73
- 'deprecated. Use keyword argument like ' \
74
- '`ERB.new(str, trim_mode: %<arg_value>s)` instead.',
75
- 'Passing eoutvar with the 4th argument of `ERB.new` is ' \
76
- 'deprecated. Use keyword argument like ' \
77
- '`ERB.new(str, eoutvar: %<arg_value>s)` instead.'
78
- ].freeze
68
+ MESSAGE_SAFE_LEVEL = 'Passing safe_level with the 2nd argument of `ERB.new` is ' \
69
+ 'deprecated. Do not use it, and specify other arguments as ' \
70
+ 'keyword arguments.'
71
+ MESSAGE_TRIM_MODE = 'Passing trim_mode with the 3rd argument of `ERB.new` is ' \
72
+ 'deprecated. Use keyword argument like ' \
73
+ '`ERB.new(str, trim_mode: %<arg_value>s)` instead.'
74
+ MESSAGE_EOUTVAR = 'Passing eoutvar with the 4th argument of `ERB.new` is ' \
75
+ 'deprecated. Use keyword argument like ' \
76
+ '`ERB.new(str, eoutvar: %<arg_value>s)` instead.'
79
77
 
80
78
  RESTRICT_ON_SEND = %i[new].freeze
81
79
 
@@ -92,10 +90,8 @@ module RuboCop
92
90
  arguments[1..3].each_with_index do |argument, i|
93
91
  next if !argument || argument.hash_type?
94
92
 
95
- message = format(MESSAGES[i], arg_value: argument.source)
96
-
97
93
  add_offense(
98
- argument.source_range, message: message
94
+ argument.source_range, message: message(i, argument.source)
99
95
  ) do |corrector|
100
96
  autocorrect(corrector, node)
101
97
  end
@@ -105,8 +101,19 @@ module RuboCop
105
101
 
106
102
  private
107
103
 
104
+ def message(positional_argument_index, arg_value)
105
+ case positional_argument_index
106
+ when 0
107
+ MESSAGE_SAFE_LEVEL
108
+ when 1
109
+ format(MESSAGE_TRIM_MODE, arg_value: arg_value)
110
+ when 2
111
+ format(MESSAGE_EOUTVAR, arg_value: arg_value)
112
+ end
113
+ end
114
+
108
115
  def autocorrect(corrector, node)
109
- str_arg = node.arguments[0].source
116
+ str_arg = node.first_argument.source
110
117
 
111
118
  kwargs = build_kwargs(node)
112
119
  overridden_kwargs = override_by_legacy_args(kwargs, node)
@@ -121,11 +128,11 @@ module RuboCop
121
128
  end
122
129
 
123
130
  def build_kwargs(node)
124
- return [nil, nil] unless node.arguments.last.hash_type?
131
+ return [nil, nil] unless node.last_argument.hash_type?
125
132
 
126
133
  trim_mode_arg, eoutvar_arg = nil
127
134
 
128
- node.arguments.last.pairs.each do |pair|
135
+ node.last_argument.pairs.each do |pair|
129
136
  case pair.key.source
130
137
  when 'trim_mode'
131
138
  trim_mode_arg = "trim_mode: #{pair.value.source}"
@@ -18,6 +18,10 @@ module RuboCop
18
18
  # # good - using BigDecimal
19
19
  # x.to_d == 0.1.to_d
20
20
  #
21
+ # # good - comparing against zero
22
+ # x == 0.0
23
+ # x != 0.0
24
+ #
21
25
  # # good
22
26
  # (x - 0.1).abs < Float::EPSILON
23
27
  #
@@ -39,6 +43,8 @@ module RuboCop
39
43
 
40
44
  def on_send(node)
41
45
  lhs, _method, rhs = *node
46
+ return if literal_zero?(lhs) || literal_zero?(rhs)
47
+
42
48
  add_offense(node) if float?(lhs) || float?(rhs)
43
49
  end
44
50
 
@@ -59,6 +65,10 @@ module RuboCop
59
65
  end
60
66
  end
61
67
 
68
+ def literal_zero?(node)
69
+ node&.numeric_type? && node.value.zero?
70
+ end
71
+
62
72
  # rubocop:disable Metrics/PerceivedComplexity
63
73
  def check_send(node)
64
74
  if node.arithmetic_operation?
@@ -35,12 +35,13 @@ module RuboCop
35
35
 
36
36
  # @!method id_as_hash_key?(node)
37
37
  def_node_matcher :id_as_hash_key?, <<~PATTERN
38
- (send _ {:key? :has_key? :fetch :[] :[]=} (send _ :object_id) ...)
38
+ (call _ {:key? :has_key? :fetch :[] :[]=} (send _ :object_id) ...)
39
39
  PATTERN
40
40
 
41
41
  def on_send(node)
42
42
  add_offense(node) if id_as_hash_key?(node)
43
43
  end
44
+ alias on_csend on_send
44
45
  end
45
46
  end
46
47
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Lint
6
+ # Emulates the following Ruby warning in Ruby 3.3.
7
+ #
8
+ # [source,ruby]
9
+ # ----
10
+ # $ ruby -e '0.times { it }'
11
+ # -e:1: warning: `it` calls without arguments will refer to the first block param in Ruby 3.4;
12
+ # use it() or self.it
13
+ # ----
14
+ #
15
+ # `it` calls without arguments will refer to the first block param in Ruby 3.4.
16
+ # So use `it()` or `self.it` to ensure compatibility.
17
+ #
18
+ # @example
19
+ #
20
+ # # bad
21
+ # do_something { it }
22
+ #
23
+ # # good
24
+ # do_something { it() }
25
+ # do_something { self.it }
26
+ #
27
+ class ItWithoutArgumentsInBlock < Base
28
+ include NodePattern::Macros
29
+
30
+ MSG = '`it` calls without arguments will refer to the first block param in Ruby 3.4; ' \
31
+ 'use `it()` or `self.it`.'
32
+
33
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
34
+ return unless (body = node.body)
35
+ return unless node.arguments.empty_and_without_delimiters?
36
+
37
+ if body.send_type? && deprecated_it_method?(body)
38
+ add_offense(body)
39
+ else
40
+ body.each_descendant(:send).each do |send_node|
41
+ next unless deprecated_it_method?(send_node)
42
+
43
+ add_offense(send_node)
44
+ end
45
+ end
46
+ end
47
+
48
+ def deprecated_it_method?(node)
49
+ return false unless node.method?(:it)
50
+
51
+ !node.receiver && node.arguments.empty? && !node.parenthesized? && !node.block_literal?
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Lint
6
+ # Checks for literal assignments in the conditions of `if`, `while`, and `until`.
7
+ # It emulates the following Ruby warning:
8
+ #
9
+ # [source,console]
10
+ # ----
11
+ # $ ruby -we 'if x = true; end'
12
+ # -e:1: warning: found `= literal' in conditional, should be ==
13
+ # ----
14
+ #
15
+ # As a lint cop, it cannot be determined if `==` is appropriate as intended,
16
+ # therefore this cop does not provide autocorrection.
17
+ #
18
+ # @example
19
+ #
20
+ # # bad
21
+ # if x = 42
22
+ # do_something
23
+ # end
24
+ #
25
+ # # good
26
+ # if x == 42
27
+ # do_something
28
+ # end
29
+ #
30
+ # # good
31
+ # if x = y
32
+ # do_something
33
+ # end
34
+ #
35
+ class LiteralAssignmentInCondition < Base
36
+ MSG = "Don't use literal assignment `= %<literal>s` in conditional, " \
37
+ 'should be `==` or non-literal operand.'
38
+
39
+ def on_if(node)
40
+ traverse_node(node.condition) do |asgn_node|
41
+ next unless asgn_node.loc.operator
42
+
43
+ rhs = asgn_node.to_a.last
44
+ next if !all_literals?(rhs) || parallel_assignment_with_splat_operator?(rhs)
45
+
46
+ range = offense_range(asgn_node, rhs)
47
+
48
+ add_offense(range, message: format(MSG, literal: rhs.source))
49
+ end
50
+ end
51
+ alias on_while on_if
52
+ alias on_until on_if
53
+
54
+ private
55
+
56
+ def traverse_node(node, &block)
57
+ yield node if AST::Node::EQUALS_ASSIGNMENTS.include?(node.type)
58
+
59
+ node.each_child_node { |child| traverse_node(child, &block) }
60
+ end
61
+
62
+ def all_literals?(node)
63
+ case node.type
64
+ when :dstr, :xstr
65
+ false
66
+ when :array
67
+ node.values.all? { |value| all_literals?(value) }
68
+ when :hash
69
+ (node.values + node.keys).all? { |item| all_literals?(item) }
70
+ else
71
+ node.respond_to?(:literal?) && node.literal?
72
+ end
73
+ end
74
+
75
+ def parallel_assignment_with_splat_operator?(node)
76
+ node.array_type? && node.values.first&.splat_type?
77
+ end
78
+
79
+ def offense_range(asgn_node, rhs)
80
+ asgn_node.loc.operator.join(rhs.source_range.end)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -34,7 +34,7 @@ module RuboCop
34
34
  # interpolation should not be removed if the expanded value
35
35
  # contains a space character.
36
36
  expanded_value = autocorrected_value(final_node)
37
- return if in_array_percent_literal?(begin_node) && /\s/.match?(expanded_value)
37
+ return if in_array_percent_literal?(begin_node) && /\s|\A\z/.match?(expanded_value)
38
38
 
39
39
  add_offense(final_node) do |corrector|
40
40
  return if final_node.dstr_type? # nested, fixed in next iteration
@@ -47,8 +47,10 @@ module RuboCop
47
47
 
48
48
  def on_regexp(node)
49
49
  each_unsafe_regexp_range(node) do |loc|
50
+ next unless (replacement = regexp_range(loc.source))
51
+
50
52
  add_offense(loc) do |corrector|
51
- corrector.replace(loc, rewrite_regexp_range(loc.source))
53
+ corrector.replace(loc, replacement)
52
54
  end
53
55
  end
54
56
  end
@@ -95,14 +97,17 @@ module RuboCop
95
97
 
96
98
  def skip_range?(range_start, range_end)
97
99
  [range_start, range_end].any? do |bound|
98
- bound.type == :escape
100
+ bound.type != :literal
99
101
  end
100
102
  end
101
103
 
102
- def rewrite_regexp_range(source)
104
+ def regexp_range(source)
103
105
  open, close = source.split('-')
104
- first = [open, range_for(open).end]
105
- second = [range_for(close).begin, close]
106
+ return unless (open_range = range_for(open))
107
+ return unless (close_range = range_for(close))
108
+
109
+ first = [open, open_range.end]
110
+ second = [close_range.begin, close]
106
111
  "#{first.uniq.join('-')}#{second.uniq.join('-')}"
107
112
  end
108
113
  end
@@ -34,35 +34,20 @@ module RuboCop
34
34
  add_offense(void_next) if void_next
35
35
  end
36
36
  end
37
-
38
- def on_numblock(node)
39
- on_numblock_body_of_reduce(node) do |body|
40
- void_next = body.each_node(:next).find do |n|
41
- n.children.empty? && parent_numblock_node(n) == node
42
- end
43
-
44
- add_offense(void_next) if void_next
45
- end
46
- end
37
+ alias on_numblock on_block
47
38
 
48
39
  private
49
40
 
50
41
  # @!method on_block_body_of_reduce(node)
51
42
  def_node_matcher :on_block_body_of_reduce, <<~PATTERN
52
- (block (send _recv {:reduce :inject} !sym) _blockargs $(begin ...))
53
- PATTERN
54
-
55
- # @!method on_numblock_body_of_reduce(node)
56
- def_node_matcher :on_numblock_body_of_reduce, <<~PATTERN
57
- (numblock (send _recv {:reduce :inject} !sym) _argscount $(begin ...))
43
+ {
44
+ (block (call _recv {:reduce :inject} !sym) _blockargs $(begin ...))
45
+ (numblock (call _recv {:reduce :inject} !sym) _argscount $(begin ...))
46
+ }
58
47
  PATTERN
59
48
 
60
49
  def parent_block_node(node)
61
- node.each_ancestor(:block).first
62
- end
63
-
64
- def parent_numblock_node(node)
65
- node.each_ancestor(:numblock).first
50
+ node.each_ancestor(:block, :numblock).first
66
51
  end
67
52
  end
68
53
  end
@@ -43,7 +43,6 @@ module RuboCop
43
43
  #
44
44
  class NonAtomicFileOperation < Base
45
45
  extend AutoCorrector
46
- include Alignment
47
46
 
48
47
  MSG_REMOVE_FILE_EXIST_CHECK = 'Remove unnecessary existence check ' \
49
48
  '`%<receiver>s.%<method_name>s`.'
@@ -51,18 +50,20 @@ module RuboCop
51
50
  MAKE_FORCE_METHODS = %i[makedirs mkdir_p mkpath].freeze
52
51
  MAKE_METHODS = %i[mkdir].freeze
53
52
  REMOVE_FORCE_METHODS = %i[rm_f rm_rf].freeze
54
- REMOVE_METHODS = %i[remove remove_dir remove_entry remove_entry_secure
55
- delete unlink remove_file rm rmdir safe_unlink].freeze
56
- RESTRICT_ON_SEND = (MAKE_METHODS + MAKE_FORCE_METHODS + REMOVE_METHODS +
57
- REMOVE_FORCE_METHODS).freeze
53
+ REMOVE_METHODS = %i[remove delete unlink remove_file rm rmdir safe_unlink].freeze
54
+ RECURSIVE_REMOVE_METHODS = %i[remove_dir remove_entry remove_entry_secure].freeze
55
+ RESTRICT_ON_SEND = (
56
+ MAKE_METHODS + MAKE_FORCE_METHODS + REMOVE_METHODS + RECURSIVE_REMOVE_METHODS +
57
+ REMOVE_FORCE_METHODS
58
+ ).freeze
58
59
 
59
60
  # @!method send_exist_node(node)
60
- def_node_search :send_exist_node, <<-PATTERN
61
+ def_node_search :send_exist_node, <<~PATTERN
61
62
  $(send (const nil? {:FileTest :File :Dir :Shell}) {:exist? :exists?} ...)
62
63
  PATTERN
63
64
 
64
65
  # @!method receiver_and_method_name(node)
65
- def_node_matcher :receiver_and_method_name, <<-PATTERN
66
+ def_node_matcher :receiver_and_method_name, <<~PATTERN
66
67
  (send (const nil? $_) $_ ...)
67
68
  PATTERN
68
69
 
@@ -140,6 +141,8 @@ module RuboCop
140
141
  'mkdir_p'
141
142
  elsif REMOVE_METHODS.include?(node.method_name)
142
143
  'rm_f'
144
+ elsif RECURSIVE_REMOVE_METHODS.include?(node.method_name)
145
+ 'rm_rf'
143
146
  else
144
147
  node.method_name
145
148
  end
@@ -94,7 +94,7 @@ module RuboCop
94
94
  parent_node = node.parent
95
95
 
96
96
  add_offense(parent_node) do |corrector|
97
- if parent_node.arguments.last&.block_pass_type?
97
+ if parent_node.last_argument&.block_pass_type?
98
98
  correct_block_pass(corrector, parent_node)
99
99
  else
100
100
  correct_block(corrector, parent_node)
@@ -116,7 +116,7 @@ module RuboCop
116
116
 
117
117
  def correct_block_pass(corrector, node)
118
118
  if unsorted_dir_glob_pass?(node)
119
- block_arg = node.arguments.last
119
+ block_arg = node.last_argument
120
120
 
121
121
  corrector.remove(last_arg_range(node))
122
122
  corrector.insert_after(node, ".sort.each(#{block_arg.source})")
@@ -130,9 +130,7 @@ module RuboCop
130
130
  # @return [Parser::Source::Range]
131
131
  #
132
132
  def last_arg_range(node)
133
- node.arguments.last.source_range.with(
134
- begin_pos: node.arguments[-2].source_range.end_pos
135
- )
133
+ node.last_argument.source_range.join(node.arguments[-2].source_range.end)
136
134
  end
137
135
 
138
136
  def unsorted_dir_loop?(node)