rubocop 1.68.0 → 1.71.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (361) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +2 -2
  4. data/config/default.yml +77 -8
  5. data/lib/rubocop/cli/command/execute_runner.rb +3 -3
  6. data/lib/rubocop/cli/command/show_cops.rb +24 -2
  7. data/lib/rubocop/comment_config.rb +1 -1
  8. data/lib/rubocop/config.rb +13 -4
  9. data/lib/rubocop/config_loader.rb +4 -0
  10. data/lib/rubocop/config_loader_resolver.rb +14 -3
  11. data/lib/rubocop/config_validator.rb +18 -8
  12. data/lib/rubocop/cop/autocorrect_logic.rb +32 -35
  13. data/lib/rubocop/cop/base.rb +7 -1
  14. data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -2
  15. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
  16. data/lib/rubocop/cop/bundler/gem_filename.rb +0 -1
  17. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +0 -1
  18. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +1 -1
  19. data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +1 -2
  20. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +0 -2
  21. data/lib/rubocop/cop/generator.rb +6 -0
  22. data/lib/rubocop/cop/internal_affairs/cop_enabled.rb +85 -0
  23. data/lib/rubocop/cop/internal_affairs/location_expression.rb +2 -1
  24. data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +3 -4
  25. data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +3 -2
  26. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
  27. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +63 -0
  28. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +131 -0
  29. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +229 -0
  30. data/lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb +126 -0
  31. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +4 -3
  32. data/lib/rubocop/cop/internal_affairs/numblock_handler.rb +1 -1
  33. data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +90 -0
  34. data/lib/rubocop/cop/internal_affairs/operator_keyword.rb +48 -0
  35. data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +3 -1
  36. data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +5 -4
  37. data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +0 -2
  38. data/lib/rubocop/cop/internal_affairs.rb +5 -0
  39. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -1
  40. data/lib/rubocop/cop/layout/argument_alignment.rb +2 -9
  41. data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
  42. data/lib/rubocop/cop/layout/begin_end_alignment.rb +0 -1
  43. data/lib/rubocop/cop/layout/block_alignment.rb +1 -2
  44. data/lib/rubocop/cop/layout/class_structure.rb +9 -9
  45. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  46. data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
  47. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  48. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +7 -11
  49. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +3 -3
  50. data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +5 -6
  51. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +4 -5
  52. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +3 -1
  53. data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
  54. data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
  55. data/lib/rubocop/cop/layout/first_argument_indentation.rb +3 -8
  56. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -7
  57. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +2 -7
  58. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +1 -1
  59. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
  60. data/lib/rubocop/cop/layout/hash_alignment.rb +6 -4
  61. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -0
  62. data/lib/rubocop/cop/layout/indentation_width.rb +7 -7
  63. data/lib/rubocop/cop/layout/leading_comment_space.rb +15 -0
  64. data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +11 -2
  65. data/lib/rubocop/cop/layout/line_continuation_spacing.rb +7 -1
  66. data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +2 -2
  67. data/lib/rubocop/cop/layout/line_length.rb +119 -4
  68. data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +1 -1
  69. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +25 -0
  70. data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +2 -1
  71. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +2 -2
  72. data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +1 -1
  73. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +2 -3
  74. data/lib/rubocop/cop/layout/parameter_alignment.rb +3 -4
  75. data/lib/rubocop/cop/layout/redundant_line_break.rb +10 -41
  76. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +4 -3
  77. data/lib/rubocop/cop/layout/single_line_block_chain.rb +1 -1
  78. data/lib/rubocop/cop/layout/space_after_colon.rb +2 -2
  79. data/lib/rubocop/cop/layout/space_after_comma.rb +1 -1
  80. data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -1
  81. data/lib/rubocop/cop/layout/space_after_semicolon.rb +1 -1
  82. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -1
  83. data/lib/rubocop/cop/layout/space_around_operators.rb +19 -20
  84. data/lib/rubocop/cop/layout/space_before_comma.rb +1 -1
  85. data/lib/rubocop/cop/layout/space_before_semicolon.rb +1 -1
  86. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +6 -0
  87. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +4 -0
  88. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +0 -1
  89. data/lib/rubocop/cop/layout/trailing_whitespace.rb +5 -3
  90. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
  91. data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +119 -0
  92. data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -3
  93. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +10 -12
  94. data/lib/rubocop/cop/lint/circular_argument_reference.rb +6 -0
  95. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +3 -3
  96. data/lib/rubocop/cop/lint/constant_reassignment.rb +148 -0
  97. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  98. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +2 -1
  99. data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +1 -1
  100. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +1 -1
  101. data/lib/rubocop/cop/lint/duplicate_set_element.rb +20 -7
  102. data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
  103. data/lib/rubocop/cop/lint/empty_expression.rb +0 -2
  104. data/lib/rubocop/cop/lint/empty_file.rb +0 -2
  105. data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
  106. data/lib/rubocop/cop/lint/float_comparison.rb +19 -8
  107. data/lib/rubocop/cop/lint/float_out_of_range.rb +2 -4
  108. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
  109. data/lib/rubocop/cop/lint/hash_new_with_keyword_arguments_as_default.rb +55 -0
  110. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  111. data/lib/rubocop/cop/lint/interpolation_check.rb +9 -0
  112. data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +3 -0
  113. data/lib/rubocop/cop/lint/literal_as_condition.rb +1 -0
  114. data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +1 -1
  115. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +24 -6
  116. data/lib/rubocop/cop/lint/missing_super.rb +2 -2
  117. data/lib/rubocop/cop/lint/mixed_case_range.rb +3 -6
  118. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -1
  119. data/lib/rubocop/cop/lint/nested_method_definition.rb +9 -5
  120. data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
  121. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +2 -2
  122. data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +5 -3
  123. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +3 -3
  124. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +1 -1
  125. data/lib/rubocop/cop/lint/number_conversion.rb +0 -1
  126. data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +1 -2
  127. data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +93 -0
  128. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -2
  129. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +3 -2
  130. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -5
  131. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +1 -1
  132. data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
  133. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +12 -7
  134. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +8 -7
  135. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +2 -2
  136. data/lib/rubocop/cop/lint/refinement_import_methods.rb +1 -1
  137. data/lib/rubocop/cop/lint/regexp_as_condition.rb +0 -1
  138. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
  139. data/lib/rubocop/cop/lint/rescue_type.rb +3 -7
  140. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +8 -1
  141. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +2 -0
  142. data/lib/rubocop/cop/lint/self_assignment.rb +8 -10
  143. data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
  144. data/lib/rubocop/cop/lint/shared_mutable_default.rb +65 -0
  145. data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
  146. data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
  147. data/lib/rubocop/cop/lint/syntax.rb +4 -1
  148. data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +1 -1
  149. data/lib/rubocop/cop/lint/unexpected_block_arity.rb +1 -1
  150. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -1
  151. data/lib/rubocop/cop/lint/unreachable_code.rb +51 -2
  152. data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -1
  153. data/lib/rubocop/cop/lint/unused_method_argument.rb +18 -2
  154. data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -4
  155. data/lib/rubocop/cop/lint/useless_assignment.rb +1 -1
  156. data/lib/rubocop/cop/lint/useless_defined.rb +55 -0
  157. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +4 -0
  158. data/lib/rubocop/cop/lint/useless_method_definition.rb +1 -1
  159. data/lib/rubocop/cop/lint/useless_numeric_operation.rb +2 -1
  160. data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
  161. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +2 -2
  162. data/lib/rubocop/cop/lint/useless_setter_call.rb +14 -25
  163. data/lib/rubocop/cop/lint/void.rb +8 -11
  164. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
  165. data/lib/rubocop/cop/metrics/class_length.rb +9 -9
  166. data/lib/rubocop/cop/metrics/collection_literal_length.rb +7 -0
  167. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
  168. data/lib/rubocop/cop/metrics/method_length.rb +8 -1
  169. data/lib/rubocop/cop/metrics/module_length.rb +1 -1
  170. data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
  171. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
  172. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +2 -3
  173. data/lib/rubocop/cop/mixin/check_assignment.rb +4 -12
  174. data/lib/rubocop/cop/mixin/check_line_breakable.rb +11 -11
  175. data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +49 -0
  176. data/lib/rubocop/cop/mixin/comments_help.rb +7 -2
  177. data/lib/rubocop/cop/mixin/dig_help.rb +27 -0
  178. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
  179. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +4 -4
  180. data/lib/rubocop/cop/mixin/hash_subset.rb +188 -0
  181. data/lib/rubocop/cop/mixin/line_length_help.rb +5 -4
  182. data/lib/rubocop/cop/mixin/method_complexity.rb +1 -1
  183. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +5 -9
  184. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +68 -30
  185. data/lib/rubocop/cop/mixin/range_help.rb +0 -1
  186. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
  187. data/lib/rubocop/cop/mixin/statement_modifier.rb +8 -3
  188. data/lib/rubocop/cop/mixin/string_help.rb +1 -1
  189. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
  190. data/lib/rubocop/cop/mixin/target_ruby_version.rb +17 -1
  191. data/lib/rubocop/cop/mixin/trailing_comma.rb +3 -3
  192. data/lib/rubocop/cop/naming/accessor_method_name.rb +6 -6
  193. data/lib/rubocop/cop/naming/block_forwarding.rb +19 -15
  194. data/lib/rubocop/cop/naming/constant_name.rb +6 -7
  195. data/lib/rubocop/cop/naming/file_name.rb +0 -2
  196. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +11 -12
  197. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +6 -14
  198. data/lib/rubocop/cop/naming/variable_name.rb +3 -4
  199. data/lib/rubocop/cop/naming/variable_number.rb +2 -3
  200. data/lib/rubocop/cop/security/compound_hash.rb +2 -0
  201. data/lib/rubocop/cop/security/yaml_load.rb +3 -2
  202. data/lib/rubocop/cop/style/access_modifier_declarations.rb +86 -28
  203. data/lib/rubocop/cop/style/ambiguous_endless_method_definition.rb +1 -1
  204. data/lib/rubocop/cop/style/and_or.rb +1 -1
  205. data/lib/rubocop/cop/style/arguments_forwarding.rb +39 -23
  206. data/lib/rubocop/cop/style/array_first_last.rb +18 -2
  207. data/lib/rubocop/cop/style/array_intersect.rb +5 -4
  208. data/lib/rubocop/cop/style/bitwise_predicate.rb +1 -1
  209. data/lib/rubocop/cop/style/block_delimiters.rb +24 -22
  210. data/lib/rubocop/cop/style/case_like_if.rb +8 -11
  211. data/lib/rubocop/cop/style/class_and_module_children.rb +6 -3
  212. data/lib/rubocop/cop/style/collection_methods.rb +1 -1
  213. data/lib/rubocop/cop/style/combinable_defined.rb +1 -1
  214. data/lib/rubocop/cop/style/combinable_loops.rb +2 -2
  215. data/lib/rubocop/cop/style/commented_keyword.rb +11 -1
  216. data/lib/rubocop/cop/style/concat_array_literals.rb +1 -1
  217. data/lib/rubocop/cop/style/conditional_assignment.rb +25 -25
  218. data/lib/rubocop/cop/style/constant_visibility.rb +3 -12
  219. data/lib/rubocop/cop/style/dig_chain.rb +89 -0
  220. data/lib/rubocop/cop/style/documentation.rb +1 -1
  221. data/lib/rubocop/cop/style/double_negation.rb +3 -3
  222. data/lib/rubocop/cop/style/each_for_simple_loop.rb +4 -7
  223. data/lib/rubocop/cop/style/each_with_object.rb +2 -3
  224. data/lib/rubocop/cop/style/empty_else.rb +4 -2
  225. data/lib/rubocop/cop/style/empty_literal.rb +1 -1
  226. data/lib/rubocop/cop/style/empty_method.rb +1 -1
  227. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  228. data/lib/rubocop/cop/style/exact_regexp_match.rb +2 -3
  229. data/lib/rubocop/cop/style/explicit_block_argument.rb +15 -2
  230. data/lib/rubocop/cop/style/exponential_notation.rb +1 -1
  231. data/lib/rubocop/cop/style/fetch_env_var.rb +2 -1
  232. data/lib/rubocop/cop/style/file_null.rb +89 -0
  233. data/lib/rubocop/cop/style/file_touch.rb +75 -0
  234. data/lib/rubocop/cop/style/float_division.rb +8 -4
  235. data/lib/rubocop/cop/style/for.rb +0 -1
  236. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  237. data/lib/rubocop/cop/style/global_vars.rb +1 -3
  238. data/lib/rubocop/cop/style/guard_clause.rb +1 -1
  239. data/lib/rubocop/cop/style/hash_conversion.rb +1 -2
  240. data/lib/rubocop/cop/style/hash_each_methods.rb +3 -6
  241. data/lib/rubocop/cop/style/hash_except.rb +35 -147
  242. data/lib/rubocop/cop/style/hash_slice.rb +80 -0
  243. data/lib/rubocop/cop/style/hash_syntax.rb +6 -3
  244. data/lib/rubocop/cop/style/identical_conditional_branches.rb +22 -3
  245. data/lib/rubocop/cop/style/if_inside_else.rb +0 -1
  246. data/lib/rubocop/cop/style/if_unless_modifier.rb +3 -3
  247. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -3
  248. data/lib/rubocop/cop/style/if_with_semicolon.rb +20 -9
  249. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  250. data/lib/rubocop/cop/style/inverse_methods.rb +6 -7
  251. data/lib/rubocop/cop/style/it_assignment.rb +36 -0
  252. data/lib/rubocop/cop/style/keyword_arguments_merging.rb +2 -2
  253. data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -1
  254. data/lib/rubocop/cop/style/lambda_call.rb +3 -2
  255. data/lib/rubocop/cop/style/map_into_array.rb +1 -1
  256. data/lib/rubocop/cop/style/map_to_hash.rb +1 -1
  257. data/lib/rubocop/cop/style/map_to_set.rb +3 -2
  258. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +20 -13
  259. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -0
  260. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +8 -11
  261. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -4
  262. data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
  263. data/lib/rubocop/cop/style/missing_else.rb +2 -0
  264. data/lib/rubocop/cop/style/missing_respond_to_missing.rb +33 -3
  265. data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
  266. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  267. data/lib/rubocop/cop/style/multiple_comparison.rb +34 -22
  268. data/lib/rubocop/cop/style/mutable_constant.rb +7 -8
  269. data/lib/rubocop/cop/style/negated_if_else_condition.rb +7 -5
  270. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
  271. data/lib/rubocop/cop/style/nested_ternary_operator.rb +5 -4
  272. data/lib/rubocop/cop/style/not.rb +1 -1
  273. data/lib/rubocop/cop/style/object_then.rb +14 -15
  274. data/lib/rubocop/cop/style/one_line_conditional.rb +25 -4
  275. data/lib/rubocop/cop/style/open_struct_use.rb +5 -5
  276. data/lib/rubocop/cop/style/operator_method_call.rb +5 -6
  277. data/lib/rubocop/cop/style/or_assignment.rb +3 -6
  278. data/lib/rubocop/cop/style/parallel_assignment.rb +9 -18
  279. data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -2
  280. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
  281. data/lib/rubocop/cop/style/proc.rb +1 -2
  282. data/lib/rubocop/cop/style/quoted_symbols.rb +1 -1
  283. data/lib/rubocop/cop/style/raise_args.rb +7 -5
  284. data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
  285. data/lib/rubocop/cop/style/redundant_argument.rb +3 -1
  286. data/lib/rubocop/cop/style/redundant_assignment.rb +1 -1
  287. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  288. data/lib/rubocop/cop/style/redundant_condition.rb +38 -23
  289. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +2 -1
  290. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +6 -10
  291. data/lib/rubocop/cop/style/redundant_each.rb +1 -1
  292. data/lib/rubocop/cop/style/redundant_exception.rb +2 -2
  293. data/lib/rubocop/cop/style/redundant_freeze.rb +2 -2
  294. data/lib/rubocop/cop/style/redundant_initialize.rb +12 -3
  295. data/lib/rubocop/cop/style/redundant_line_continuation.rb +44 -23
  296. data/lib/rubocop/cop/style/redundant_parentheses.rb +12 -12
  297. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +4 -0
  298. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
  299. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
  300. data/lib/rubocop/cop/style/redundant_return.rb +2 -2
  301. data/lib/rubocop/cop/style/redundant_self.rb +8 -15
  302. data/lib/rubocop/cop/style/redundant_self_assignment.rb +20 -32
  303. data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +4 -4
  304. data/lib/rubocop/cop/style/redundant_sort.rb +3 -3
  305. data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -2
  306. data/lib/rubocop/cop/style/rescue_modifier.rb +2 -3
  307. data/lib/rubocop/cop/style/return_nil.rb +1 -1
  308. data/lib/rubocop/cop/style/safe_navigation.rb +2 -2
  309. data/lib/rubocop/cop/style/select_by_regexp.rb +1 -1
  310. data/lib/rubocop/cop/style/self_assignment.rb +11 -17
  311. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  312. data/lib/rubocop/cop/style/send_with_literal_method_name.rb +2 -1
  313. data/lib/rubocop/cop/style/signal_exception.rb +2 -3
  314. data/lib/rubocop/cop/style/single_argument_dig.rb +9 -5
  315. data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
  316. data/lib/rubocop/cop/style/single_line_do_end_block.rb +12 -3
  317. data/lib/rubocop/cop/style/single_line_methods.rb +3 -4
  318. data/lib/rubocop/cop/style/slicing_with_range.rb +40 -11
  319. data/lib/rubocop/cop/style/sole_nested_conditional.rb +4 -5
  320. data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
  321. data/lib/rubocop/cop/style/string_concatenation.rb +14 -13
  322. data/lib/rubocop/cop/style/string_literals.rb +1 -1
  323. data/lib/rubocop/cop/style/string_methods.rb +1 -1
  324. data/lib/rubocop/cop/style/super_arguments.rb +65 -17
  325. data/lib/rubocop/cop/style/swap_values.rb +4 -15
  326. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  327. data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -1
  328. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +4 -1
  329. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +4 -4
  330. data/lib/rubocop/cop/style/variable_interpolation.rb +1 -2
  331. data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
  332. data/lib/rubocop/cop/style/yoda_condition.rb +8 -4
  333. data/lib/rubocop/cop/style/yoda_expression.rb +2 -1
  334. data/lib/rubocop/cop/util.rb +11 -4
  335. data/lib/rubocop/cop/variable_force/variable.rb +14 -2
  336. data/lib/rubocop/cop/variable_force/variable_table.rb +3 -3
  337. data/lib/rubocop/cop/variable_force.rb +4 -10
  338. data/lib/rubocop/cops_documentation_generator.rb +22 -14
  339. data/lib/rubocop/directive_comment.rb +9 -8
  340. data/lib/rubocop/formatter/formatter_set.rb +1 -1
  341. data/lib/rubocop/lsp/diagnostic.rb +189 -0
  342. data/lib/rubocop/lsp/logger.rb +2 -2
  343. data/lib/rubocop/lsp/routes.rb +7 -23
  344. data/lib/rubocop/lsp/runtime.rb +15 -49
  345. data/lib/rubocop/lsp/stdin_runner.rb +83 -0
  346. data/lib/rubocop/magic_comment.rb +3 -3
  347. data/lib/rubocop/options.rb +2 -1
  348. data/lib/rubocop/path_util.rb +11 -8
  349. data/lib/rubocop/result_cache.rb +13 -13
  350. data/lib/rubocop/rspec/expect_offense.rb +6 -2
  351. data/lib/rubocop/rspec/shared_contexts.rb +4 -1
  352. data/lib/rubocop/rspec/support.rb +1 -2
  353. data/lib/rubocop/runner.rb +5 -6
  354. data/lib/rubocop/target_finder.rb +1 -0
  355. data/lib/rubocop/target_ruby.rb +15 -0
  356. data/lib/rubocop/version.rb +1 -1
  357. data/lib/rubocop.rb +14 -0
  358. data/lib/ruby_lsp/rubocop/addon.rb +78 -0
  359. data/lib/ruby_lsp/rubocop/wraps_built_in_lsp_runtime.rb +50 -0
  360. metadata +36 -15
  361. data/lib/rubocop/rspec/host_environment_simulation_helper.rb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f0623068e9eac24fe4b1f5c7e4987d3a8adc7a2ec7f5f65c6cfb9d0ad9d1278
4
- data.tar.gz: 9abb03dde6881cb7c11a21ee947c33a7d8874b9893f81e81cd7617f52f1bb714
3
+ metadata.gz: 8d7c6408a777042eced58bec2bc889312b24d8701f5db99da3b471088f589d6f
4
+ data.tar.gz: 27423e682d55f04840a3bf3d5e0301556e4a1c419857e3422ced38ec423c0003
5
5
  SHA512:
6
- metadata.gz: 3392244d7137845de4f7c9867695350666750b349879ac4796590d090b0b1a182f21fb9c96f6d284bfd9eaf21a7594f8b7de2d59da62458400a709430bb6f7a2
7
- data.tar.gz: e2a5a3dd61755c091a91ea99828846fa875b3b7ca8ffaea67425245755e147159691c587a7a80089a428480b7ad07fef8da1be7dc209ac0a60bb46cff3a37d0f
6
+ metadata.gz: 8729a8ea3adae11fcb2501bfea338821a8f9894209ea6fb482b62ebfae87019e07ded7bf02d3371c18726b28c2491c79952e7b86c193388a045f886a833b427c
7
+ data.tar.gz: 44251afbbbc2aa7c121033ea05f25e1b3447afba7487d04a81f9463347ba28bcea05bdc2e434248f15cd235d9e452cb3f9f378f94adb5507eeb6d5ce58ba4119
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-24 Bozhidar Batsov
1
+ Copyright (c) 2012-25 Bozhidar Batsov
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -52,7 +52,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
52
52
  in your `Gemfile`:
53
53
 
54
54
  ```rb
55
- gem 'rubocop', '~> 1.68', require: false
55
+ gem 'rubocop', '~> 1.71', require: false
56
56
  ```
57
57
 
58
58
  See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
@@ -247,5 +247,5 @@ RuboCop's changelog is available [here](CHANGELOG.md).
247
247
 
248
248
  ## Copyright
249
249
 
250
- Copyright (c) 2012-2024 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for
250
+ Copyright (c) 2012-2025 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for
251
251
  further details.
data/config/default.yml CHANGED
@@ -1086,11 +1086,11 @@ Layout/LineLength:
1086
1086
  StyleGuide: '#max-line-length'
1087
1087
  Enabled: true
1088
1088
  VersionAdded: '0.25'
1089
- VersionChanged: '1.4'
1089
+ VersionChanged: '1.69'
1090
1090
  Max: 120
1091
+ AllowHeredoc: true
1091
1092
  # To make it possible to copy or click on URIs in the code, we allow lines
1092
1093
  # containing a URI to be longer than Max.
1093
- AllowHeredoc: true
1094
1094
  AllowURI: true
1095
1095
  URISchemes:
1096
1096
  - http
@@ -1102,6 +1102,8 @@ Layout/LineLength:
1102
1102
  # elements. Strings will be converted to Regexp objects. A line that matches
1103
1103
  # any regular expression listed in this option will be ignored by LineLength.
1104
1104
  AllowedPatterns: []
1105
+ # If SplitStrings is true, long strings will be split using continuations
1106
+ SplitStrings: false
1105
1107
 
1106
1108
  Layout/MultilineArrayBraceLayout:
1107
1109
  Description: >-
@@ -1499,7 +1501,6 @@ Layout/SpaceInsideHashLiteralBraces:
1499
1501
  - space
1500
1502
  - no_space
1501
1503
 
1502
-
1503
1504
  Layout/SpaceInsideParens:
1504
1505
  Description: 'No spaces after ( or before ).'
1505
1506
  StyleGuide: '#spaces-braces'
@@ -1615,6 +1616,12 @@ Lint/AmbiguousRegexpLiteral:
1615
1616
  VersionAdded: '0.17'
1616
1617
  VersionChanged: '0.83'
1617
1618
 
1619
+ Lint/ArrayLiteralInRegexp:
1620
+ Description: 'Checks for an array literal interpolated inside a regexp.'
1621
+ Enabled: pending
1622
+ VersionAdded: '1.71'
1623
+ SafeAutoCorrect: false
1624
+
1618
1625
  Lint/AssignmentInCondition:
1619
1626
  Description: "Don't use assignment in conditions."
1620
1627
  StyleGuide: '#safe-assignment-in-condition'
@@ -1634,7 +1641,7 @@ Lint/BinaryOperatorWithIdenticalOperands:
1634
1641
  Enabled: true
1635
1642
  Safe: false
1636
1643
  VersionAdded: '0.89'
1637
- VersionChanged: '1.7'
1644
+ VersionChanged: '1.69'
1638
1645
 
1639
1646
  Lint/BooleanSymbol:
1640
1647
  Description: 'Check for `:true` and `:false` symbols.'
@@ -1664,6 +1671,11 @@ Lint/ConstantOverwrittenInRescue:
1664
1671
  Enabled: pending
1665
1672
  VersionAdded: '1.31'
1666
1673
 
1674
+ Lint/ConstantReassignment:
1675
+ Description: 'Checks for constant reassignments.'
1676
+ Enabled: pending
1677
+ VersionAdded: '1.70'
1678
+
1667
1679
  Lint/ConstantResolution:
1668
1680
  Description: 'Check that constants are fully qualified with `::`.'
1669
1681
  Enabled: false
@@ -1956,6 +1968,11 @@ Lint/HashCompareByIdentity:
1956
1968
  Safe: false
1957
1969
  VersionAdded: '0.93'
1958
1970
 
1971
+ Lint/HashNewWithKeywordArgumentsAsDefault:
1972
+ Description: 'Checks for the deprecated use of keyword arguments for hash default in `Hash.new`.'
1973
+ Enabled: pending
1974
+ VersionAdded: '1.69'
1975
+
1959
1976
  Lint/HeredocMethodCallPosition:
1960
1977
  Description: >-
1961
1978
  Checks for the ordering of a method call where
@@ -2146,6 +2163,11 @@ Lint/NumberedParameterAssignment:
2146
2163
  Enabled: pending
2147
2164
  VersionAdded: '1.9'
2148
2165
 
2166
+ Lint/NumericOperationWithConstantResult:
2167
+ Description: 'Checks for numeric operations with constant results.'
2168
+ Enabled: pending
2169
+ VersionAdded: '1.69'
2170
+
2149
2171
  Lint/OrAssignmentToConstant:
2150
2172
  Description: 'Checks unintended or-assignment to constant.'
2151
2173
  Enabled: pending
@@ -2377,7 +2399,6 @@ Lint/ShadowedArgument:
2377
2399
  VersionAdded: '0.52'
2378
2400
  IgnoreImplicitReferences: false
2379
2401
 
2380
-
2381
2402
  Lint/ShadowedException:
2382
2403
  Description: >-
2383
2404
  Avoid rescuing a higher level exception
@@ -2392,6 +2413,12 @@ Lint/ShadowingOuterLocalVariable:
2392
2413
  Enabled: true
2393
2414
  VersionAdded: '0.9'
2394
2415
 
2416
+ Lint/SharedMutableDefault:
2417
+ Description: 'Checks for mutable literals used as default arguments during Hash initialization.'
2418
+ StyleGuide: '#no-mutable-defaults'
2419
+ Enabled: pending
2420
+ VersionAdded: '1.70'
2421
+
2395
2422
  Lint/StructNewOverride:
2396
2423
  Description: 'Disallow overriding the `Struct` built-in methods via `Struct.new`.'
2397
2424
  Enabled: true
@@ -2521,10 +2548,12 @@ Lint/UnusedMethodArgument:
2521
2548
  Enabled: true
2522
2549
  AutoCorrect: contextual
2523
2550
  VersionAdded: '0.21'
2524
- VersionChanged: '1.61'
2551
+ VersionChanged: '1.69'
2525
2552
  AllowUnusedKeywordArguments: false
2526
2553
  IgnoreEmptyMethods: true
2527
2554
  IgnoreNotImplementedMethods: true
2555
+ NotImplementedExceptions:
2556
+ - NotImplementedError
2528
2557
 
2529
2558
  Lint/UriEscapeUnescape:
2530
2559
  Description: >-
@@ -2559,6 +2588,11 @@ Lint/UselessAssignment:
2559
2588
  VersionAdded: '0.11'
2560
2589
  VersionChanged: '1.66'
2561
2590
 
2591
+ Lint/UselessDefined:
2592
+ Description: 'Checks for calls to `defined?` with strings and symbols. The result of such a call will always be truthy.'
2593
+ Enabled: pending
2594
+ VersionAdded: '1.69'
2595
+
2562
2596
  Lint/UselessElseWithoutRescue:
2563
2597
  Description: 'Checks for useless `else` in `begin..end` without `rescue`.'
2564
2598
  Enabled: true
@@ -3119,13 +3153,14 @@ Style/AccessModifierDeclarations:
3119
3153
  Description: 'Checks style of how access modifiers are used.'
3120
3154
  Enabled: true
3121
3155
  VersionAdded: '0.57'
3122
- VersionChanged: '0.81'
3156
+ VersionChanged: '1.70'
3123
3157
  EnforcedStyle: group
3124
3158
  SupportedStyles:
3125
3159
  - inline
3126
3160
  - group
3127
3161
  AllowModifiersOnSymbols: true
3128
3162
  AllowModifiersOnAttrs: true
3163
+ AllowModifiersOnAliasMethod: true
3129
3164
  SafeAutoCorrect: false
3130
3165
 
3131
3166
  Style/AccessorGrouping:
@@ -3698,6 +3733,12 @@ Style/DefWithParentheses:
3698
3733
  VersionAdded: '0.9'
3699
3734
  VersionChanged: '0.12'
3700
3735
 
3736
+ Style/DigChain:
3737
+ Description: 'Use `dig` with multiple parameters instead of chaining multiple calls.'
3738
+ Enabled: pending
3739
+ Safe: false
3740
+ VersionAdded: '1.69'
3741
+
3701
3742
  Style/Dir:
3702
3743
  Description: >-
3703
3744
  Use the `__dir__` method to retrieve the canonicalized
@@ -3924,12 +3965,24 @@ Style/FileEmpty:
3924
3965
  Safe: false
3925
3966
  VersionAdded: '1.48'
3926
3967
 
3968
+ Style/FileNull:
3969
+ Description: 'Use `File::NULL` instead of hardcoding "dev/null".'
3970
+ Enabled: pending
3971
+ SafeAutoCorrect: false
3972
+ VersionAdded: '1.69'
3973
+
3927
3974
  Style/FileRead:
3928
3975
  Description: 'Favor `File.(bin)read` convenience methods.'
3929
3976
  StyleGuide: '#file-read'
3930
3977
  Enabled: pending
3931
3978
  VersionAdded: '1.24'
3932
3979
 
3980
+ Style/FileTouch:
3981
+ Description: 'Favor `FileUtils.touch` for touching files.'
3982
+ Enabled: pending
3983
+ VersionAdded: '1.69'
3984
+ SafeAutoCorrect: false
3985
+
3933
3986
  Style/FileWrite:
3934
3987
  Description: 'Favor `File.(bin)write` convenience methods.'
3935
3988
  StyleGuide: '#file-write'
@@ -4016,6 +4069,9 @@ Style/FrozenStringLiteralComment:
4016
4069
  # exist in a file.
4017
4070
  - never
4018
4071
  SafeAutoCorrect: false
4072
+ Exclude:
4073
+ # Prevent the Ruby warning: `'frozen_string_literal' is ignored after any tokens` when using Active Admin.
4074
+ - '**/*.arb'
4019
4075
 
4020
4076
  Style/GlobalStdStream:
4021
4077
  Description: 'Enforces the use of `$stdout/$stderr/$stdin` instead of `STDOUT/STDERR/STDIN`.'
@@ -4094,6 +4150,14 @@ Style/HashLikeCase:
4094
4150
  # to trigger this cop
4095
4151
  MinBranchesCount: 3
4096
4152
 
4153
+ Style/HashSlice:
4154
+ Description: >-
4155
+ Checks for usages of `Hash#reject`, `Hash#select`, and `Hash#filter` methods
4156
+ that can be replaced with `Hash#slice` method.
4157
+ Enabled: pending
4158
+ Safe: false
4159
+ VersionAdded: '1.71'
4160
+
4097
4161
  Style/HashSyntax:
4098
4162
  Description: >-
4099
4163
  Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax
@@ -4281,6 +4345,11 @@ Style/IpAddresses:
4281
4345
  - '**/gems.rb'
4282
4346
  - '**/*.gemspec'
4283
4347
 
4348
+ Style/ItAssignment:
4349
+ Description: 'Checks for assignment to `it` inside a block.'
4350
+ Enabled: pending
4351
+ VersionAdded: '1.70'
4352
+
4284
4353
  Style/KeywordArgumentsMerging:
4285
4354
  Description: >-
4286
4355
  When passing an existing hash as keyword arguments, provide additional arguments
@@ -5024,7 +5093,7 @@ Style/RedundantConstantBase:
5024
5093
  VersionAdded: '1.40'
5025
5094
 
5026
5095
  Style/RedundantCurrentDirectoryInPath:
5027
- Description: 'Checks for uses a redundant current directory in path.'
5096
+ Description: 'Checks for a redundant current directory in a path given to `require_relative`.'
5028
5097
  Enabled: pending
5029
5098
  VersionAdded: '1.53'
5030
5099
 
@@ -71,11 +71,11 @@ module RuboCop
71
71
 
72
72
  warn Rainbow("\n#{pluralize(errors.size, 'error')} occurred:").red
73
73
 
74
- errors.each { |error| warn error }
74
+ errors.each { |error| warn Rainbow(error).red }
75
75
 
76
- warn <<~WARNING
76
+ warn Rainbow(<<~WARNING.strip).yellow
77
77
  Errors are usually caused by RuboCop bugs.
78
- Please, report your problems to RuboCop's issue tracker.
78
+ Please, update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version.
79
79
  #{bug_tracker_uri}
80
80
  Mention the following information in the issue report:
81
81
  #{RuboCop::Version.verbose}
@@ -9,11 +9,31 @@ module RuboCop
9
9
  class ShowCops < Base
10
10
  self.command_name = :show_cops
11
11
 
12
+ ExactMatcher = Struct.new(:pattern) do
13
+ def match?(name)
14
+ name == pattern
15
+ end
16
+ end
17
+
18
+ WildcardMatcher = Struct.new(:pattern) do
19
+ def match?(name)
20
+ File.fnmatch(pattern, name, File::FNM_PATHNAME)
21
+ end
22
+ end
23
+
12
24
  def initialize(env)
13
25
  super
14
26
 
15
27
  # Load the configs so the require()s are done for custom cops
16
28
  @config = @config_store.for(Dir.pwd)
29
+
30
+ @cop_matchers = @options[:show_cops].map do |pattern|
31
+ if pattern.include?('*')
32
+ WildcardMatcher.new(pattern)
33
+ else
34
+ ExactMatcher.new(pattern)
35
+ end
36
+ end
17
37
  end
18
38
 
19
39
  def run
@@ -24,7 +44,7 @@ module RuboCop
24
44
 
25
45
  def print_available_cops
26
46
  registry = Cop::Registry.global
27
- show_all = @options[:show_cops].empty?
47
+ show_all = @cop_matchers.empty?
28
48
 
29
49
  puts "# Available cops (#{registry.length}) + config for #{Dir.pwd}: " if show_all
30
50
 
@@ -56,7 +76,9 @@ module RuboCop
56
76
 
57
77
  def selected_cops_of_department(cops, department)
58
78
  cops_of_department(cops, department).select do |cop|
59
- @options[:show_cops].include?(cop.cop_name)
79
+ @cop_matchers.any? do |matcher|
80
+ matcher.match?(cop.cop_name)
81
+ end
60
82
  end
61
83
  end
62
84
 
@@ -87,7 +87,7 @@ module RuboCop
87
87
  next unless directive.enabled?
88
88
  next if directive.all_cops?
89
89
 
90
- cops.merge(directive.cop_names)
90
+ cops.merge(directive.raw_cop_names)
91
91
  end
92
92
  cops
93
93
  end
@@ -16,6 +16,7 @@ module RuboCop
16
16
 
17
17
  CopConfig = Struct.new(:name, :metadata)
18
18
 
19
+ EMPTY_CONFIG = {}.freeze
19
20
  DEFAULT_RAILS_VERSION = 5.0
20
21
  attr_reader :loaded_path
21
22
 
@@ -80,10 +81,7 @@ module RuboCop
80
81
 
81
82
  def make_excludes_absolute
82
83
  each_key do |key|
83
- @validator.validate_section_presence(key)
84
- next unless self[key]['Exclude']
85
-
86
- self[key]['Exclude'].map! do |exclude_elem|
84
+ dig(key, 'Exclude')&.map! do |exclude_elem|
87
85
  if exclude_elem.is_a?(String) && !absolute?(exclude_elem)
88
86
  File.expand_path(File.join(base_dir_for_path_parameters, exclude_elem))
89
87
  else
@@ -123,6 +121,13 @@ module RuboCop
123
121
  @for_cop[cop]
124
122
  end
125
123
 
124
+ # @return [Config, Hash] for the given cop / cop name.
125
+ # If the given cop is enabled, returns its configuration hash.
126
+ # Otherwise, returns an empty hash.
127
+ def for_enabled_cop(cop)
128
+ cop_enabled?(cop) ? for_cop(cop) : EMPTY_CONFIG
129
+ end
130
+
126
131
  # @return [Config] for the given cop merged with that of its department (if any)
127
132
  # Note: the 'Enabled' attribute is same as that returned by `for_cop`
128
133
  def for_badge(badge)
@@ -159,6 +164,10 @@ module RuboCop
159
164
  @for_all_cops ||= self['AllCops'] || {}
160
165
  end
161
166
 
167
+ def cop_enabled?(name)
168
+ !!for_cop(name)['Enabled']
169
+ end
170
+
162
171
  def disabled_new_cops?
163
172
  for_all_cops['NewCops'] == 'disable'
164
173
  end
@@ -41,6 +41,10 @@ module RuboCop
41
41
  def clear_options
42
42
  @debug = nil
43
43
  @loaded_features = Set.new
44
+ @disable_pending_cops = nil
45
+ @enable_pending_cops = nil
46
+ @ignore_parent_exclusion = nil
47
+ @ignore_unrecognized_cops = nil
44
48
  FileFinder.root_level = nil
45
49
  end
46
50
 
@@ -163,14 +163,21 @@ module RuboCop
163
163
  end
164
164
 
165
165
  def warn_on_duplicate_setting(base_hash, derived_hash, key, **opts)
166
+ # If the file being considered is remote, don't bother checking for duplicates
167
+ return if remote_config?(opts[:file])
168
+
166
169
  return unless duplicate_setting?(base_hash, derived_hash, key, opts[:inherited_file])
167
170
 
168
171
  inherit_mode = opts[:inherit_mode]['merge'] || opts[:inherit_mode]['override']
169
172
  return if base_hash[key].is_a?(Array) && inherit_mode&.include?(key)
170
173
 
171
- puts "#{PathUtil.smart_path(opts[:file])}: " \
172
- "#{opts[:cop_name]}:#{key} overrides " \
173
- "the same parameter in #{opts[:inherited_file]}"
174
+ puts duplicate_setting_warning(opts, key)
175
+ end
176
+
177
+ def duplicate_setting_warning(opts, key)
178
+ "#{PathUtil.smart_path(opts[:file])}: " \
179
+ "#{opts[:cop_name]}:#{key} overrides " \
180
+ "the same parameter in #{opts[:inherited_file]}"
174
181
  end
175
182
 
176
183
  def determine_inherit_mode(hash, key)
@@ -242,6 +249,10 @@ module RuboCop
242
249
  uri.start_with?('http://', 'https://')
243
250
  end
244
251
 
252
+ def remote_config?(file)
253
+ file.is_a?(RemoteConfig)
254
+ end
255
+
245
256
  def handle_disabled_by_default(config, new_default_configuration)
246
257
  department_config = config.to_hash.reject { |cop| cop.include?('/') }
247
258
  department_config.each do |dept, dept_params|
@@ -3,6 +3,7 @@
3
3
  module RuboCop
4
4
  # Handles validation of configuration, for example cop names, parameter
5
5
  # names, and Ruby versions.
6
+ # rubocop:disable Metrics/ClassLength
6
7
  class ConfigValidator
7
8
  extend SimpleForwardable
8
9
 
@@ -41,8 +42,9 @@ module RuboCop
41
42
  ConfigLoader.default_configuration.key?(key)
42
43
  end
43
44
 
44
- check_obsoletions
45
+ validate_parameter_shape(valid_cop_names)
45
46
 
47
+ check_obsoletions
46
48
  alert_about_unrecognized_cops(invalid_cop_names)
47
49
  validate_new_cops_parameter
48
50
  validate_parameter_names(valid_cop_names)
@@ -64,12 +66,6 @@ module RuboCop
64
66
  target_ruby.version
65
67
  end
66
68
 
67
- def validate_section_presence(name)
68
- return unless @config.key?(name) && @config[name].nil?
69
-
70
- raise ValidationError, "empty section #{name} found in #{smart_loaded_path}"
71
- end
72
-
73
69
  private
74
70
 
75
71
  attr_reader :target_ruby
@@ -177,9 +173,22 @@ module RuboCop
177
173
  raise ValidationError, message
178
174
  end
179
175
 
176
+ def validate_parameter_shape(valid_cop_names)
177
+ valid_cop_names.each do |name|
178
+ if @config[name].nil?
179
+ raise ValidationError, "empty section #{name.inspect} found in #{smart_loaded_path}"
180
+ elsif !@config[name].is_a?(Hash)
181
+ raise ValidationError, <<~MESSAGE
182
+ The configuration for #{name.inspect} in #{smart_loaded_path} is not a Hash.
183
+
184
+ Found: #{@config[name].inspect}
185
+ MESSAGE
186
+ end
187
+ end
188
+ end
189
+
180
190
  def validate_parameter_names(valid_cop_names)
181
191
  valid_cop_names.each do |name|
182
- validate_section_presence(name)
183
192
  each_invalid_parameter(name) do |param, supported_params|
184
193
  warn Rainbow(<<~MESSAGE).yellow
185
194
  Warning: #{name} does not support #{param} parameter.
@@ -277,4 +286,5 @@ module RuboCop
277
286
  "is supposed to be #{supposed_values} and #{Rainbow(value).yellow} is not."
278
287
  end
279
288
  end
289
+ # rubocop:enable Metrics/ClassLength
280
290
  end
@@ -49,17 +49,31 @@ module RuboCop
49
49
  private
50
50
 
51
51
  def disable_offense(offense_range)
52
- range = surrounding_heredoc(offense_range) ||
53
- surrounding_percent_array(offense_range) ||
54
- string_continuation(offense_range)
52
+ unbreakable_range = multiline_ranges(offense_range)&.find do |range|
53
+ range_overlaps_offense?(offense_range, range)
54
+ end
55
55
 
56
- if range
57
- disable_offense_before_and_after(range_by_lines(range))
56
+ if unbreakable_range
57
+ disable_offense_before_and_after(range_by_lines(unbreakable_range))
58
58
  else
59
59
  disable_offense_with_eol_or_surround_comment(offense_range)
60
60
  end
61
61
  end
62
62
 
63
+ def multiline_ranges(offense_range)
64
+ return if offense_range.empty?
65
+
66
+ processed_source.ast.each_node.filter_map do |node|
67
+ if surrounding_heredoc?(node)
68
+ heredoc_range(node)
69
+ elsif string_continuation?(node)
70
+ range_by_lines(node.source_range)
71
+ elsif surrounding_percent_array?(node) || multiline_string?(node)
72
+ node.source_range
73
+ end
74
+ end
75
+ end
76
+
63
77
  def disable_offense_with_eol_or_surround_comment(range)
64
78
  eol_comment = " # rubocop:todo #{cop_name}"
65
79
  needed_line_length = (range.source_line + eol_comment).length
@@ -71,45 +85,28 @@ module RuboCop
71
85
  end
72
86
  end
73
87
 
74
- def surrounding_heredoc(offense_range)
75
- # The empty offense range is an edge case that can be reached from the Lint/Syntax cop.
76
- return nil if offense_range.empty?
77
-
78
- heredoc_nodes = processed_source.ast.each_descendant.select do |node|
79
- node.respond_to?(:heredoc?) && node.heredoc?
80
- end
81
- heredoc_nodes.map { |node| node.source_range.join(node.loc.heredoc_end) }
82
- .find { |range| range.contains?(offense_range) }
88
+ def range_overlaps_offense?(offense_range, range)
89
+ offense_range.begin_pos > range.begin_pos && range.overlaps?(offense_range)
83
90
  end
84
91
 
85
- def surrounding_percent_array(offense_range)
86
- return nil if offense_range.empty?
87
-
88
- percent_array = processed_source.ast.each_descendant.select do |node|
89
- node.array_type? && node.percent_literal?
90
- end
91
-
92
- percent_array.map(&:source_range).find do |range|
93
- range_overlaps_offense?(offense_range, range)
94
- end
92
+ def surrounding_heredoc?(node)
93
+ node.type?(:str, :dstr, :xstr) && node.heredoc?
95
94
  end
96
95
 
97
- def string_continuation(offense_range)
98
- return nil if offense_range.empty?
99
-
100
- string_continuation_nodes = processed_source.ast.each_descendant.filter_map do |node|
101
- range_by_lines(node.source_range) if string_continuation?(node)
102
- end
103
-
104
- string_continuation_nodes.find { |range| range_overlaps_offense?(offense_range, range) }
96
+ def heredoc_range(node)
97
+ node.source_range.join(node.loc.heredoc_end)
105
98
  end
106
99
 
107
- def range_overlaps_offense?(offense_range, range)
108
- offense_range.begin_pos > range.begin_pos && range.overlaps?(offense_range)
100
+ def surrounding_percent_array?(node)
101
+ node.array_type? && node.percent_literal?
109
102
  end
110
103
 
111
104
  def string_continuation?(node)
112
- (node.str_type? || node.dstr_type? || node.xstr_type?) && node.source.match?(/\\\s*$/)
105
+ node.type?(:str, :dstr, :xstr) && node.source.match?(/\\\s*$/)
106
+ end
107
+
108
+ def multiline_string?(node)
109
+ node.dstr_type? && node.multiline?
113
110
  end
114
111
 
115
112
  def range_of_first_line(range)
@@ -60,7 +60,7 @@ module RuboCop
60
60
  []
61
61
  end
62
62
 
63
- # Returns an url to view this cops documentation online.
63
+ # Returns a url to view this cops documentation online.
64
64
  # Requires 'DocumentationBaseURL' to be set for your department.
65
65
  # Will follow the convention of RuboCops own documentation structure,
66
66
  # overwrite this method to accommodate your custom layout.
@@ -261,6 +261,12 @@ module RuboCop
261
261
  @config.target_ruby_version
262
262
  end
263
263
 
264
+ # Returns a gems locked versions (i.e. from Gemfile.lock or gems.locked)
265
+ # @returns [Gem::Version | nil] The locked gem version, or nil if the gem is not present.
266
+ def target_gem_version(gem_name)
267
+ @config.gem_versions_in_target && @config.gem_versions_in_target[gem_name]
268
+ end
269
+
264
270
  def parser_engine
265
271
  @config.parser_engine
266
272
  end
@@ -66,14 +66,14 @@ module RuboCop
66
66
 
67
67
  def conditional_declaration?(nodes)
68
68
  parent = nodes[0].each_ancestor.find { |ancestor| !ancestor.begin_type? }
69
- return false unless parent&.if_type? || parent&.when_type?
69
+ return false unless parent&.type?(:if, :when)
70
70
 
71
71
  root_conditional_node = parent.if_type? ? parent : parent.parent
72
72
  nodes.all? { |node| within_conditional?(node, root_conditional_node) }
73
73
  end
74
74
 
75
75
  def within_conditional?(node, conditional_node)
76
- conditional_node.branches.any? do |branch|
76
+ conditional_node.branches.compact.any? do |branch|
77
77
  branch == node || branch.child_nodes.include?(node)
78
78
  end
79
79
  end
@@ -161,7 +161,7 @@ module RuboCop
161
161
  end
162
162
 
163
163
  def gem_options(node)
164
- return [] unless node.last_argument&.type == :hash
164
+ return [] unless node.last_argument&.hash_type?
165
165
 
166
166
  node.last_argument.keys.map(&:value)
167
167
  end
@@ -27,7 +27,6 @@ module RuboCop
27
27
  # Project contains gems.rb and gems.locked files
28
28
  class GemFilename < Base
29
29
  include ConfigurableEnforcedStyle
30
- include RangeHelp
31
30
 
32
31
  MSG_GEMFILE_REQUIRED = '`gems.rb` file was found but `Gemfile` is required ' \
33
32
  '(file path: %<file_path>s).'
@@ -39,7 +39,6 @@ module RuboCop
39
39
  # source 'http://rubygems.org'
40
40
  #
41
41
  class InsecureProtocolSource < Base
42
- include RangeHelp
43
42
  extend AutoCorrector
44
43
 
45
44
  MSG = 'The source `:%<source>s` is deprecated because HTTP requests ' \
@@ -39,7 +39,7 @@ module RuboCop
39
39
  def requires_parentheses?
40
40
  return true if collection_node.send_type? && collection_node.operator_method?
41
41
 
42
- collection_node.range_type? || collection_node.or_type? || collection_node.and_type?
42
+ collection_node.range_type? || collection_node.operator_keyword?
43
43
  end
44
44
 
45
45
  def end_range