rubocop 1.66.1 → 1.69.1

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 (246) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +96 -12
  4. data/config/internal_affairs.yml +11 -0
  5. data/lib/rubocop/cached_data.rb +12 -4
  6. data/lib/rubocop/cli/command/auto_generate_config.rb +6 -7
  7. data/lib/rubocop/cli/command/execute_runner.rb +1 -1
  8. data/lib/rubocop/cli/command/lsp.rb +2 -2
  9. data/lib/rubocop/cli/command/version.rb +2 -2
  10. data/lib/rubocop/config_loader_resolver.rb +3 -3
  11. data/lib/rubocop/config_validator.rb +2 -1
  12. data/lib/rubocop/cop/autocorrect_logic.rb +22 -2
  13. data/lib/rubocop/cop/base.rb +7 -3
  14. data/lib/rubocop/cop/bundler/gem_filename.rb +0 -1
  15. data/lib/rubocop/cop/bundler/gem_version.rb +1 -0
  16. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +0 -1
  17. data/lib/rubocop/cop/cop.rb +8 -0
  18. data/lib/rubocop/cop/correctors/alignment_corrector.rb +1 -12
  19. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +1 -1
  20. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
  21. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +10 -0
  22. data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +1 -2
  23. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +0 -2
  24. data/lib/rubocop/cop/generator.rb +6 -0
  25. data/lib/rubocop/cop/internal_affairs/cop_description.rb +0 -4
  26. data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +3 -4
  27. data/lib/rubocop/cop/internal_affairs/numblock_handler.rb +1 -1
  28. data/lib/rubocop/cop/internal_affairs/operator_keyword.rb +46 -0
  29. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +6 -21
  30. data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +8 -1
  31. data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +0 -2
  32. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +0 -5
  33. data/lib/rubocop/cop/internal_affairs.rb +17 -0
  34. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +5 -1
  35. data/lib/rubocop/cop/layout/argument_alignment.rb +1 -2
  36. data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
  37. data/lib/rubocop/cop/layout/begin_end_alignment.rb +0 -1
  38. data/lib/rubocop/cop/layout/block_alignment.rb +1 -2
  39. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  40. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +2 -2
  41. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -3
  42. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +3 -4
  43. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +3 -1
  44. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +8 -0
  45. data/lib/rubocop/cop/layout/indentation_width.rb +11 -12
  46. data/lib/rubocop/cop/layout/leading_comment_space.rb +71 -1
  47. data/lib/rubocop/cop/layout/line_length.rb +118 -4
  48. data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -1
  49. data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +1 -1
  50. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +2 -3
  51. data/lib/rubocop/cop/layout/parameter_alignment.rb +3 -4
  52. data/lib/rubocop/cop/layout/redundant_line_break.rb +3 -35
  53. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -2
  54. data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
  55. data/lib/rubocop/cop/layout/space_around_operators.rb +16 -17
  56. data/lib/rubocop/cop/layout/space_before_brackets.rb +5 -5
  57. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +6 -0
  58. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +4 -0
  59. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +4 -0
  60. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +0 -1
  61. data/lib/rubocop/cop/lint/ambiguous_range.rb +4 -1
  62. data/lib/rubocop/cop/lint/big_decimal_new.rb +4 -7
  63. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +10 -12
  64. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
  65. data/lib/rubocop/cop/lint/circular_argument_reference.rb +6 -0
  66. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +2 -1
  67. data/lib/rubocop/cop/lint/duplicate_branch.rb +39 -4
  68. data/lib/rubocop/cop/lint/duplicate_set_element.rb +74 -0
  69. data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
  70. data/lib/rubocop/cop/lint/empty_file.rb +0 -2
  71. data/lib/rubocop/cop/lint/ensure_return.rb +1 -4
  72. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
  73. data/lib/rubocop/cop/lint/float_comparison.rb +15 -7
  74. data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -3
  75. data/lib/rubocop/cop/lint/hash_new_with_keyword_arguments_as_default.rb +55 -0
  76. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +10 -4
  77. data/lib/rubocop/cop/lint/interpolation_check.rb +9 -0
  78. data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +8 -14
  79. data/lib/rubocop/cop/lint/literal_as_condition.rb +1 -0
  80. data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +1 -1
  81. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +25 -2
  82. data/lib/rubocop/cop/lint/mixed_case_range.rb +2 -5
  83. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
  84. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +2 -2
  85. data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +8 -1
  86. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +3 -3
  87. data/lib/rubocop/cop/lint/number_conversion.rb +0 -1
  88. data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +1 -2
  89. data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +106 -0
  90. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -2
  91. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +1 -1
  92. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +5 -6
  93. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +1 -1
  94. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +13 -8
  95. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +8 -7
  96. data/lib/rubocop/cop/lint/refinement_import_methods.rb +1 -1
  97. data/lib/rubocop/cop/lint/regexp_as_condition.rb +0 -1
  98. data/lib/rubocop/cop/lint/rescue_type.rb +3 -7
  99. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +9 -0
  100. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +109 -41
  101. data/lib/rubocop/cop/lint/self_assignment.rb +8 -10
  102. data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
  103. data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
  104. data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +91 -0
  105. data/lib/rubocop/cop/lint/unreachable_code.rb +51 -2
  106. data/lib/rubocop/cop/lint/unused_method_argument.rb +18 -2
  107. data/lib/rubocop/cop/lint/uri_regexp.rb +25 -7
  108. data/lib/rubocop/cop/lint/useless_defined.rb +55 -0
  109. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +4 -0
  110. data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
  111. data/lib/rubocop/cop/lint/useless_setter_call.rb +14 -25
  112. data/lib/rubocop/cop/lint/void.rb +3 -2
  113. data/lib/rubocop/cop/metrics/class_length.rb +7 -7
  114. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +4 -1
  115. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
  116. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +2 -3
  117. data/lib/rubocop/cop/mixin/check_assignment.rb +4 -12
  118. data/lib/rubocop/cop/mixin/check_line_breakable.rb +10 -0
  119. data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +49 -0
  120. data/lib/rubocop/cop/mixin/dig_help.rb +27 -0
  121. data/lib/rubocop/cop/mixin/endless_method_rewriter.rb +24 -0
  122. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +3 -1
  123. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +5 -9
  124. data/lib/rubocop/cop/mixin/percent_array.rb +1 -1
  125. data/lib/rubocop/cop/mixin/range_help.rb +0 -1
  126. data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -2
  127. data/lib/rubocop/cop/mixin/target_ruby_version.rb +17 -1
  128. data/lib/rubocop/cop/naming/accessor_method_name.rb +6 -6
  129. data/lib/rubocop/cop/naming/block_forwarding.rb +1 -1
  130. data/lib/rubocop/cop/naming/constant_name.rb +6 -7
  131. data/lib/rubocop/cop/naming/file_name.rb +0 -2
  132. data/lib/rubocop/cop/naming/inclusive_language.rb +12 -3
  133. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +11 -12
  134. data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
  135. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +3 -11
  136. data/lib/rubocop/cop/naming/variable_name.rb +3 -4
  137. data/lib/rubocop/cop/naming/variable_number.rb +2 -3
  138. data/lib/rubocop/cop/offense.rb +4 -5
  139. data/lib/rubocop/cop/security/compound_hash.rb +1 -0
  140. data/lib/rubocop/cop/security/yaml_load.rb +3 -2
  141. data/lib/rubocop/cop/style/access_modifier_declarations.rb +64 -25
  142. data/lib/rubocop/cop/style/accessor_grouping.rb +10 -2
  143. data/lib/rubocop/cop/style/ambiguous_endless_method_definition.rb +79 -0
  144. data/lib/rubocop/cop/style/arguments_forwarding.rb +46 -6
  145. data/lib/rubocop/cop/style/array_intersect.rb +5 -4
  146. data/lib/rubocop/cop/style/bitwise_predicate.rb +100 -0
  147. data/lib/rubocop/cop/style/block_delimiters.rb +41 -5
  148. data/lib/rubocop/cop/style/case_like_if.rb +8 -11
  149. data/lib/rubocop/cop/style/collection_compact.rb +10 -10
  150. data/lib/rubocop/cop/style/combinable_defined.rb +115 -0
  151. data/lib/rubocop/cop/style/combinable_loops.rb +7 -0
  152. data/lib/rubocop/cop/style/commented_keyword.rb +17 -1
  153. data/lib/rubocop/cop/style/conditional_assignment.rb +20 -22
  154. data/lib/rubocop/cop/style/constant_visibility.rb +3 -12
  155. data/lib/rubocop/cop/style/data_inheritance.rb +1 -1
  156. data/lib/rubocop/cop/style/dig_chain.rb +89 -0
  157. data/lib/rubocop/cop/style/endless_method.rb +1 -14
  158. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  159. data/lib/rubocop/cop/style/fetch_env_var.rb +1 -0
  160. data/lib/rubocop/cop/style/file_null.rb +73 -0
  161. data/lib/rubocop/cop/style/file_touch.rb +75 -0
  162. data/lib/rubocop/cop/style/for.rb +0 -1
  163. data/lib/rubocop/cop/style/global_vars.rb +1 -3
  164. data/lib/rubocop/cop/style/guard_clause.rb +16 -3
  165. data/lib/rubocop/cop/style/hash_conversion.rb +1 -2
  166. data/lib/rubocop/cop/style/hash_each_methods.rb +6 -0
  167. data/lib/rubocop/cop/style/hash_except.rb +19 -7
  168. data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
  169. data/lib/rubocop/cop/style/if_inside_else.rb +1 -2
  170. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -2
  171. data/lib/rubocop/cop/style/if_with_semicolon.rb +20 -7
  172. data/lib/rubocop/cop/style/inverse_methods.rb +0 -1
  173. data/lib/rubocop/cop/style/keyword_arguments_merging.rb +67 -0
  174. data/lib/rubocop/cop/style/lambda.rb +1 -1
  175. data/lib/rubocop/cop/style/lambda_call.rb +3 -2
  176. data/lib/rubocop/cop/style/map_into_array.rb +59 -8
  177. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +13 -8
  178. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +7 -11
  179. data/lib/rubocop/cop/style/missing_respond_to_missing.rb +33 -3
  180. data/lib/rubocop/cop/style/multiline_memoization.rb +2 -2
  181. data/lib/rubocop/cop/style/multiple_comparison.rb +28 -39
  182. data/lib/rubocop/cop/style/mutable_constant.rb +4 -5
  183. data/lib/rubocop/cop/style/negated_if_else_condition.rb +6 -4
  184. data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
  185. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
  186. data/lib/rubocop/cop/style/nested_ternary_operator.rb +5 -4
  187. data/lib/rubocop/cop/style/not.rb +1 -1
  188. data/lib/rubocop/cop/style/object_then.rb +1 -0
  189. data/lib/rubocop/cop/style/one_line_conditional.rb +29 -4
  190. data/lib/rubocop/cop/style/operator_method_call.rb +25 -7
  191. data/lib/rubocop/cop/style/or_assignment.rb +3 -6
  192. data/lib/rubocop/cop/style/parallel_assignment.rb +8 -13
  193. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  194. data/lib/rubocop/cop/style/redundant_argument.rb +3 -1
  195. data/lib/rubocop/cop/style/redundant_assignment.rb +1 -1
  196. data/lib/rubocop/cop/style/redundant_begin.rb +4 -0
  197. data/lib/rubocop/cop/style/redundant_condition.rb +37 -22
  198. data/lib/rubocop/cop/style/redundant_line_continuation.rb +24 -5
  199. data/lib/rubocop/cop/style/redundant_parentheses.rb +11 -13
  200. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +1 -0
  201. data/lib/rubocop/cop/style/redundant_return.rb +2 -2
  202. data/lib/rubocop/cop/style/redundant_self.rb +8 -15
  203. data/lib/rubocop/cop/style/redundant_self_assignment.rb +7 -5
  204. data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +4 -4
  205. data/lib/rubocop/cop/style/redundant_sort.rb +1 -1
  206. data/lib/rubocop/cop/style/require_order.rb +1 -1
  207. data/lib/rubocop/cop/style/rescue_modifier.rb +15 -4
  208. data/lib/rubocop/cop/style/return_nil_in_predicate_method_definition.rb +54 -12
  209. data/lib/rubocop/cop/style/safe_navigation.rb +104 -50
  210. data/lib/rubocop/cop/style/safe_navigation_chain_length.rb +52 -0
  211. data/lib/rubocop/cop/style/select_by_regexp.rb +10 -7
  212. data/lib/rubocop/cop/style/self_assignment.rb +11 -17
  213. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  214. data/lib/rubocop/cop/style/signal_exception.rb +2 -3
  215. data/lib/rubocop/cop/style/single_argument_dig.rb +9 -5
  216. data/lib/rubocop/cop/style/single_line_do_end_block.rb +13 -3
  217. data/lib/rubocop/cop/style/sole_nested_conditional.rb +2 -3
  218. data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
  219. data/lib/rubocop/cop/style/string_concatenation.rb +13 -12
  220. data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
  221. data/lib/rubocop/cop/style/swap_values.rb +4 -15
  222. data/lib/rubocop/cop/style/ternary_parentheses.rb +26 -5
  223. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +4 -4
  224. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  225. data/lib/rubocop/cop/style/variable_interpolation.rb +1 -2
  226. data/lib/rubocop/cop/team.rb +8 -1
  227. data/lib/rubocop/cop/util.rb +1 -1
  228. data/lib/rubocop/cop/variable_force/assignment.rb +18 -3
  229. data/lib/rubocop/cop/variable_force/branch.rb +1 -1
  230. data/lib/rubocop/cop/variable_force/variable.rb +5 -1
  231. data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
  232. data/lib/rubocop/cop/variable_force.rb +4 -10
  233. data/lib/rubocop/cops_documentation_generator.rb +90 -41
  234. data/lib/rubocop/file_finder.rb +9 -4
  235. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  236. data/lib/rubocop/lsp/runtime.rb +2 -0
  237. data/lib/rubocop/lsp/server.rb +0 -1
  238. data/lib/rubocop/rspec/expect_offense.rb +1 -0
  239. data/lib/rubocop/runner.rb +17 -6
  240. data/lib/rubocop/server/cache.rb +6 -1
  241. data/lib/rubocop/server/core.rb +1 -0
  242. data/lib/rubocop/target_ruby.rb +13 -13
  243. data/lib/rubocop/version.rb +28 -7
  244. data/lib/rubocop/yaml_duplication_checker.rb +20 -27
  245. data/lib/rubocop.rb +18 -0
  246. metadata +32 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a10568527197e80492a28c5b524fa524dbce965513daff4f47e260e03b49d98
4
- data.tar.gz: 8ea447437cbd36aa805b3941cf51b07eecc9dc538ed6a4584f09a1335e21cb48
3
+ metadata.gz: 8ab30572529c057731f5ebd7548808a1aa9f588f75a45ec0d41ecec2dbbc8015
4
+ data.tar.gz: 9beff10b3b9361a9ffc58c0da4920c9c7c7d1caa09e813ea96c46cd7f01683a4
5
5
  SHA512:
6
- metadata.gz: 1f292c70ffac1cb186e5be899582c4849a29866722c87ab92a60a723dd16fe86fdf12073c8a7190bba197d246eae3b25ba3cdc6b586b28061cef39ac22b3b438
7
- data.tar.gz: 2dbfc28779854fae0d28fd266ba269b92cb0e3b5c26200aa250df02ff9810804b7b1fcc289a43bac1913dc04c79f788487f9351444f7242cbcdad6854a821d69
6
+ metadata.gz: a1fdca8813de85e849ba3ff5266c589b74986984192247fc53c541c81475ae672788a663444070fc5428cbfd1024de7cccc9ac7924fe0dab8e138069b3f6b8f7
7
+ data.tar.gz: 7896834ccaa34e897da918b457b7ab2c738e21b474536144ddbaf71af2d5ae1e829fdeb699701323f6c67d85cb7b2fb1adcc21f3fde1683cb6273387cd390ba2
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.66', require: false
55
+ gem 'rubocop', '~> 1.69', require: false
56
56
  ```
57
57
 
58
58
  See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
data/config/default.yml CHANGED
@@ -861,6 +861,7 @@ Layout/FirstMethodArgumentLineBreak:
861
861
  Enabled: false
862
862
  VersionAdded: '0.49'
863
863
  AllowMultilineFinalElement: false
864
+ AllowedMethods: []
864
865
 
865
866
  Layout/FirstMethodParameterLineBreak:
866
867
  Description: >-
@@ -1036,6 +1037,8 @@ Layout/LeadingCommentSpace:
1036
1037
  VersionChanged: '0.73'
1037
1038
  AllowDoxygenCommentStyle: false
1038
1039
  AllowGemfileRubyComment: false
1040
+ AllowRBSInlineAnnotation: false
1041
+ AllowSteepAnnotation: false
1039
1042
 
1040
1043
  Layout/LeadingEmptyLines:
1041
1044
  Description: Check for unnecessary blank lines at the beginning of a file.
@@ -1083,11 +1086,11 @@ Layout/LineLength:
1083
1086
  StyleGuide: '#max-line-length'
1084
1087
  Enabled: true
1085
1088
  VersionAdded: '0.25'
1086
- VersionChanged: '1.4'
1089
+ VersionChanged: '1.69'
1087
1090
  Max: 120
1091
+ AllowHeredoc: true
1088
1092
  # To make it possible to copy or click on URIs in the code, we allow lines
1089
1093
  # containing a URI to be longer than Max.
1090
- AllowHeredoc: true
1091
1094
  AllowURI: true
1092
1095
  URISchemes:
1093
1096
  - http
@@ -1099,6 +1102,8 @@ Layout/LineLength:
1099
1102
  # elements. Strings will be converted to Regexp objects. A line that matches
1100
1103
  # any regular expression listed in this option will be ignored by LineLength.
1101
1104
  AllowedPatterns: []
1105
+ # If SplitStrings is true, long strings will be split using continuations
1106
+ SplitStrings: false
1102
1107
 
1103
1108
  Layout/MultilineArrayBraceLayout:
1104
1109
  Description: >-
@@ -1496,7 +1501,6 @@ Layout/SpaceInsideHashLiteralBraces:
1496
1501
  - space
1497
1502
  - no_space
1498
1503
 
1499
-
1500
1504
  Layout/SpaceInsideParens:
1501
1505
  Description: 'No spaces after ( or before ).'
1502
1506
  StyleGuide: '#spaces-braces'
@@ -1631,7 +1635,7 @@ Lint/BinaryOperatorWithIdenticalOperands:
1631
1635
  Enabled: true
1632
1636
  Safe: false
1633
1637
  VersionAdded: '0.89'
1634
- VersionChanged: '1.7'
1638
+ VersionChanged: '1.69'
1635
1639
 
1636
1640
  Lint/BooleanSymbol:
1637
1641
  Description: 'Check for `:true` and `:false` symbols.'
@@ -1783,6 +1787,7 @@ Lint/DuplicateBranch:
1783
1787
  VersionChanged: '1.7'
1784
1788
  IgnoreLiteralBranches: false
1785
1789
  IgnoreConstantBranches: false
1790
+ IgnoreDuplicateElseBranch: false
1786
1791
 
1787
1792
  Lint/DuplicateCaseCondition:
1788
1793
  Description: 'Do not repeat values in case conditionals.'
@@ -1832,6 +1837,11 @@ Lint/DuplicateRescueException:
1832
1837
  Enabled: true
1833
1838
  VersionAdded: '0.89'
1834
1839
 
1840
+ Lint/DuplicateSetElement:
1841
+ Description: 'Checks for duplicate elements in Set.'
1842
+ Enabled: pending
1843
+ VersionAdded: '1.67'
1844
+
1835
1845
  Lint/EachWithObjectArgument:
1836
1846
  Description: 'Check for immutable argument given to each_with_object.'
1837
1847
  Enabled: true
@@ -1947,6 +1957,11 @@ Lint/HashCompareByIdentity:
1947
1957
  Safe: false
1948
1958
  VersionAdded: '0.93'
1949
1959
 
1960
+ Lint/HashNewWithKeywordArgumentsAsDefault:
1961
+ Description: 'Checks for the deprecated use of keyword arguments for hash default in `Hash.new`.'
1962
+ Enabled: pending
1963
+ VersionAdded: '1.69'
1964
+
1950
1965
  Lint/HeredocMethodCallPosition:
1951
1966
  Description: >-
1952
1967
  Checks for the ordering of a method call where
@@ -2137,6 +2152,11 @@ Lint/NumberedParameterAssignment:
2137
2152
  Enabled: pending
2138
2153
  VersionAdded: '1.9'
2139
2154
 
2155
+ Lint/NumericOperationWithConstantResult:
2156
+ Description: 'Checks for numeric operations with constant results.'
2157
+ Enabled: pending
2158
+ VersionAdded: '1.69'
2159
+
2140
2160
  Lint/OrAssignmentToConstant:
2141
2161
  Description: 'Checks unintended or-assignment to constant.'
2142
2162
  Enabled: pending
@@ -2327,9 +2347,9 @@ Lint/SafeNavigationChain:
2327
2347
 
2328
2348
  Lint/SafeNavigationConsistency:
2329
2349
  Description: >-
2330
- Check to make sure that if safe navigation is used for a method
2331
- call in an `&&` or `||` condition that safe navigation is used
2332
- for all method calls on that same object.
2350
+ Check to make sure that if safe navigation is used in an `&&` or `||` condition,
2351
+ consistent and appropriate safe navigation, without excess or deficiency,
2352
+ is used for all method calls on the same object.
2333
2353
  Enabled: true
2334
2354
  VersionAdded: '0.55'
2335
2355
  VersionChanged: '0.77'
@@ -2368,7 +2388,6 @@ Lint/ShadowedArgument:
2368
2388
  VersionAdded: '0.52'
2369
2389
  IgnoreImplicitReferences: false
2370
2390
 
2371
-
2372
2391
  Lint/ShadowedException:
2373
2392
  Description: >-
2374
2393
  Avoid rescuing a higher level exception
@@ -2448,6 +2467,11 @@ Lint/UnderscorePrefixedVariableName:
2448
2467
  VersionAdded: '0.21'
2449
2468
  AllowKeywordBlockArguments: false
2450
2469
 
2470
+ Lint/UnescapedBracketInRegexp:
2471
+ Description: 'Checks for unescaped literal `]` in Regexp.'
2472
+ Enabled: pending
2473
+ VersionAdded: '1.68'
2474
+
2451
2475
  Lint/UnexpectedBlockArity:
2452
2476
  Description: 'Looks for blocks that have fewer arguments that the calling method expects.'
2453
2477
  Enabled: pending
@@ -2507,10 +2531,12 @@ Lint/UnusedMethodArgument:
2507
2531
  Enabled: true
2508
2532
  AutoCorrect: contextual
2509
2533
  VersionAdded: '0.21'
2510
- VersionChanged: '1.61'
2534
+ VersionChanged: '1.69'
2511
2535
  AllowUnusedKeywordArguments: false
2512
2536
  IgnoreEmptyMethods: true
2513
2537
  IgnoreNotImplementedMethods: true
2538
+ NotImplementedExceptions:
2539
+ - NotImplementedError
2514
2540
 
2515
2541
  Lint/UriEscapeUnescape:
2516
2542
  Description: >-
@@ -2545,6 +2571,11 @@ Lint/UselessAssignment:
2545
2571
  VersionAdded: '0.11'
2546
2572
  VersionChanged: '1.66'
2547
2573
 
2574
+ Lint/UselessDefined:
2575
+ Description: 'Checks for calls to `defined?` with strings and symbols. The result of such a call will always be truthy.'
2576
+ Enabled: pending
2577
+ VersionAdded: '1.69'
2578
+
2548
2579
  Lint/UselessElseWithoutRescue:
2549
2580
  Description: 'Checks for useless `else` in `begin..end` without `rescue`.'
2550
2581
  Enabled: true
@@ -3136,6 +3167,12 @@ Style/Alias:
3136
3167
  - prefer_alias
3137
3168
  - prefer_alias_method
3138
3169
 
3170
+ Style/AmbiguousEndlessMethodDefinition:
3171
+ Description: 'Checks for endless methods inside operators of lower precedence.'
3172
+ StyleGuide: '#ambiguous-endless-method-defintions'
3173
+ Enabled: pending
3174
+ VersionAdded: '1.68'
3175
+
3139
3176
  Style/AndOr:
3140
3177
  Description: 'Use &&/|| instead of and/or.'
3141
3178
  StyleGuide: '#no-and-or-or'
@@ -3243,6 +3280,13 @@ Style/BisectedAttrAccessor:
3243
3280
  Enabled: true
3244
3281
  VersionAdded: '0.87'
3245
3282
 
3283
+ Style/BitwisePredicate:
3284
+ Description: 'Prefer bitwise predicate methods over direct comparison operations.'
3285
+ StyleGuide: '#bitwise-predicate-methods'
3286
+ Enabled: pending
3287
+ Safe: false
3288
+ VersionAdded: '1.68'
3289
+
3246
3290
  Style/BlockComments:
3247
3291
  Description: 'Do not use block comments.'
3248
3292
  StyleGuide: '#no-block-comments'
@@ -3526,6 +3570,11 @@ Style/ColonMethodDefinition:
3526
3570
  Enabled: true
3527
3571
  VersionAdded: '0.52'
3528
3572
 
3573
+ Style/CombinableDefined:
3574
+ Description: 'Checks successive `defined?` calls that can be combined into a single call.'
3575
+ Enabled: pending
3576
+ VersionAdded: '1.68'
3577
+
3529
3578
  Style/CombinableLoops:
3530
3579
  Description: >-
3531
3580
  Checks for places where multiple consecutive loops over the same data
@@ -3666,6 +3715,12 @@ Style/DefWithParentheses:
3666
3715
  VersionAdded: '0.9'
3667
3716
  VersionChanged: '0.12'
3668
3717
 
3718
+ Style/DigChain:
3719
+ Description: 'Use `dig` with multiple parameters instead of chaining multiple calls.'
3720
+ Enabled: pending
3721
+ Safe: false
3722
+ VersionAdded: '1.69'
3723
+
3669
3724
  Style/Dir:
3670
3725
  Description: >-
3671
3726
  Use the `__dir__` method to retrieve the canonicalized
@@ -3892,12 +3947,24 @@ Style/FileEmpty:
3892
3947
  Safe: false
3893
3948
  VersionAdded: '1.48'
3894
3949
 
3950
+ Style/FileNull:
3951
+ Description: 'Use `File::NULL` instead of hardcoding "dev/null".'
3952
+ Enabled: pending
3953
+ SafeAutoCorrect: false
3954
+ VersionAdded: '1.69'
3955
+
3895
3956
  Style/FileRead:
3896
3957
  Description: 'Favor `File.(bin)read` convenience methods.'
3897
3958
  StyleGuide: '#file-read'
3898
3959
  Enabled: pending
3899
3960
  VersionAdded: '1.24'
3900
3961
 
3962
+ Style/FileTouch:
3963
+ Description: 'Favor `FileUtils.touch` for touching files.'
3964
+ Enabled: pending
3965
+ VersionAdded: '1.69'
3966
+ SafeAutoCorrect: false
3967
+
3901
3968
  Style/FileWrite:
3902
3969
  Description: 'Favor `File.(bin)write` convenience methods.'
3903
3970
  StyleGuide: '#file-write'
@@ -4069,7 +4136,7 @@ Style/HashSyntax:
4069
4136
  StyleGuide: '#hash-literals'
4070
4137
  Enabled: true
4071
4138
  VersionAdded: '0.9'
4072
- VersionChanged: '1.24'
4139
+ VersionChanged: '1.67'
4073
4140
  EnforcedStyle: ruby19
4074
4141
  SupportedStyles:
4075
4142
  # checks for 1.9 syntax (e.g. {a: 1}) for all symbol keys
@@ -4081,7 +4148,7 @@ Style/HashSyntax:
4081
4148
  # enforces both ruby19 and no_mixed_keys styles
4082
4149
  - ruby19_no_mixed_keys
4083
4150
  # Force hashes that have a hash value omission
4084
- EnforcedShorthandSyntax: always
4151
+ EnforcedShorthandSyntax: either
4085
4152
  SupportedShorthandSyntax:
4086
4153
  # forces use of the 3.1 syntax (e.g. {foo:}) when the hash key and value are the same.
4087
4154
  - always
@@ -4249,6 +4316,14 @@ Style/IpAddresses:
4249
4316
  - '**/gems.rb'
4250
4317
  - '**/*.gemspec'
4251
4318
 
4319
+ Style/KeywordArgumentsMerging:
4320
+ Description: >-
4321
+ When passing an existing hash as keyword arguments, provide additional arguments
4322
+ directly rather than using `merge`.
4323
+ StyleGuide: '#merging-keyword-arguments'
4324
+ Enabled: pending
4325
+ VersionAdded: '1.68'
4326
+
4252
4327
  Style/KeywordParametersOrder:
4253
4328
  Description: 'Enforces that optional keyword parameters are placed at the end of the parameters list.'
4254
4329
  StyleGuide: '#keyword-parameters-order'
@@ -4318,6 +4393,7 @@ Style/MapIntoArray:
4318
4393
  StyleGuide: '#functional-code'
4319
4394
  Enabled: pending
4320
4395
  VersionAdded: '1.63'
4396
+ VersionChanged: '1.67'
4321
4397
  Safe: false
4322
4398
 
4323
4399
  Style/MapToHash:
@@ -5208,6 +5284,7 @@ Style/ReturnNilInPredicateMethodDefinition:
5208
5284
  AllowedMethods: []
5209
5285
  AllowedPatterns: []
5210
5286
  VersionAdded: '1.53'
5287
+ VersionChanged: '1.67'
5211
5288
 
5212
5289
  Style/SafeNavigation:
5213
5290
  Description: >-
@@ -5218,7 +5295,7 @@ Style/SafeNavigation:
5218
5295
  be `nil` or truthy, but never `false`.
5219
5296
  Enabled: true
5220
5297
  VersionAdded: '0.43'
5221
- VersionChanged: '1.27'
5298
+ VersionChanged: '1.67'
5222
5299
  # Safe navigation may cause a statement to start returning `nil` in addition
5223
5300
  # to whatever it used to return.
5224
5301
  ConvertCodeThatCanStartToReturnNil: false
@@ -5232,6 +5309,13 @@ Style/SafeNavigation:
5232
5309
  # Maximum length of method chains for register an offense.
5233
5310
  MaxChainLength: 2
5234
5311
 
5312
+ Style/SafeNavigationChainLength:
5313
+ Description: 'Enforces safe navigation chains length to not exceed the configured maximum.'
5314
+ StyleGuide: '#safe-navigation'
5315
+ Enabled: pending
5316
+ VersionAdded: '1.68'
5317
+ Max: 2
5318
+
5235
5319
  Style/Sample:
5236
5320
  Description: >-
5237
5321
  Use `sample` instead of `shuffle.first`,
@@ -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'
@@ -45,15 +45,13 @@ 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 = location_from_source_buffer(o, source_buffer)
49
+ location = location_from_source_buffer(o)
52
50
  Cop::Offense.new(o['severity'], location, o['message'], o['cop_name'], o['status'].to_sym)
53
51
  end
54
52
  end
55
53
 
56
- def location_from_source_buffer(offense, source_buffer)
54
+ def location_from_source_buffer(offense)
57
55
  begin_pos = offense['location']['begin_pos']
58
56
  end_pos = offense['location']['end_pos']
59
57
  if begin_pos.zero? && end_pos.zero?
@@ -62,5 +60,15 @@ module RuboCop
62
60
  Parser::Source::Range.new(source_buffer, begin_pos, end_pos)
63
61
  end
64
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
65
73
  end
66
74
  end
@@ -151,16 +151,15 @@ module RuboCop
151
151
  end
152
152
 
153
153
  def relative_path_to_todo_from_options_config
154
- return AUTO_GENERATED_FILE if !@options[:config] || options_config_in_root?
154
+ return AUTO_GENERATED_FILE unless @options[:config]
155
155
 
156
- base = Pathname.new('.')
157
- config_dir = Pathname.new(File.dirname(@options[:config]))
156
+ base = Pathname.new(Dir.pwd)
157
+ config_dir = Pathname.new(@options[:config]).realpath.dirname
158
158
 
159
- "#{base.relative_path_from(config_dir)}/#{AUTO_GENERATED_FILE}"
160
- end
159
+ # Don't have the path start with `/`
160
+ return AUTO_GENERATED_FILE if config_dir == base
161
161
 
162
- def options_config_in_root?
163
- File.dirname(@options[:config]) == '.'
162
+ "#{base.relative_path_from(config_dir)}/#{AUTO_GENERATED_FILE}"
164
163
  end
165
164
  end
166
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
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../lsp/server'
4
-
5
3
  module RuboCop
6
4
  class CLI
7
5
  module Command
@@ -11,6 +9,8 @@ module RuboCop
11
9
  self.command_name = :lsp
12
10
 
13
11
  def run
12
+ # Load on demand, `languge-server-protocol` is heavy to require.
13
+ require_relative '../../lsp/server'
14
14
  RuboCop::LSP::Server.new(@config_store).start
15
15
  end
16
16
  end
@@ -9,8 +9,8 @@ module RuboCop
9
9
  self.command_name = :version
10
10
 
11
11
  def run
12
- puts RuboCop::Version.version(debug: false) if @options[:version]
13
- puts RuboCop::Version.version(debug: true, env: env) if @options[:verbose_version]
12
+ puts RuboCop::Version::STRING if @options[:version]
13
+ puts RuboCop::Version.verbose(env: env) if @options[:verbose_version]
14
14
  end
15
15
  end
16
16
  end
@@ -166,7 +166,7 @@ module RuboCop
166
166
  return unless duplicate_setting?(base_hash, derived_hash, key, opts[:inherited_file])
167
167
 
168
168
  inherit_mode = opts[:inherit_mode]['merge'] || opts[:inherit_mode]['override']
169
- return if base_hash[key].is_a?(Array) && inherit_mode && inherit_mode.include?(key)
169
+ return if base_hash[key].is_a?(Array) && inherit_mode&.include?(key)
170
170
 
171
171
  puts "#{PathUtil.smart_path(opts[:file])}: " \
172
172
  "#{opts[:cop_name]}:#{key} overrides " \
@@ -194,11 +194,11 @@ module RuboCop
194
194
  end
195
195
 
196
196
  def should_merge?(mode, key)
197
- mode && mode['merge'] && mode['merge'].include?(key)
197
+ mode && mode['merge']&.include?(key)
198
198
  end
199
199
 
200
200
  def should_override?(mode, key)
201
- mode && mode['override'] && mode['override'].include?(key)
201
+ mode && mode['override']&.include?(key)
202
202
  end
203
203
 
204
204
  def merge_hashes?(base_hash, derived_hash, key)
@@ -7,7 +7,8 @@ module RuboCop
7
7
  extend SimpleForwardable
8
8
 
9
9
  # @api private
10
- COMMON_PARAMS = %w[Exclude Include Severity inherit_mode AutoCorrect StyleGuide Details].freeze
10
+ COMMON_PARAMS = %w[Exclude Include Severity inherit_mode AutoCorrect StyleGuide Details
11
+ Enabled].freeze
11
12
  # @api private
12
13
  INTERNAL_PARAMS = %w[Description StyleGuide
13
14
  VersionAdded VersionChanged VersionRemoved
@@ -49,7 +49,9 @@ module RuboCop
49
49
  private
50
50
 
51
51
  def disable_offense(offense_range)
52
- range = surrounding_heredoc(offense_range) || surrounding_percent_array(offense_range)
52
+ range = surrounding_heredoc(offense_range) ||
53
+ surrounding_percent_array(offense_range) ||
54
+ string_continuation(offense_range)
53
55
 
54
56
  if range
55
57
  disable_offense_before_and_after(range_by_lines(range))
@@ -88,10 +90,28 @@ module RuboCop
88
90
  end
89
91
 
90
92
  percent_array.map(&:source_range).find do |range|
91
- offense_range.begin_pos > range.begin_pos && range.overlaps?(offense_range)
93
+ range_overlaps_offense?(offense_range, range)
92
94
  end
93
95
  end
94
96
 
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) }
105
+ end
106
+
107
+ def range_overlaps_offense?(offense_range, range)
108
+ offense_range.begin_pos > range.begin_pos && range.overlaps?(offense_range)
109
+ end
110
+
111
+ def string_continuation?(node)
112
+ (node.str_type? || node.dstr_type? || node.xstr_type?) && node.source.match?(/\\\s*$/)
113
+ end
114
+
95
115
  def range_of_first_line(range)
96
116
  begin_of_first_line = range.begin_pos - range.column
97
117
  end_of_first_line = begin_of_first_line + range.source_line.length
@@ -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.
@@ -322,8 +322,12 @@ module RuboCop
322
322
  # @api private
323
323
  def self.callbacks_needed
324
324
  @callbacks_needed ||= public_instance_methods.select do |m|
325
- m.start_with?(/on_|after_/) &&
326
- !Base.method_defined?(m) # exclude standard "callbacks" like 'on_begin_investigation'
325
+ # OPTIMIZE: Check method existence first to make fewer `start_with?` calls.
326
+ # At the time of writing this comment, this excludes 98 of ~104 methods.
327
+ # `start_with?` with two string arguments instead of a regex is faster
328
+ # in this specific case as well.
329
+ !Base.method_defined?(m) && # exclude standard "callbacks" like 'on_begin_investigation'
330
+ m.start_with?('on_', 'after_')
327
331
  end
328
332
  end
329
333
  # rubocop:enable Layout/ClassStructure
@@ -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).'
@@ -56,6 +56,7 @@ module RuboCop
56
56
 
57
57
  REQUIRED_MSG = 'Gem version specification is required.'
58
58
  FORBIDDEN_MSG = 'Gem version specification is forbidden.'
59
+ RESTRICT_ON_SEND = %i[gem].freeze
59
60
  VERSION_SPECIFICATION_REGEX = /^\s*[~<>=]*\s*[0-9.]+/.freeze
60
61
 
61
62
  # @!method includes_version_specification?(node)
@@ -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 ' \
@@ -22,6 +22,14 @@ module RuboCop
22
22
  end
23
23
  end
24
24
 
25
+ def self.inherited(_subclass)
26
+ super
27
+ warn Rainbow(<<~WARNING).yellow, uplevel: 1
28
+ Inheriting from `RuboCop::Cop::Cop` is deprecated. Use `RuboCop::Cop::Base` instead.
29
+ For more information, see https://docs.rubocop.org/rubocop/v1_upgrade_notes.html.
30
+ WARNING
31
+ end
32
+
25
33
  def self.support_autocorrect?
26
34
  method_defined?(:autocorrect)
27
35
  end
@@ -47,7 +47,7 @@ module RuboCop
47
47
  if column_delta.positive? && range.resize(1).source != "\n"
48
48
  corrector.insert_before(range, ' ' * column_delta)
49
49
  elsif /\A[ \t]+\z/.match?(range.source)
50
- remove(range, corrector)
50
+ corrector.remove(range)
51
51
  end
52
52
  end
53
53
 
@@ -96,17 +96,6 @@ module RuboCop
96
96
  end
97
97
  end
98
98
 
99
- def remove(range, corrector)
100
- original_stderr = $stderr
101
- $stderr = StringIO.new # Avoid error messages on console
102
- corrector.remove(range)
103
- rescue RuntimeError
104
- range = range_between(range.begin_pos + 1, range.end_pos + 1)
105
- retry if /^ +$/.match?(range.source)
106
- ensure
107
- $stderr = original_stderr
108
- end
109
-
110
99
  def each_line(expr)
111
100
  line_begin_pos = expr.begin_pos
112
101
  expr.source.each_line do |line|
@@ -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
@@ -22,7 +22,7 @@ module RuboCop
22
22
  private
23
23
 
24
24
  def ternary_condition?(node)
25
- node.parent&.if_type? && node.parent&.ternary?
25
+ node.parent&.if_type? && node.parent.ternary?
26
26
  end
27
27
 
28
28
  def next_char_is_question_mark?(node)
@@ -94,6 +94,16 @@ module RuboCop
94
94
  end
95
95
 
96
96
  def substitute_escaped_delimiters(content, delimiters)
97
+ if delimiters.first != delimiters.last
98
+ # With different delimiters (eg. `[]`, `()`), if there are the same
99
+ # number of each, escaping is not necessary
100
+ delimiter_counts = delimiters.each_with_object({}) do |delimiter, counts|
101
+ counts[delimiter] = content.count(delimiter)
102
+ end
103
+
104
+ return content if delimiter_counts[delimiters.first] == delimiter_counts[delimiters.last]
105
+ end
106
+
97
107
  delimiters.each { |delim| content.gsub!(delim, "\\#{delim}") }
98
108
  end
99
109
 
@@ -62,8 +62,7 @@ module RuboCop
62
62
 
63
63
  def node_and_method_name(node, attribute)
64
64
  if node.op_asgn_type?
65
- lhs, _op, _rhs = *node
66
- [lhs, attribute]
65
+ [node.lhs, attribute]
67
66
  else
68
67
  [node, :"#{attribute}="]
69
68
  end
@@ -53,8 +53,6 @@ module RuboCop
53
53
  # spec.required_ruby_version = '~> 2.5'
54
54
  # end
55
55
  class RequiredRubyVersion < Base
56
- include RangeHelp
57
-
58
56
  RESTRICT_ON_SEND = %i[required_ruby_version=].freeze
59
57
  NOT_EQUAL_MSG = '`required_ruby_version` and `TargetRubyVersion` ' \
60
58
  '(%<target_ruby_version>s, which may be specified in ' \