rubocop 1.59.0 → 1.68.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (352) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +69 -70
  4. data/assets/output.css.erb +159 -0
  5. data/assets/output.html.erb +1 -160
  6. data/config/default.yml +165 -24
  7. data/config/internal_affairs.yml +11 -0
  8. data/exe/rubocop +4 -3
  9. data/lib/rubocop/cached_data.rb +21 -5
  10. data/lib/rubocop/cli/command/auto_generate_config.rb +18 -10
  11. data/lib/rubocop/cli/command/execute_runner.rb +1 -1
  12. data/lib/rubocop/cli/command/lsp.rb +4 -4
  13. data/lib/rubocop/cli/command/show_docs_url.rb +2 -2
  14. data/lib/rubocop/cli/command/version.rb +2 -2
  15. data/lib/rubocop/cli.rb +10 -1
  16. data/lib/rubocop/comment_config.rb +1 -1
  17. data/lib/rubocop/config.rb +41 -13
  18. data/lib/rubocop/config_finder.rb +12 -2
  19. data/lib/rubocop/config_loader.rb +15 -10
  20. data/lib/rubocop/config_loader_resolver.rb +13 -8
  21. data/lib/rubocop/config_obsoletion.rb +1 -1
  22. data/lib/rubocop/config_validator.rb +17 -9
  23. data/lib/rubocop/cop/autocorrect_logic.rb +28 -3
  24. data/lib/rubocop/cop/base.rb +73 -18
  25. data/lib/rubocop/cop/bundler/gem_version.rb +4 -5
  26. data/lib/rubocop/cop/cop.rb +30 -4
  27. data/lib/rubocop/cop/correctors/alignment_corrector.rb +1 -12
  28. data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +4 -8
  29. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +5 -13
  30. data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -0
  31. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
  32. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +10 -0
  33. data/lib/rubocop/cop/documentation.rb +32 -5
  34. data/lib/rubocop/cop/exclude_limit.rb +1 -1
  35. data/lib/rubocop/cop/force.rb +12 -0
  36. data/lib/rubocop/cop/gemspec/add_runtime_dependency.rb +38 -0
  37. data/lib/rubocop/cop/gemspec/dependency_version.rb +3 -5
  38. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
  39. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +5 -1
  40. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +3 -3
  41. data/lib/rubocop/cop/internal_affairs/cop_description.rb +0 -4
  42. data/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb +2 -1
  43. data/lib/rubocop/cop/internal_affairs/example_description.rb +6 -5
  44. data/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +8 -6
  45. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +123 -29
  46. data/lib/rubocop/cop/internal_affairs/redundant_expect_offense_arguments.rb +34 -0
  47. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +6 -21
  48. data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +8 -1
  49. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +11 -1
  50. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +0 -5
  51. data/lib/rubocop/cop/internal_affairs.rb +17 -0
  52. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +5 -1
  53. data/lib/rubocop/cop/layout/assignment_indentation.rb +3 -2
  54. data/lib/rubocop/cop/layout/block_alignment.rb +30 -12
  55. data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
  56. data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
  57. data/lib/rubocop/cop/layout/condition_position.rb +0 -4
  58. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  59. data/lib/rubocop/cop/layout/empty_comment.rb +3 -1
  60. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  61. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +14 -7
  62. data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +1 -1
  63. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
  64. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +8 -3
  65. data/lib/rubocop/cop/layout/end_alignment.rb +8 -2
  66. data/lib/rubocop/cop/layout/first_argument_indentation.rb +2 -2
  67. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +18 -4
  68. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +8 -0
  69. data/lib/rubocop/cop/layout/heredoc_indentation.rb +1 -1
  70. data/lib/rubocop/cop/layout/indentation_width.rb +5 -6
  71. data/lib/rubocop/cop/layout/leading_comment_space.rb +56 -1
  72. data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +1 -1
  73. data/lib/rubocop/cop/layout/line_length.rb +20 -20
  74. data/lib/rubocop/cop/layout/redundant_line_break.rb +14 -2
  75. data/lib/rubocop/cop/layout/space_around_operators.rb +3 -0
  76. data/lib/rubocop/cop/layout/space_before_block_braces.rb +19 -10
  77. data/lib/rubocop/cop/layout/space_before_brackets.rb +5 -5
  78. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +4 -0
  79. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +1 -1
  80. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +3 -4
  81. data/lib/rubocop/cop/legacy/corrector.rb +12 -2
  82. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +0 -2
  83. data/lib/rubocop/cop/lint/ambiguous_operator.rb +0 -2
  84. data/lib/rubocop/cop/lint/ambiguous_range.rb +4 -1
  85. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +0 -2
  86. data/lib/rubocop/cop/lint/assignment_in_condition.rb +2 -2
  87. data/lib/rubocop/cop/lint/big_decimal_new.rb +4 -7
  88. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -3
  89. data/lib/rubocop/cop/lint/circular_argument_reference.rb +0 -13
  90. data/lib/rubocop/cop/lint/debugger.rb +27 -6
  91. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
  92. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +0 -10
  93. data/lib/rubocop/cop/lint/duplicate_branch.rb +39 -4
  94. data/lib/rubocop/cop/lint/duplicate_case_condition.rb +1 -5
  95. data/lib/rubocop/cop/lint/duplicate_hash_key.rb +0 -4
  96. data/lib/rubocop/cop/lint/duplicate_methods.rb +0 -10
  97. data/lib/rubocop/cop/lint/duplicate_set_element.rb +74 -0
  98. data/lib/rubocop/cop/lint/each_with_object_argument.rb +0 -4
  99. data/lib/rubocop/cop/lint/else_layout.rb +0 -2
  100. data/lib/rubocop/cop/lint/empty_conditional_body.rb +29 -8
  101. data/lib/rubocop/cop/lint/empty_ensure.rb +1 -11
  102. data/lib/rubocop/cop/lint/empty_interpolation.rb +0 -4
  103. data/lib/rubocop/cop/lint/empty_when.rb +1 -3
  104. data/lib/rubocop/cop/lint/ensure_return.rb +1 -9
  105. data/lib/rubocop/cop/lint/erb_new_arguments.rb +21 -14
  106. data/lib/rubocop/cop/lint/float_comparison.rb +1 -1
  107. data/lib/rubocop/cop/lint/float_out_of_range.rb +0 -4
  108. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +0 -10
  109. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +23 -12
  110. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +0 -7
  111. data/lib/rubocop/cop/lint/interpolation_check.rb +0 -4
  112. data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +5 -14
  113. data/lib/rubocop/cop/lint/literal_as_condition.rb +1 -1
  114. data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +13 -6
  115. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +25 -6
  116. data/lib/rubocop/cop/lint/loop.rb +6 -12
  117. data/lib/rubocop/cop/lint/mixed_case_range.rb +9 -4
  118. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -7
  119. data/lib/rubocop/cop/lint/next_without_accumulator.rb +0 -4
  120. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +0 -5
  121. data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +7 -0
  122. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +1 -1
  123. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +5 -6
  124. data/lib/rubocop/cop/lint/percent_string_array.rb +0 -4
  125. data/lib/rubocop/cop/lint/percent_symbol_array.rb +0 -4
  126. data/lib/rubocop/cop/lint/rand_one.rb +0 -4
  127. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +3 -1
  128. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +14 -9
  129. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
  130. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +0 -4
  131. data/lib/rubocop/cop/lint/redundant_with_index.rb +4 -0
  132. data/lib/rubocop/cop/lint/require_parentheses.rb +0 -4
  133. data/lib/rubocop/cop/lint/rescue_exception.rb +0 -4
  134. data/lib/rubocop/cop/lint/rescue_type.rb +1 -3
  135. data/lib/rubocop/cop/lint/return_in_void_context.rb +0 -2
  136. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +9 -4
  137. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +107 -41
  138. data/lib/rubocop/cop/lint/script_permission.rb +3 -3
  139. data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
  140. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +6 -10
  141. data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
  142. data/lib/rubocop/cop/lint/syntax.rb +6 -3
  143. data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -3
  144. data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +88 -0
  145. data/lib/rubocop/cop/lint/unified_integer.rb +0 -4
  146. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -0
  147. data/lib/rubocop/cop/lint/unreachable_code.rb +4 -7
  148. data/lib/rubocop/cop/lint/unreachable_loop.rb +8 -2
  149. data/lib/rubocop/cop/lint/uri_regexp.rb +25 -7
  150. data/lib/rubocop/cop/lint/useless_assignment.rb +19 -16
  151. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +0 -4
  152. data/lib/rubocop/cop/lint/useless_numeric_operation.rb +77 -0
  153. data/lib/rubocop/cop/lint/useless_setter_call.rb +0 -4
  154. data/lib/rubocop/cop/lint/useless_times.rb +1 -1
  155. data/lib/rubocop/cop/lint/void.rb +41 -9
  156. data/lib/rubocop/cop/metrics/block_length.rb +6 -5
  157. data/lib/rubocop/cop/metrics/block_nesting.rb +19 -7
  158. data/lib/rubocop/cop/metrics/class_length.rb +6 -5
  159. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +4 -1
  160. data/lib/rubocop/cop/metrics/method_length.rb +6 -5
  161. data/lib/rubocop/cop/metrics/module_length.rb +6 -5
  162. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +5 -5
  163. data/lib/rubocop/cop/mixin/alignment.rb +5 -1
  164. data/lib/rubocop/cop/mixin/allowed_methods.rb +7 -1
  165. data/lib/rubocop/cop/mixin/allowed_pattern.rb +15 -3
  166. data/lib/rubocop/cop/mixin/annotation_comment.rb +0 -2
  167. data/lib/rubocop/cop/mixin/check_line_breakable.rb +10 -0
  168. data/lib/rubocop/cop/mixin/code_length.rb +12 -1
  169. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -0
  170. data/lib/rubocop/cop/mixin/configurable_max.rb +5 -1
  171. data/lib/rubocop/cop/mixin/endless_method_rewriter.rb +24 -0
  172. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +22 -10
  173. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +9 -2
  174. data/lib/rubocop/cop/mixin/line_length_help.rb +7 -2
  175. data/lib/rubocop/cop/mixin/method_complexity.rb +15 -6
  176. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
  177. data/lib/rubocop/cop/mixin/percent_array.rb +1 -1
  178. data/lib/rubocop/cop/mixin/rescue_node.rb +4 -0
  179. data/lib/rubocop/cop/mixin/safe_assignment.rb +1 -1
  180. data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -2
  181. data/lib/rubocop/cop/mixin/string_literals_help.rb +12 -0
  182. data/lib/rubocop/cop/naming/accessor_method_name.rb +5 -0
  183. data/lib/rubocop/cop/naming/block_forwarding.rb +33 -6
  184. data/lib/rubocop/cop/naming/file_name.rb +2 -2
  185. data/lib/rubocop/cop/naming/inclusive_language.rb +13 -5
  186. data/lib/rubocop/cop/naming/predicate_name.rb +55 -29
  187. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -1
  188. data/lib/rubocop/cop/offense.rb +4 -5
  189. data/lib/rubocop/cop/registry.rb +1 -1
  190. data/lib/rubocop/cop/security/compound_hash.rb +2 -2
  191. data/lib/rubocop/cop/security/open.rb +2 -2
  192. data/lib/rubocop/cop/style/access_modifier_declarations.rb +62 -2
  193. data/lib/rubocop/cop/style/accessor_grouping.rb +10 -2
  194. data/lib/rubocop/cop/style/alias.rb +2 -1
  195. data/lib/rubocop/cop/style/ambiguous_endless_method_definition.rb +79 -0
  196. data/lib/rubocop/cop/style/arguments_forwarding.rb +141 -24
  197. data/lib/rubocop/cop/style/bitwise_predicate.rb +100 -0
  198. data/lib/rubocop/cop/style/block_delimiters.rb +31 -3
  199. data/lib/rubocop/cop/style/case_like_if.rb +1 -1
  200. data/lib/rubocop/cop/style/class_vars.rb +3 -3
  201. data/lib/rubocop/cop/style/collection_compact.rb +19 -10
  202. data/lib/rubocop/cop/style/combinable_defined.rb +115 -0
  203. data/lib/rubocop/cop/style/combinable_loops.rb +7 -0
  204. data/lib/rubocop/cop/style/commented_keyword.rb +12 -3
  205. data/lib/rubocop/cop/style/conditional_assignment.rb +7 -8
  206. data/lib/rubocop/cop/style/copyright.rb +31 -21
  207. data/lib/rubocop/cop/style/data_inheritance.rb +1 -1
  208. data/lib/rubocop/cop/style/def_with_parentheses.rb +0 -2
  209. data/lib/rubocop/cop/style/documentation.rb +24 -24
  210. data/lib/rubocop/cop/style/documentation_method.rb +20 -0
  211. data/lib/rubocop/cop/style/each_for_simple_loop.rb +7 -8
  212. data/lib/rubocop/cop/style/empty_else.rb +6 -5
  213. data/lib/rubocop/cop/style/empty_heredoc.rb +1 -14
  214. data/lib/rubocop/cop/style/empty_literal.rb +31 -22
  215. data/lib/rubocop/cop/style/endless_method.rb +1 -14
  216. data/lib/rubocop/cop/style/eval_with_location.rb +16 -24
  217. data/lib/rubocop/cop/style/exact_regexp_match.rb +2 -1
  218. data/lib/rubocop/cop/style/file_read.rb +2 -5
  219. data/lib/rubocop/cop/style/file_write.rb +2 -5
  220. data/lib/rubocop/cop/style/for.rb +2 -0
  221. data/lib/rubocop/cop/style/format_string.rb +9 -9
  222. data/lib/rubocop/cop/style/format_string_token.rb +2 -2
  223. data/lib/rubocop/cop/style/global_std_stream.rb +7 -1
  224. data/lib/rubocop/cop/style/guard_clause.rb +17 -2
  225. data/lib/rubocop/cop/style/hash_each_methods.rb +35 -8
  226. data/lib/rubocop/cop/style/hash_except.rb +8 -5
  227. data/lib/rubocop/cop/style/hash_syntax.rb +26 -4
  228. data/lib/rubocop/cop/style/identical_conditional_branches.rb +5 -2
  229. data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
  230. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +5 -4
  231. data/lib/rubocop/cop/style/if_with_semicolon.rb +49 -6
  232. data/lib/rubocop/cop/style/in_pattern_then.rb +6 -2
  233. data/lib/rubocop/cop/style/inverse_methods.rb +8 -8
  234. data/lib/rubocop/cop/style/invertible_unless_condition.rb +46 -4
  235. data/lib/rubocop/cop/style/keyword_arguments_merging.rb +67 -0
  236. data/lib/rubocop/cop/style/lambda.rb +1 -1
  237. data/lib/rubocop/cop/style/magic_comment_format.rb +1 -1
  238. data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +81 -50
  239. data/lib/rubocop/cop/style/map_into_array.rb +233 -0
  240. data/lib/rubocop/cop/style/map_to_hash.rb +10 -6
  241. data/lib/rubocop/cop/style/map_to_set.rb +1 -1
  242. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +29 -11
  243. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -4
  244. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -2
  245. data/lib/rubocop/cop/style/missing_else.rb +0 -4
  246. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  247. data/lib/rubocop/cop/style/multiline_method_signature.rb +10 -1
  248. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +5 -3
  249. data/lib/rubocop/cop/style/multiline_when_then.rb +0 -4
  250. data/lib/rubocop/cop/style/multiple_comparison.rb +28 -47
  251. data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
  252. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
  253. data/lib/rubocop/cop/style/nil_comparison.rb +2 -0
  254. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
  255. data/lib/rubocop/cop/style/numeric_predicate.rb +12 -4
  256. data/lib/rubocop/cop/style/object_then.rb +5 -3
  257. data/lib/rubocop/cop/style/one_line_conditional.rb +6 -2
  258. data/lib/rubocop/cop/style/operator_method_call.rb +25 -6
  259. data/lib/rubocop/cop/style/parallel_assignment.rb +8 -9
  260. data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -0
  261. data/lib/rubocop/cop/style/quoted_symbols.rb +1 -3
  262. data/lib/rubocop/cop/style/raise_args.rb +4 -1
  263. data/lib/rubocop/cop/style/redundant_argument.rb +25 -2
  264. data/lib/rubocop/cop/style/redundant_assignment.rb +10 -2
  265. data/lib/rubocop/cop/style/redundant_begin.rb +5 -1
  266. data/lib/rubocop/cop/style/redundant_condition.rb +4 -4
  267. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +5 -4
  268. data/lib/rubocop/cop/style/redundant_each.rb +7 -4
  269. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -1
  270. data/lib/rubocop/cop/style/redundant_filter_chain.rb +1 -1
  271. data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +46 -0
  272. data/lib/rubocop/cop/style/redundant_line_continuation.rb +40 -7
  273. data/lib/rubocop/cop/style/redundant_parentheses.rb +27 -13
  274. data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
  275. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +4 -1
  276. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -24
  277. data/lib/rubocop/cop/style/redundant_return.rb +6 -0
  278. data/lib/rubocop/cop/style/require_order.rb +2 -2
  279. data/lib/rubocop/cop/style/rescue_modifier.rb +13 -1
  280. data/lib/rubocop/cop/style/return_nil_in_predicate_method_definition.rb +54 -12
  281. data/lib/rubocop/cop/style/safe_navigation.rb +106 -52
  282. data/lib/rubocop/cop/style/safe_navigation_chain_length.rb +52 -0
  283. data/lib/rubocop/cop/style/sample.rb +1 -3
  284. data/lib/rubocop/cop/style/select_by_regexp.rb +9 -6
  285. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  286. data/lib/rubocop/cop/style/send.rb +4 -4
  287. data/lib/rubocop/cop/style/send_with_literal_method_name.rb +104 -0
  288. data/lib/rubocop/cop/style/slicing_with_range.rb +76 -10
  289. data/lib/rubocop/cop/style/sole_nested_conditional.rb +21 -2
  290. data/lib/rubocop/cop/style/special_global_vars.rb +1 -2
  291. data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
  292. data/lib/rubocop/cop/style/super_arguments.rb +174 -0
  293. data/lib/rubocop/cop/style/symbol_proc.rb +75 -5
  294. data/lib/rubocop/cop/style/ternary_parentheses.rb +26 -5
  295. data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -1
  296. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  297. data/lib/rubocop/cop/style/while_until_do.rb +0 -2
  298. data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
  299. data/lib/rubocop/cop/style/zero_length_predicate.rb +32 -24
  300. data/lib/rubocop/cop/team.rb +27 -3
  301. data/lib/rubocop/cop/util.rb +8 -2
  302. data/lib/rubocop/cop/utils/regexp_ranges.rb +1 -1
  303. data/lib/rubocop/cop/variable_force/assignment.rb +18 -3
  304. data/lib/rubocop/cop/variable_force/branch.rb +1 -1
  305. data/lib/rubocop/cop/variable_force/variable.rb +5 -1
  306. data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
  307. data/lib/rubocop/cop/variable_force.rb +13 -1
  308. data/lib/rubocop/cops_documentation_generator.rb +96 -43
  309. data/lib/rubocop/core_ext/string.rb +2 -6
  310. data/lib/rubocop/directive_comment.rb +10 -8
  311. data/lib/rubocop/ext/regexp_node.rb +18 -35
  312. data/lib/rubocop/ext/regexp_parser.rb +4 -21
  313. data/lib/rubocop/file_finder.rb +9 -4
  314. data/lib/rubocop/formatter/clang_style_formatter.rb +3 -7
  315. data/lib/rubocop/formatter/disabled_config_formatter.rb +24 -9
  316. data/lib/rubocop/formatter/formatter_set.rb +7 -1
  317. data/lib/rubocop/formatter/html_formatter.rb +32 -10
  318. data/lib/rubocop/formatter/json_formatter.rb +0 -1
  319. data/lib/rubocop/formatter/junit_formatter.rb +70 -23
  320. data/lib/rubocop/formatter/offense_count_formatter.rb +12 -2
  321. data/lib/rubocop/formatter/tap_formatter.rb +3 -7
  322. data/lib/rubocop/formatter.rb +1 -1
  323. data/lib/rubocop/lockfile.rb +58 -7
  324. data/lib/rubocop/lsp/logger.rb +1 -1
  325. data/lib/rubocop/lsp/routes.rb +12 -15
  326. data/lib/rubocop/lsp/runtime.rb +3 -1
  327. data/lib/rubocop/lsp/server.rb +6 -2
  328. data/lib/rubocop/lsp/severity.rb +1 -1
  329. data/lib/rubocop/lsp.rb +36 -0
  330. data/lib/rubocop/magic_comment.rb +1 -1
  331. data/lib/rubocop/options.rb +17 -12
  332. data/lib/rubocop/path_util.rb +6 -2
  333. data/lib/rubocop/rake_task.rb +1 -1
  334. data/lib/rubocop/remote_config.rb +5 -1
  335. data/lib/rubocop/result_cache.rb +2 -8
  336. data/lib/rubocop/rspec/cop_helper.rb +8 -2
  337. data/lib/rubocop/rspec/expect_offense.rb +17 -8
  338. data/lib/rubocop/rspec/shared_contexts.rb +75 -18
  339. data/lib/rubocop/rspec/support.rb +3 -0
  340. data/lib/rubocop/runner.rb +31 -9
  341. data/lib/rubocop/server/cache.rb +16 -2
  342. data/lib/rubocop/server/client_command/exec.rb +2 -3
  343. data/lib/rubocop/server/client_command/start.rb +1 -1
  344. data/lib/rubocop/server/core.rb +5 -0
  345. data/lib/rubocop/server/server_command/exec.rb +0 -1
  346. data/lib/rubocop/target_finder.rb +84 -78
  347. data/lib/rubocop/target_ruby.rb +87 -81
  348. data/lib/rubocop/version.rb +45 -9
  349. data/lib/rubocop/yaml_duplication_checker.rb +20 -26
  350. data/lib/rubocop.rb +21 -1
  351. metadata +33 -35
  352. /data/lib/rubocop/formatter/{git_hub_actions_formatter.rb → github_actions_formatter.rb} +0 -0
data/config/default.yml CHANGED
@@ -82,6 +82,8 @@ AllCops:
82
82
  StyleGuideBaseURL: https://rubystyle.guide
83
83
  # Documentation URLs will be constructed using the base URL.
84
84
  DocumentationBaseURL: https://docs.rubocop.org/rubocop
85
+ # Documentation URLs will end with this extension.
86
+ DocumentationExtension: .html
85
87
  # Extra details are not displayed in offense messages by default. Change
86
88
  # behavior by overriding ExtraDetails, or by giving the
87
89
  # `-E/--extra-details` option.
@@ -144,6 +146,12 @@ AllCops:
144
146
  # Ruby version is still unresolved, RuboCop will use the oldest officially
145
147
  # supported Ruby version (currently Ruby 2.7).
146
148
  TargetRubyVersion: ~
149
+ # You can specify the parser engine. There are two options available:
150
+ # - `parser_whitequark` ... https://github.com/whitequark/parser
151
+ # - `parser_prism` ... https://github.com/ruby/prism (`Prism::Translation::Parser`)
152
+ # By default, `parser` is used. For the `TargetRubyVersion` value, `parser` can be specified for versions `2.0` and above.
153
+ # `parser_prism` can be specified for versions `3.3` and above. `parser_prism` is faster but still considered experimental.
154
+ ParserEngine: parser_whitequark
147
155
  # Determines if a notification for extension libraries should be shown when
148
156
  # rubocop is run. Keys are the name of the extension, and values are an array
149
157
  # of gems in the Gemfile that the extension is suggested for, if not already
@@ -157,8 +165,14 @@ AllCops:
157
165
  rubocop-graphql: [graphql]
158
166
  rubocop-capybara: [capybara]
159
167
  rubocop-factory_bot: [factory_bot, factory_bot_rails]
168
+ rubocop-rspec_rails: [rspec-rails]
160
169
  # Enable/Disable checking the methods extended by Active Support.
161
170
  ActiveSupportExtensionsEnabled: false
171
+ # Future version of Ruby will freeze string literals by default.
172
+ # This allows to opt in early, for example when enabled through RUBYOPT.
173
+ # For now this will behave as if set to false but in future ruby versions
174
+ # (likely 4.0) it will be true by default.
175
+ StringLiteralsFrozenByDefault: ~
162
176
 
163
177
  #################### Bundler ###############################
164
178
 
@@ -255,6 +269,15 @@ Bundler/OrderedGems:
255
269
 
256
270
  #################### Gemspec ###############################
257
271
 
272
+ Gemspec/AddRuntimeDependency:
273
+ Description: 'Prefer `add_dependency` over `add_runtime_dependency`.'
274
+ StyleGuide: '#add_dependency_vs_add_runtime_dependency'
275
+ Reference: https://github.com/rubygems/rubygems/issues/7799#issuecomment-2192720316
276
+ Enabled: pending
277
+ VersionAdded: '1.65'
278
+ Include:
279
+ - '**/*.gemspec'
280
+
258
281
  Gemspec/DependencyVersion:
259
282
  Description: 'Requires or forbids specifying gem dependency versions.'
260
283
  Enabled: false
@@ -556,7 +579,9 @@ Layout/ElseAlignment:
556
579
  Layout/EmptyComment:
557
580
  Description: 'Checks empty comment.'
558
581
  Enabled: true
582
+ AutoCorrect: contextual
559
583
  VersionAdded: '0.53'
584
+ VersionChanged: '1.61'
560
585
  AllowBorderComment: true
561
586
  AllowMarginComment: true
562
587
 
@@ -836,6 +861,7 @@ Layout/FirstMethodArgumentLineBreak:
836
861
  Enabled: false
837
862
  VersionAdded: '0.49'
838
863
  AllowMultilineFinalElement: false
864
+ AllowedMethods: []
839
865
 
840
866
  Layout/FirstMethodParameterLineBreak:
841
867
  Description: >-
@@ -1011,6 +1037,8 @@ Layout/LeadingCommentSpace:
1011
1037
  VersionChanged: '0.73'
1012
1038
  AllowDoxygenCommentStyle: false
1013
1039
  AllowGemfileRubyComment: false
1040
+ AllowRBSInlineAnnotation: false
1041
+ AllowSteepAnnotation: false
1014
1042
 
1015
1043
  Layout/LeadingEmptyLines:
1016
1044
  Description: Check for unnecessary blank lines at the beginning of a file.
@@ -1649,7 +1677,7 @@ Lint/Debugger:
1649
1677
  Description: 'Check for debugger calls.'
1650
1678
  Enabled: true
1651
1679
  VersionAdded: '0.14'
1652
- VersionChanged: '1.46'
1680
+ VersionChanged: '1.63'
1653
1681
  DebuggerMethods:
1654
1682
  # Groups are available so that a specific group can be disabled in
1655
1683
  # a user's configuration, but are otherwise not significant.
@@ -1662,8 +1690,14 @@ Lint/Debugger:
1662
1690
  - Kernel.byebug
1663
1691
  - Kernel.remote_byebug
1664
1692
  Capybara:
1693
+ - page.save_and_open_page
1694
+ - page.save_and_open_screenshot
1695
+ - page.save_page
1696
+ - page.save_screenshot
1665
1697
  - save_and_open_page
1666
1698
  - save_and_open_screenshot
1699
+ - save_page
1700
+ - save_screenshot
1667
1701
  debug.rb:
1668
1702
  - binding.b
1669
1703
  - binding.break
@@ -1685,6 +1719,10 @@ Lint/Debugger:
1685
1719
  - jard
1686
1720
  WebConsole:
1687
1721
  - binding.console
1722
+ DebuggerRequires:
1723
+ debug.rb:
1724
+ - debug/open
1725
+ - debug/start
1688
1726
 
1689
1727
  Lint/DeprecatedClassMethods:
1690
1728
  Description: 'Check for deprecated class method calls.'
@@ -1748,6 +1786,7 @@ Lint/DuplicateBranch:
1748
1786
  VersionChanged: '1.7'
1749
1787
  IgnoreLiteralBranches: false
1750
1788
  IgnoreConstantBranches: false
1789
+ IgnoreDuplicateElseBranch: false
1751
1790
 
1752
1791
  Lint/DuplicateCaseCondition:
1753
1792
  Description: 'Do not repeat values in case conditionals.'
@@ -1797,6 +1836,11 @@ Lint/DuplicateRescueException:
1797
1836
  Enabled: true
1798
1837
  VersionAdded: '0.89'
1799
1838
 
1839
+ Lint/DuplicateSetElement:
1840
+ Description: 'Checks for duplicate elements in Set.'
1841
+ Enabled: pending
1842
+ VersionAdded: '1.67'
1843
+
1800
1844
  Lint/EachWithObjectArgument:
1801
1845
  Description: 'Check for immutable argument given to each_with_object.'
1802
1846
  Enabled: true
@@ -1825,16 +1869,18 @@ Lint/EmptyClass:
1825
1869
  Lint/EmptyConditionalBody:
1826
1870
  Description: 'Checks for the presence of `if`, `elsif` and `unless` branches without a body.'
1827
1871
  Enabled: true
1872
+ AutoCorrect: contextual
1828
1873
  SafeAutoCorrect: false
1829
1874
  AllowComments: true
1830
1875
  VersionAdded: '0.89'
1831
- VersionChanged: '1.34'
1876
+ VersionChanged: '1.61'
1832
1877
 
1833
1878
  Lint/EmptyEnsure:
1834
1879
  Description: 'Checks for empty ensure block.'
1835
1880
  Enabled: true
1881
+ AutoCorrect: contextual
1836
1882
  VersionAdded: '0.10'
1837
- VersionChanged: '0.48'
1883
+ VersionChanged: '1.61'
1838
1884
 
1839
1885
  Lint/EmptyExpression:
1840
1886
  Description: 'Checks for empty expressions.'
@@ -1856,8 +1902,9 @@ Lint/EmptyInPattern:
1856
1902
  Lint/EmptyInterpolation:
1857
1903
  Description: 'Checks for empty string interpolation.'
1858
1904
  Enabled: true
1905
+ AutoCorrect: contextual
1859
1906
  VersionAdded: '0.20'
1860
- VersionChanged: '0.45'
1907
+ VersionChanged: '1.61'
1861
1908
 
1862
1909
  Lint/EmptyWhen:
1863
1910
  Description: 'Checks for `when` branches with empty bodies.'
@@ -2289,9 +2336,9 @@ Lint/SafeNavigationChain:
2289
2336
 
2290
2337
  Lint/SafeNavigationConsistency:
2291
2338
  Description: >-
2292
- Check to make sure that if safe navigation is used for a method
2293
- call in an `&&` or `||` condition that safe navigation is used
2294
- for all method calls on that same object.
2339
+ Check to make sure that if safe navigation is used in an `&&` or `||` condition,
2340
+ consistent and appropriate safe navigation, without excess or deficiency,
2341
+ is used for all method calls on the same object.
2295
2342
  Enabled: true
2296
2343
  VersionAdded: '0.55'
2297
2344
  VersionChanged: '0.77'
@@ -2395,7 +2442,9 @@ Lint/TopLevelReturnWithArgument:
2395
2442
  Lint/TrailingCommaInAttributeDeclaration:
2396
2443
  Description: 'Checks for trailing commas in attribute declarations.'
2397
2444
  Enabled: true
2445
+ AutoCorrect: contextual
2398
2446
  VersionAdded: '0.90'
2447
+ VersionChanged: '1.61'
2399
2448
 
2400
2449
  Lint/TripleQuotes:
2401
2450
  Description: 'Checks for useless triple quote constructs.'
@@ -2408,6 +2457,11 @@ Lint/UnderscorePrefixedVariableName:
2408
2457
  VersionAdded: '0.21'
2409
2458
  AllowKeywordBlockArguments: false
2410
2459
 
2460
+ Lint/UnescapedBracketInRegexp:
2461
+ Description: 'Checks for unescaped literal `]` in Regexp.'
2462
+ Enabled: pending
2463
+ VersionAdded: '1.68'
2464
+
2411
2465
  Lint/UnexpectedBlockArity:
2412
2466
  Description: 'Looks for blocks that have fewer arguments that the calling method expects.'
2413
2467
  Enabled: pending
@@ -2455,8 +2509,9 @@ Lint/UnusedBlockArgument:
2455
2509
  Description: 'Checks for unused block arguments.'
2456
2510
  StyleGuide: '#underscore-unused-vars'
2457
2511
  Enabled: true
2512
+ AutoCorrect: contextual
2458
2513
  VersionAdded: '0.21'
2459
- VersionChanged: '0.22'
2514
+ VersionChanged: '1.61'
2460
2515
  IgnoreEmptyBlocks: true
2461
2516
  AllowUnusedKeywordArguments: false
2462
2517
 
@@ -2464,8 +2519,9 @@ Lint/UnusedMethodArgument:
2464
2519
  Description: 'Checks for unused method arguments.'
2465
2520
  StyleGuide: '#underscore-unused-vars'
2466
2521
  Enabled: true
2522
+ AutoCorrect: contextual
2467
2523
  VersionAdded: '0.21'
2468
- VersionChanged: '0.81'
2524
+ VersionChanged: '1.61'
2469
2525
  AllowUnusedKeywordArguments: false
2470
2526
  IgnoreEmptyMethods: true
2471
2527
  IgnoreNotImplementedMethods: true
@@ -2489,8 +2545,9 @@ Lint/UriRegexp:
2489
2545
  Lint/UselessAccessModifier:
2490
2546
  Description: 'Checks for useless access modifiers.'
2491
2547
  Enabled: true
2548
+ AutoCorrect: contextual
2492
2549
  VersionAdded: '0.20'
2493
- VersionChanged: '0.83'
2550
+ VersionChanged: '1.61'
2494
2551
  ContextCreatingMethods: []
2495
2552
  MethodCreatingMethods: []
2496
2553
 
@@ -2498,9 +2555,9 @@ Lint/UselessAssignment:
2498
2555
  Description: 'Checks for useless assignment to a local variable.'
2499
2556
  StyleGuide: '#underscore-unused-vars'
2500
2557
  Enabled: true
2558
+ AutoCorrect: contextual
2501
2559
  VersionAdded: '0.11'
2502
- VersionChanged: '1.51'
2503
- SafeAutoCorrect: false
2560
+ VersionChanged: '1.66'
2504
2561
 
2505
2562
  Lint/UselessElseWithoutRescue:
2506
2563
  Description: 'Checks for useless `else` in `begin..end` without `rescue`.'
@@ -2511,10 +2568,16 @@ Lint/UselessElseWithoutRescue:
2511
2568
  Lint/UselessMethodDefinition:
2512
2569
  Description: 'Checks for useless method definitions.'
2513
2570
  Enabled: true
2571
+ AutoCorrect: contextual
2514
2572
  VersionAdded: '0.90'
2515
- VersionChanged: '0.91'
2573
+ VersionChanged: '1.61'
2516
2574
  Safe: false
2517
2575
 
2576
+ Lint/UselessNumericOperation:
2577
+ Description: 'Checks for useless numeric operations.'
2578
+ Enabled: pending
2579
+ VersionAdded: '1.66'
2580
+
2518
2581
  Lint/UselessRescue:
2519
2582
  Description: 'Checks for useless `rescue`s.'
2520
2583
  Enabled: pending
@@ -2535,13 +2598,17 @@ Lint/UselessSetterCall:
2535
2598
  Lint/UselessTimes:
2536
2599
  Description: 'Checks for useless `Integer#times` calls.'
2537
2600
  Enabled: true
2538
- VersionAdded: '0.91'
2539
2601
  Safe: false
2602
+ AutoCorrect: contextual
2603
+ VersionAdded: '0.91'
2604
+ VersionChanged: '1.61'
2540
2605
 
2541
2606
  Lint/Void:
2542
2607
  Description: 'Possible use of operator/literal/variable in void context.'
2543
2608
  Enabled: true
2609
+ AutoCorrect: contextual
2544
2610
  VersionAdded: '0.9'
2611
+ VersionChanged: '1.61'
2545
2612
  CheckForMethodsWithNoSideEffects: false
2546
2613
 
2547
2614
  #################### Metrics ###############################
@@ -2584,8 +2651,9 @@ Metrics/BlockNesting:
2584
2651
  StyleGuide: '#three-is-the-number-thou-shalt-count'
2585
2652
  Enabled: true
2586
2653
  VersionAdded: '0.25'
2587
- VersionChanged: '0.47'
2654
+ VersionChanged: '1.65'
2588
2655
  CountBlocks: false
2656
+ CountModifierForms: false
2589
2657
  Max: 3
2590
2658
 
2591
2659
  Metrics/ClassLength:
@@ -2740,7 +2808,8 @@ Naming/FileName:
2740
2808
  VersionChanged: '1.23'
2741
2809
  # Camel case file names listed in `AllCops:Include` and all file names listed
2742
2810
  # in `AllCops:Exclude` are excluded by default. Add extra excludes here.
2743
- Exclude: []
2811
+ Exclude:
2812
+ - Rakefile.rb
2744
2813
  # When `true`, requires that each source file should define a class or module
2745
2814
  # with a name which matches the file name (converted to ... case).
2746
2815
  # It further expects it to be nested inside modules which match the names
@@ -3056,6 +3125,7 @@ Style/AccessModifierDeclarations:
3056
3125
  - inline
3057
3126
  - group
3058
3127
  AllowModifiersOnSymbols: true
3128
+ AllowModifiersOnAttrs: true
3059
3129
  SafeAutoCorrect: false
3060
3130
 
3061
3131
  Style/AccessorGrouping:
@@ -3080,6 +3150,12 @@ Style/Alias:
3080
3150
  - prefer_alias
3081
3151
  - prefer_alias_method
3082
3152
 
3153
+ Style/AmbiguousEndlessMethodDefinition:
3154
+ Description: 'Checks for endless methods inside operators of lower precedence.'
3155
+ StyleGuide: '#ambiguous-endless-method-defintions'
3156
+ Enabled: pending
3157
+ VersionAdded: '1.68'
3158
+
3083
3159
  Style/AndOr:
3084
3160
  Description: 'Use &&/|| instead of and/or.'
3085
3161
  StyleGuide: '#no-and-or-or'
@@ -3187,6 +3263,13 @@ Style/BisectedAttrAccessor:
3187
3263
  Enabled: true
3188
3264
  VersionAdded: '0.87'
3189
3265
 
3266
+ Style/BitwisePredicate:
3267
+ Description: 'Prefer bitwise predicate methods over direct comparison operations.'
3268
+ StyleGuide: '#bitwise-predicate-methods'
3269
+ Enabled: pending
3270
+ Safe: false
3271
+ VersionAdded: '1.68'
3272
+
3190
3273
  Style/BlockComments:
3191
3274
  Description: 'Do not use block comments.'
3192
3275
  StyleGuide: '#no-block-comments'
@@ -3470,6 +3553,11 @@ Style/ColonMethodDefinition:
3470
3553
  Enabled: true
3471
3554
  VersionAdded: '0.52'
3472
3555
 
3556
+ Style/CombinableDefined:
3557
+ Description: 'Checks successive `defined?` calls that can be combined into a single call.'
3558
+ Enabled: pending
3559
+ VersionAdded: '1.68'
3560
+
3473
3561
  Style/CombinableLoops:
3474
3562
  Description: >-
3475
3563
  Checks for places where multiple consecutive loops over the same data
@@ -3653,6 +3741,7 @@ Style/DocumentationMethod:
3653
3741
  Description: 'Checks for missing documentation comment for public methods.'
3654
3742
  Enabled: false
3655
3743
  VersionAdded: '0.43'
3744
+ AllowedMethods: []
3656
3745
  Exclude:
3657
3746
  - 'spec/**/*'
3658
3747
  - 'test/**/*'
@@ -3701,8 +3790,9 @@ Style/EmptyCaseCondition:
3701
3790
  Style/EmptyElse:
3702
3791
  Description: 'Avoid empty else-clauses.'
3703
3792
  Enabled: true
3793
+ AutoCorrect: contextual
3704
3794
  VersionAdded: '0.28'
3705
- VersionChanged: '0.32'
3795
+ VersionChanged: '1.61'
3706
3796
  EnforcedStyle: both
3707
3797
  # empty - warn only on empty `else`
3708
3798
  # nil - warn on `else` with nil in it
@@ -3716,7 +3806,9 @@ Style/EmptyElse:
3716
3806
  Style/EmptyHeredoc:
3717
3807
  Description: 'Checks for using empty heredoc to reduce redundancy.'
3718
3808
  Enabled: pending
3809
+ AutoCorrect: contextual
3719
3810
  VersionAdded: '1.32'
3811
+ VersionChanged: '1.61'
3720
3812
 
3721
3813
  Style/EmptyLambdaParameter:
3722
3814
  Description: 'Omit parens for empty lambda parameters.'
@@ -3734,7 +3826,9 @@ Style/EmptyMethod:
3734
3826
  Description: 'Checks the formatting of empty method definitions.'
3735
3827
  StyleGuide: '#no-single-line-methods'
3736
3828
  Enabled: true
3829
+ AutoCorrect: contextual
3737
3830
  VersionAdded: '0.46'
3831
+ VersionChanged: '1.61'
3738
3832
  EnforcedStyle: compact
3739
3833
  SupportedStyles:
3740
3834
  - compact
@@ -4007,7 +4101,7 @@ Style/HashSyntax:
4007
4101
  StyleGuide: '#hash-literals'
4008
4102
  Enabled: true
4009
4103
  VersionAdded: '0.9'
4010
- VersionChanged: '1.24'
4104
+ VersionChanged: '1.67'
4011
4105
  EnforcedStyle: ruby19
4012
4106
  SupportedStyles:
4013
4107
  # checks for 1.9 syntax (e.g. {a: 1}) for all symbol keys
@@ -4019,7 +4113,7 @@ Style/HashSyntax:
4019
4113
  # enforces both ruby19 and no_mixed_keys styles
4020
4114
  - ruby19_no_mixed_keys
4021
4115
  # Force hashes that have a hash value omission
4022
- EnforcedShorthandSyntax: always
4116
+ EnforcedShorthandSyntax: either
4023
4117
  SupportedShorthandSyntax:
4024
4118
  # forces use of the 3.1 syntax (e.g. {foo:}) when the hash key and value are the same.
4025
4119
  - always
@@ -4029,6 +4123,8 @@ Style/HashSyntax:
4029
4123
  - either
4030
4124
  # forces use of the 3.1 syntax only if all values can be omitted in the hash.
4031
4125
  - consistent
4126
+ # allow either (implicit or explicit) syntax but enforce consistency within a single hash
4127
+ - either_consistent
4032
4128
  # Force hashes that have a symbol value to use hash rockets
4033
4129
  UseHashRocketsWithSymbolValues: false
4034
4130
  # Do not suggest { a?: 1 } over { :a? => 1 } in ruby19 style
@@ -4185,6 +4281,14 @@ Style/IpAddresses:
4185
4281
  - '**/gems.rb'
4186
4282
  - '**/*.gemspec'
4187
4283
 
4284
+ Style/KeywordArgumentsMerging:
4285
+ Description: >-
4286
+ When passing an existing hash as keyword arguments, provide additional arguments
4287
+ directly rather than using `merge`.
4288
+ StyleGuide: '#merging-keyword-arguments'
4289
+ Enabled: pending
4290
+ VersionAdded: '1.68'
4291
+
4188
4292
  Style/KeywordParametersOrder:
4189
4293
  Description: 'Enforces that optional keyword parameters are placed at the end of the parameters list.'
4190
4294
  StyleGuide: '#keyword-parameters-order'
@@ -4249,6 +4353,14 @@ Style/MapCompactWithConditionalBlock:
4249
4353
  Enabled: pending
4250
4354
  VersionAdded: '1.30'
4251
4355
 
4356
+ Style/MapIntoArray:
4357
+ Description: 'Checks for usages of `each` with `<<`, `push`, or `append` which can be replaced by `map`.'
4358
+ StyleGuide: '#functional-code'
4359
+ Enabled: pending
4360
+ VersionAdded: '1.63'
4361
+ VersionChanged: '1.67'
4362
+ Safe: false
4363
+
4252
4364
  Style/MapToHash:
4253
4365
  Description: 'Prefer `to_h` with a block over `map.to_h`.'
4254
4366
  Enabled: pending
@@ -4712,6 +4824,7 @@ Style/OperatorMethodCall:
4712
4824
 
4713
4825
  Style/OptionHash:
4714
4826
  Description: "Don't use option hashes when you can use keyword arguments."
4827
+ StyleGuide: '#keyword-arguments-vs-option-hashes'
4715
4828
  Enabled: false
4716
4829
  VersionAdded: '0.33'
4717
4830
  VersionChanged: '0.34'
@@ -4834,8 +4947,9 @@ Style/RaiseArgs:
4834
4947
  Description: 'Checks the arguments passed to raise/fail.'
4835
4948
  StyleGuide: '#exception-class-messages'
4836
4949
  Enabled: true
4950
+ Safe: false
4837
4951
  VersionAdded: '0.14'
4838
- VersionChanged: '1.2'
4952
+ VersionChanged: '1.61'
4839
4953
  EnforcedStyle: exploded
4840
4954
  SupportedStyles:
4841
4955
  - compact # raise Exception.new(msg)
@@ -4976,10 +5090,11 @@ Style/RedundantHeredocDelimiterQuotes:
4976
5090
  Style/RedundantInitialize:
4977
5091
  Description: 'Checks for redundant `initialize` methods.'
4978
5092
  Enabled: pending
5093
+ AutoCorrect: contextual
4979
5094
  Safe: false
4980
5095
  AllowComments: true
4981
5096
  VersionAdded: '1.27'
4982
- VersionChanged: '1.28'
5097
+ VersionChanged: '1.61'
4983
5098
 
4984
5099
  Style/RedundantInterpolation:
4985
5100
  Description: 'Checks for strings that are just an interpolated expression.'
@@ -4988,6 +5103,11 @@ Style/RedundantInterpolation:
4988
5103
  VersionAdded: '0.76'
4989
5104
  VersionChanged: '1.30'
4990
5105
 
5106
+ Style/RedundantInterpolationUnfreeze:
5107
+ Description: 'Checks for redundant unfreezing of interpolated strings.'
5108
+ Enabled: pending
5109
+ VersionAdded: '1.66'
5110
+
4991
5111
  Style/RedundantLineContinuation:
4992
5112
  Description: 'Check for redundant line continuation.'
4993
5113
  Enabled: pending
@@ -5129,6 +5249,7 @@ Style/ReturnNilInPredicateMethodDefinition:
5129
5249
  AllowedMethods: []
5130
5250
  AllowedPatterns: []
5131
5251
  VersionAdded: '1.53'
5252
+ VersionChanged: '1.67'
5132
5253
 
5133
5254
  Style/SafeNavigation:
5134
5255
  Description: >-
@@ -5139,7 +5260,7 @@ Style/SafeNavigation:
5139
5260
  be `nil` or truthy, but never `false`.
5140
5261
  Enabled: true
5141
5262
  VersionAdded: '0.43'
5142
- VersionChanged: '1.27'
5263
+ VersionChanged: '1.67'
5143
5264
  # Safe navigation may cause a statement to start returning `nil` in addition
5144
5265
  # to whatever it used to return.
5145
5266
  ConvertCodeThatCanStartToReturnNil: false
@@ -5153,6 +5274,13 @@ Style/SafeNavigation:
5153
5274
  # Maximum length of method chains for register an offense.
5154
5275
  MaxChainLength: 2
5155
5276
 
5277
+ Style/SafeNavigationChainLength:
5278
+ Description: 'Enforces safe navigation chains length to not exceed the configured maximum.'
5279
+ StyleGuide: '#safe-navigation'
5280
+ Enabled: pending
5281
+ VersionAdded: '1.68'
5282
+ Max: 2
5283
+
5156
5284
  Style/Sample:
5157
5285
  Description: >-
5158
5286
  Use `sample` instead of `shuffle.first`,
@@ -5191,6 +5319,13 @@ Style/Send:
5191
5319
  Enabled: false
5192
5320
  VersionAdded: '0.33'
5193
5321
 
5322
+ Style/SendWithLiteralMethodName:
5323
+ Description: 'Detects the use of the `public_send` method with a static method name argument.'
5324
+ Enabled: pending
5325
+ Safe: false
5326
+ AllowSend: true
5327
+ VersionAdded: '1.64'
5328
+
5194
5329
  Style/SignalException:
5195
5330
  Description: 'Checks for proper usage of fail and raise.'
5196
5331
  StyleGuide: '#prefer-raise-over-fail'
@@ -5237,7 +5372,8 @@ Style/SingleLineMethods:
5237
5372
  AllowIfMethodIsEmpty: true
5238
5373
 
5239
5374
  Style/SlicingWithRange:
5240
- Description: 'Checks array slicing is done with endless ranges when suitable.'
5375
+ Description: 'Checks array slicing is done with redundant, endless, and beginless ranges when suitable.'
5376
+ StyleGuide: '#slicing-with-ranges'
5241
5377
  Enabled: true
5242
5378
  VersionAdded: '0.83'
5243
5379
  Safe: false
@@ -5364,6 +5500,11 @@ Style/StructInheritance:
5364
5500
  VersionAdded: '0.29'
5365
5501
  VersionChanged: '1.20'
5366
5502
 
5503
+ Style/SuperArguments:
5504
+ Description: 'Call `super` without arguments and parentheses when the signature is identical.'
5505
+ Enabled: pending
5506
+ VersionAdded: '1.64'
5507
+
5367
5508
  Style/SuperWithArgsParentheses:
5368
5509
  Description: 'Use parentheses for `super` with arguments.'
5369
5510
  StyleGuide: '#super-with-args'
@@ -5399,7 +5540,7 @@ Style/SymbolProc:
5399
5540
  Enabled: true
5400
5541
  Safe: false
5401
5542
  VersionAdded: '0.26'
5402
- VersionChanged: '1.40'
5543
+ VersionChanged: '1.64'
5403
5544
  AllowMethodsWithArguments: false
5404
5545
  # A list of method names to be always allowed by the check.
5405
5546
  # The names should be fairly unique, otherwise you'll end up ignoring lots of code.
@@ -0,0 +1,11 @@
1
+ # Configuration for InternalAffairs cops. This file will be
2
+ # automatically loaded when `rubocop/cop/internal_affairs` is required.
3
+ # Only do this when developing custom cops or a RuboCop extension.
4
+
5
+ InternalAffairs/CopDescription:
6
+ Include:
7
+ - 'lib/rubocop/cop/**/*.rb'
8
+
9
+ InternalAffairs/UselessMessageAssertion:
10
+ Include:
11
+ - '**/*_spec.rb'
data/exe/rubocop CHANGED
@@ -11,13 +11,14 @@ exit exit_status if server_cli.exit?
11
11
  if RuboCop::Server.running?
12
12
  exit_status = RuboCop::Server::ClientCommand::Exec.new.run
13
13
  else
14
- require 'benchmark'
15
14
  require 'rubocop'
16
15
 
17
16
  cli = RuboCop::CLI.new
18
17
 
19
- time = Benchmark.realtime { exit_status = cli.run }
18
+ time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
19
+ exit_status = cli.run
20
+ elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - time_start
20
21
 
21
- puts "Finished in #{time} seconds" if cli.options[:debug] || cli.options[:display_time]
22
+ puts "Finished in #{elapsed_time} seconds" if cli.options[:debug] || cli.options[:display_time]
22
23
  end
23
24
  exit exit_status
@@ -45,14 +45,30 @@ module RuboCop
45
45
 
46
46
  # Restore an offense object loaded from a JSON file.
47
47
  def deserialize_offenses(offenses)
48
- source_buffer = Parser::Source::Buffer.new(@filename)
49
- source_buffer.source = File.read(@filename, encoding: Encoding::UTF_8)
50
48
  offenses.map! do |o|
51
- location = Parser::Source::Range.new(source_buffer,
52
- o['location']['begin_pos'],
53
- o['location']['end_pos'])
49
+ location = location_from_source_buffer(o)
54
50
  Cop::Offense.new(o['severity'], location, o['message'], o['cop_name'], o['status'].to_sym)
55
51
  end
56
52
  end
53
+
54
+ def location_from_source_buffer(offense)
55
+ begin_pos = offense['location']['begin_pos']
56
+ end_pos = offense['location']['end_pos']
57
+ if begin_pos.zero? && end_pos.zero?
58
+ Cop::Offense::NO_LOCATION
59
+ else
60
+ Parser::Source::Range.new(source_buffer, begin_pos, end_pos)
61
+ end
62
+ end
63
+
64
+ # Delay creation until needed. Some type of offenses will have no buffer associated with them
65
+ # and be global only. For these, trying to create the buffer will likely fail, for example
66
+ # because of unknown encoding comments.
67
+ def source_buffer
68
+ @source_buffer ||= begin
69
+ source = File.read(@filename, encoding: Encoding::UTF_8)
70
+ Parser::Source::Buffer.new(@filename, source: source)
71
+ end
72
+ end
57
73
  end
58
74
  end
@@ -17,7 +17,10 @@ module RuboCop
17
17
 
18
18
  PHASE_1_OVERRIDDEN = '(skipped because the default Layout/LineLength:Max is overridden)'
19
19
  PHASE_1_DISABLED = '(skipped because Layout/LineLength is disabled)'
20
- PHASE_1_SKIPPED = '(skipped because a list of cops is passed to the `--only` flag)'
20
+ PHASE_1_SKIPPED_ONLY_COPS =
21
+ '(skipped because a list of cops is passed to the `--only` flag)'
22
+ PHASE_1_SKIPPED_ONLY_EXCLUDE =
23
+ '(skipped because only excludes will be generated due to `--auto-gen-only-exclude` flag)'
21
24
 
22
25
  def run
23
26
  add_formatter
@@ -29,12 +32,14 @@ module RuboCop
29
32
  private
30
33
 
31
34
  def maybe_run_line_length_cop
32
- if !line_length_enabled?(@config_store.for_pwd)
35
+ if only_exclude?
36
+ skip_line_length_cop(PHASE_1_SKIPPED_ONLY_EXCLUDE)
37
+ elsif !line_length_enabled?(@config_store.for_pwd)
33
38
  skip_line_length_cop(PHASE_1_DISABLED)
34
39
  elsif !same_max_line_length?(@config_store.for_pwd, ConfigLoader.default_configuration)
35
40
  skip_line_length_cop(PHASE_1_OVERRIDDEN)
36
41
  elsif options_has_only_flag?
37
- skip_line_length_cop(PHASE_1_SKIPPED)
42
+ skip_line_length_cop(PHASE_1_SKIPPED_ONLY_COPS)
38
43
  else
39
44
  run_line_length_cop
40
45
  end
@@ -65,6 +70,10 @@ module RuboCop
65
70
  @options[:only]
66
71
  end
67
72
 
73
+ def only_exclude?
74
+ @options[:auto_gen_only_exclude]
75
+ end
76
+
68
77
  # Do an initial run with only Layout/LineLength so that cops that
69
78
  # depend on Layout/LineLength:Max get the correct value for that
70
79
  # parameter.
@@ -142,16 +151,15 @@ module RuboCop
142
151
  end
143
152
 
144
153
  def relative_path_to_todo_from_options_config
145
- return AUTO_GENERATED_FILE if !@options[:config] || options_config_in_root?
154
+ return AUTO_GENERATED_FILE unless @options[:config]
146
155
 
147
- base = Pathname.new('.')
148
- config_dir = Pathname.new(File.dirname(@options[:config]))
156
+ base = Pathname.new(Dir.pwd)
157
+ config_dir = Pathname.new(@options[:config]).realpath.dirname
149
158
 
150
- "#{base.relative_path_from(config_dir)}/#{AUTO_GENERATED_FILE}"
151
- end
159
+ # Don't have the path start with `/`
160
+ return AUTO_GENERATED_FILE if config_dir == base
152
161
 
153
- def options_config_in_root?
154
- File.dirname(@options[:config]) == '.'
162
+ "#{base.relative_path_from(config_dir)}/#{AUTO_GENERATED_FILE}"
155
163
  end
156
164
  end
157
165
  end
@@ -78,7 +78,7 @@ module RuboCop
78
78
  Please, report your problems to RuboCop's issue tracker.
79
79
  #{bug_tracker_uri}
80
80
  Mention the following information in the issue report:
81
- #{RuboCop::Version.version(debug: true)}
81
+ #{RuboCop::Version.verbose}
82
82
  WARNING
83
83
  end
84
84