rubocop 1.75.1 → 1.75.6

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 (99) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +31 -18
  3. data/lib/rubocop/config_validator.rb +6 -6
  4. data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -1
  5. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +1 -0
  6. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +6 -1
  7. data/lib/rubocop/cop/layout/block_alignment.rb +1 -2
  8. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  9. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  10. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -2
  11. data/lib/rubocop/cop/layout/hash_alignment.rb +2 -2
  12. data/lib/rubocop/cop/layout/leading_comment_space.rb +13 -1
  13. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +1 -1
  14. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -4
  15. data/lib/rubocop/cop/layout/space_after_semicolon.rb +10 -0
  16. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +5 -1
  17. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +3 -0
  18. data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +2 -3
  19. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
  20. data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -5
  21. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
  22. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
  23. data/lib/rubocop/cop/lint/duplicate_methods.rb +46 -5
  24. data/lib/rubocop/cop/lint/literal_as_condition.rb +25 -11
  25. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -1
  26. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
  27. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +2 -2
  28. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
  29. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +7 -4
  30. data/lib/rubocop/cop/lint/return_in_void_context.rb +7 -2
  31. data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
  32. data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -1
  33. data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
  34. data/lib/rubocop/cop/lint/useless_assignment.rb +2 -0
  35. data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
  36. data/lib/rubocop/cop/lint/void.rb +2 -2
  37. data/lib/rubocop/cop/message_annotator.rb +7 -3
  38. data/lib/rubocop/cop/mixin/check_line_breakable.rb +2 -2
  39. data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +1 -1
  40. data/lib/rubocop/cop/mixin/def_node.rb +1 -1
  41. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
  42. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +0 -1
  43. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +15 -14
  44. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
  45. data/lib/rubocop/cop/mixin/trailing_comma.rb +9 -5
  46. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
  47. data/lib/rubocop/cop/naming/method_name.rb +1 -1
  48. data/lib/rubocop/cop/style/arguments_forwarding.rb +8 -5
  49. data/lib/rubocop/cop/style/class_and_module_children.rb +19 -3
  50. data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -1
  51. data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
  52. data/lib/rubocop/cop/style/comparable_between.rb +5 -2
  53. data/lib/rubocop/cop/style/conditional_assignment.rb +16 -4
  54. data/lib/rubocop/cop/style/data_inheritance.rb +7 -0
  55. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  56. data/lib/rubocop/cop/style/empty_literal.rb +4 -0
  57. data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
  58. data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -2
  59. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -2
  60. data/lib/rubocop/cop/style/global_std_stream.rb +3 -0
  61. data/lib/rubocop/cop/style/hash_fetch_chain.rb +0 -1
  62. data/lib/rubocop/cop/style/hash_syntax.rb +3 -0
  63. data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
  64. data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
  65. data/lib/rubocop/cop/style/identical_conditional_branches.rb +3 -3
  66. data/lib/rubocop/cop/style/if_unless_modifier.rb +20 -0
  67. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
  68. data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -1
  69. data/lib/rubocop/cop/style/lambda_call.rb +7 -2
  70. data/lib/rubocop/cop/style/map_into_array.rb +3 -1
  71. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +4 -1
  72. data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -0
  73. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  74. data/lib/rubocop/cop/style/redundant_condition.rb +13 -1
  75. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +1 -1
  76. data/lib/rubocop/cop/style/redundant_line_continuation.rb +0 -3
  77. data/lib/rubocop/cop/style/redundant_parentheses.rb +20 -3
  78. data/lib/rubocop/cop/style/return_nil.rb +2 -2
  79. data/lib/rubocop/cop/style/safe_navigation.rb +18 -3
  80. data/lib/rubocop/cop/style/sole_nested_conditional.rb +4 -2
  81. data/lib/rubocop/cop/style/string_concatenation.rb +1 -2
  82. data/lib/rubocop/cop/style/struct_inheritance.rb +8 -1
  83. data/lib/rubocop/cop/style/super_arguments.rb +1 -2
  84. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +7 -1
  85. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +1 -1
  86. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +1 -1
  87. data/lib/rubocop/cop/util.rb +1 -1
  88. data/lib/rubocop/cop/variable_force/variable.rb +1 -1
  89. data/lib/rubocop/cops_documentation_generator.rb +6 -2
  90. data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -1
  91. data/lib/rubocop/formatter/html_formatter.rb +1 -1
  92. data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
  93. data/lib/rubocop/magic_comment.rb +8 -0
  94. data/lib/rubocop/rspec/cop_helper.rb +2 -2
  95. data/lib/rubocop/rspec/shared_contexts.rb +1 -2
  96. data/lib/rubocop/server/cache.rb +13 -10
  97. data/lib/rubocop/target_finder.rb +6 -2
  98. data/lib/rubocop/version.rb +1 -1
  99. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a064330786019e0efee6b496e761b05bea0286f0afdcbb4fffad2f07433aef9d
4
- data.tar.gz: eb1ee00d5fe060ea49203635df3c7457df6f416de93c9801a687386aa02f4768
3
+ metadata.gz: 4692afe0e994fae9d158ac440d48f460623d28bbad07fc7ccf141aa3737e82a1
4
+ data.tar.gz: 3dba40c9526a877cdc7269d54b3c89e3d64f8147cb5e2b885146c1d02d94bc19
5
5
  SHA512:
6
- metadata.gz: 336c6e38cc6162a00ca4c9780dcc71fb4b03a785af0eb6abb6c30baf2e1c8512af12e921a2036564102290324e418278cb83ceb06d7a1ec44ddf314923275f89
7
- data.tar.gz: cbe9d5ab5685dbab70de2b281ecc807494631a294273260d87315d6875b753d9c2b60f6d7c14379eaf5b384894a4400c747ef91a57323c418c66a51076b33f06
6
+ metadata.gz: acd7a48eac01d73747fb22cef86c75c4b2da8a910f341ddda19572eabd9126e8a42edac565df8ce0e6946e69f44d892e08c358dd9c6d72455974c05277731e3e
7
+ data.tar.gz: 2afef8e39089e476050a24aa63e4f637a4765759b31c74672740fb86067dada674140574c61a0d426950ea57e36c7b5bdc00db5cbab14e0000fa7aa065e83c6c
data/config/default.yml CHANGED
@@ -274,7 +274,8 @@ Bundler/OrderedGems:
274
274
  Gemspec/AddRuntimeDependency:
275
275
  Description: 'Prefer `add_dependency` over `add_runtime_dependency`.'
276
276
  StyleGuide: '#add_dependency_vs_add_runtime_dependency'
277
- Reference: https://github.com/rubygems/rubygems/issues/7799#issuecomment-2192720316
277
+ References:
278
+ - https://github.com/rubygems/rubygems/issues/7799#issuecomment-2192720316
278
279
  Enabled: pending
279
280
  VersionAdded: '1.65'
280
281
  Include:
@@ -343,7 +344,7 @@ Gemspec/RequireMFA:
343
344
  Severity: warning
344
345
  VersionAdded: '1.23'
345
346
  VersionChanged: '1.40'
346
- Reference:
347
+ References:
347
348
  - https://guides.rubygems.org/mfa-requirement-opt-in/
348
349
  Include:
349
350
  - '**/*.gemspec'
@@ -604,7 +605,7 @@ Layout/EmptyLineAfterMultilineCondition:
604
605
  # This is disabled, because this style is not very common in practice.
605
606
  Enabled: false
606
607
  VersionAdded: '0.90'
607
- Reference:
608
+ References:
608
609
  - https://github.com/airbnb/ruby#multiline-if-newline
609
610
 
610
611
  Layout/EmptyLineBetweenDefs:
@@ -639,7 +640,7 @@ Layout/EmptyLinesAroundAccessModifier:
639
640
  SupportedStyles:
640
641
  - around
641
642
  - only_before
642
- Reference:
643
+ References:
643
644
  # A reference to `EnforcedStyle: only_before`.
644
645
  - https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions
645
646
 
@@ -996,7 +997,7 @@ Layout/IndentationConsistency:
996
997
  SupportedStyles:
997
998
  - normal
998
999
  - indented_internal_methods
999
- Reference:
1000
+ References:
1000
1001
  # A reference to `EnforcedStyle: indented_internal_methods`.
1001
1002
  - https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions
1002
1003
 
@@ -2035,7 +2036,8 @@ Lint/InterpolationCheck:
2035
2036
 
2036
2037
  Lint/ItWithoutArgumentsInBlock:
2037
2038
  Description: 'Checks uses of `it` calls without arguments in block.'
2038
- Reference: 'https://bugs.ruby-lang.org/issues/18980'
2039
+ References:
2040
+ - 'https://bugs.ruby-lang.org/issues/18980'
2039
2041
  Enabled: pending
2040
2042
  VersionAdded: '1.59'
2041
2043
 
@@ -2673,7 +2675,7 @@ Metrics/AbcSize:
2673
2675
  Description: >-
2674
2676
  A calculated magnitude based on number of assignments,
2675
2677
  branches, and conditions.
2676
- Reference:
2678
+ References:
2677
2679
  - http://c2.com/cgi/wiki?AbcMetric
2678
2680
  - https://en.wikipedia.org/wiki/ABC_Software_Metric
2679
2681
  Enabled: true
@@ -3150,7 +3152,8 @@ Security/JSONLoad:
3150
3152
  Description: >-
3151
3153
  Prefer usage of `JSON.parse` over `JSON.load` due to potential
3152
3154
  security issues. See reference for more information.
3153
- Reference: 'https://ruby-doc.org/stdlib-2.7.0/libdoc/json/rdoc/JSON.html#method-i-load'
3155
+ References:
3156
+ - 'https://ruby-doc.org/stdlib-2.7.0/libdoc/json/rdoc/JSON.html#method-i-load'
3154
3157
  Enabled: true
3155
3158
  VersionAdded: '0.43'
3156
3159
  VersionChanged: '1.22'
@@ -3162,7 +3165,8 @@ Security/MarshalLoad:
3162
3165
  Description: >-
3163
3166
  Avoid using of `Marshal.load` or `Marshal.restore` due to potential
3164
3167
  security issues. See reference for more information.
3165
- Reference: 'https://ruby-doc.org/core-2.7.0/Marshal.html#module-Marshal-label-Security+considerations'
3168
+ References:
3169
+ - 'https://ruby-doc.org/core-2.7.0/Marshal.html#module-Marshal-label-Security+considerations'
3166
3170
  Enabled: true
3167
3171
  VersionAdded: '0.47'
3168
3172
 
@@ -3177,7 +3181,8 @@ Security/YAMLLoad:
3177
3181
  Description: >-
3178
3182
  Prefer usage of `YAML.safe_load` over `YAML.load` due to potential
3179
3183
  security issues. See reference for more information.
3180
- Reference: 'https://ruby-doc.org/stdlib-2.7.0/libdoc/yaml/rdoc/YAML.html#module-YAML-label-Security'
3184
+ References:
3185
+ - 'https://ruby-doc.org/stdlib-2.7.0/libdoc/yaml/rdoc/YAML.html#module-YAML-label-Security'
3181
3186
  Enabled: true
3182
3187
  VersionAdded: '0.47'
3183
3188
  SafeAutoCorrect: false
@@ -3271,7 +3276,8 @@ Style/ArrayCoercion:
3271
3276
 
3272
3277
  Style/ArrayFirstLast:
3273
3278
  Description: 'Use `arr.first` and `arr.last` instead of `arr[0]` and `arr[-1]`.'
3274
- Reference: '#first-and-last'
3279
+ References:
3280
+ - '#first-and-last'
3275
3281
  Enabled: false
3276
3282
  VersionAdded: '1.58'
3277
3283
  Safe: false
@@ -3696,7 +3702,9 @@ Style/CommentedKeyword:
3696
3702
  Style/ComparableBetween:
3697
3703
  Description: 'Enforces the use of `Comparable#between?` instead of logical comparison.'
3698
3704
  Enabled: pending
3705
+ Safe: false
3699
3706
  VersionAdded: '1.74'
3707
+ VersionChanged: '1.75'
3700
3708
  StyleGuide: '#ranges-or-between'
3701
3709
 
3702
3710
  Style/ComparableClamp:
@@ -4009,7 +4017,7 @@ Style/ExponentialNotation:
4009
4017
  Style/FetchEnvVar:
4010
4018
  Description: >-
4011
4019
  Suggests `ENV.fetch` for the replacement of `ENV[]`.
4012
- Reference:
4020
+ References:
4013
4021
  - https://rubystyle.guide/#hash-fetch-defaults
4014
4022
  Enabled: pending
4015
4023
  VersionAdded: '1.28'
@@ -4050,7 +4058,8 @@ Style/FileWrite:
4050
4058
  Style/FloatDivision:
4051
4059
  Description: 'For performing float division, coerce one side only.'
4052
4060
  StyleGuide: '#float-division'
4053
- Reference: 'https://blog.rubystyle.guide/ruby/2019/06/21/float-division.html'
4061
+ References:
4062
+ - 'https://blog.rubystyle.guide/ruby/2019/06/21/float-division.html'
4054
4063
  Enabled: true
4055
4064
  VersionAdded: '0.72'
4056
4065
  VersionChanged: '1.9'
@@ -4147,7 +4156,8 @@ Style/GlobalStdStream:
4147
4156
  Style/GlobalVars:
4148
4157
  Description: 'Do not introduce global variables.'
4149
4158
  StyleGuide: '#instance-vars'
4150
- Reference: 'https://www.zenspider.com/ruby/quickref.html'
4159
+ References:
4160
+ - 'https://www.zenspider.com/ruby/quickref.html'
4151
4161
  Enabled: true
4152
4162
  VersionAdded: '0.13'
4153
4163
  # Built-in global variables are allowed by default.
@@ -4958,7 +4968,7 @@ Style/OpenStructUse:
4958
4968
  Description: >-
4959
4969
  Avoid using OpenStruct. As of Ruby 3.0, use is officially discouraged due to performance,
4960
4970
  version compatibility, and potential security issues.
4961
- Reference:
4971
+ References:
4962
4972
  - https://docs.ruby-lang.org/en/3.0.0/OpenStruct.html#class-OpenStruct-label-Caveats
4963
4973
 
4964
4974
  Enabled: pending
@@ -5203,7 +5213,8 @@ Style/RedundantFetchBlock:
5203
5213
  Description: >-
5204
5214
  Use `fetch(key, value)` instead of `fetch(key) { value }`
5205
5215
  when value has Numeric, Rational, Complex, Symbol or String type, `false`, `true`, `nil` or is a constant.
5206
- Reference: 'https://github.com/fastruby/fast-ruby#hashfetch-with-argument-vs-hashfetch--block-code'
5216
+ References:
5217
+ - 'https://github.com/fastruby/fast-ruby#hashfetch-with-argument-vs-hashfetch--block-code'
5207
5218
  Enabled: true
5208
5219
  Safe: false
5209
5220
  # If enabled, this cop will autocorrect usages of
@@ -5445,7 +5456,8 @@ Style/Sample:
5445
5456
  Description: >-
5446
5457
  Use `sample` instead of `shuffle.first`,
5447
5458
  `shuffle.last`, and `shuffle[Integer]`.
5448
- Reference: 'https://github.com/fastruby/fast-ruby#arrayshufflefirst-vs-arraysample-code'
5459
+ References:
5460
+ - 'https://github.com/fastruby/fast-ruby#arrayshufflefirst-vs-arraysample-code'
5449
5461
  Enabled: true
5450
5462
  VersionAdded: '0.30'
5451
5463
 
@@ -5940,7 +5952,8 @@ Style/YAMLFileRead:
5940
5952
 
5941
5953
  Style/YodaCondition:
5942
5954
  Description: 'Forbid or enforce yoda conditions.'
5943
- Reference: 'https://en.wikipedia.org/wiki/Yoda_conditions'
5955
+ References:
5956
+ - 'https://en.wikipedia.org/wiki/Yoda_conditions'
5944
5957
  Enabled: true
5945
5958
  EnforcedStyle: forbid_for_all_comparison_operators
5946
5959
  SupportedStyles:
@@ -9,16 +9,16 @@ module RuboCop
9
9
 
10
10
  # @api private
11
11
  COMMON_PARAMS = %w[Exclude Include Severity inherit_mode AutoCorrect StyleGuide Details
12
- Enabled Reference].freeze
12
+ Enabled Reference References].freeze
13
13
  # @api private
14
14
  INTERNAL_PARAMS = %w[Description StyleGuide
15
15
  VersionAdded VersionChanged VersionRemoved
16
- Reference Safe SafeAutoCorrect].freeze
16
+ Reference References Safe SafeAutoCorrect].freeze
17
17
  # @api private
18
18
  NEW_COPS_VALUES = %w[pending disable enable].freeze
19
19
 
20
20
  # @api private
21
- CONFIG_CHECK_KEYS = %w[Enabled Safe SafeAutoCorrect AutoCorrect].to_set.freeze
21
+ CONFIG_CHECK_KEYS = %w[Enabled Safe SafeAutoCorrect AutoCorrect References].to_set.freeze
22
22
  CONFIG_CHECK_DEPARTMENTS = %w[pending override_department].freeze
23
23
  CONFIG_CHECK_AUTOCORRECTS = %w[always contextual disabled].freeze
24
24
  private_constant :CONFIG_CHECK_KEYS, :CONFIG_CHECK_DEPARTMENTS
@@ -260,8 +260,7 @@ module RuboCop
260
260
  end
261
261
  end
262
262
 
263
- # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
264
- def check_cop_config_value(hash, parent = nil)
263
+ def check_cop_config_value(hash, parent = nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
265
264
  hash.each do |key, value|
266
265
  check_cop_config_value(value, key) if value.is_a?(Hash)
267
266
 
@@ -271,6 +270,8 @@ module RuboCop
271
270
  supposed_values = 'a boolean'
272
271
  elsif key == 'AutoCorrect' && !CONFIG_CHECK_AUTOCORRECTS.include?(value)
273
272
  supposed_values = '`always`, `contextual`, `disabled`, or a boolean'
273
+ elsif key == 'References'
274
+ supposed_values = 'an array of strings'
274
275
  else
275
276
  next
276
277
  end
@@ -278,7 +279,6 @@ module RuboCop
278
279
  raise ValidationError, param_error_message(parent, key, value, supposed_values)
279
280
  end
280
281
  end
281
- # rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
282
282
 
283
283
  # FIXME: Handling colors in exception messages like this is ugly.
284
284
  def param_error_message(parent, key, value, supposed_values)
@@ -69,7 +69,7 @@ module RuboCop
69
69
  # @!method offense_example(node)
70
70
  def_node_matcher :offense_example, <<~PATTERN
71
71
  (block
72
- (send _ {:it :specify} $...)
72
+ (send _ {:it :specify :xit :fit} $...)
73
73
  _args
74
74
  `(send nil? %RESTRICT_ON_SEND ...)
75
75
  )
@@ -28,6 +28,7 @@ module RuboCop
28
28
  RESTRICT_ON_SEND = %i[def_node_matcher def_node_search].freeze
29
29
  NODE_GROUPS = {
30
30
  any_block: %i[block numblock itblock],
31
+ any_def: %i[def defs],
31
32
  argument: %i[arg optarg restarg kwarg kwoptarg kwrestarg blockarg forward_arg shadowarg],
32
33
  boolean: %i[true false],
33
34
  call: %i[send csend],
@@ -10,7 +10,12 @@ module RuboCop
10
10
  extend FileFinder
11
11
 
12
12
  ALLOWED_CONFIGURATIONS = %w[
13
- Safe SafeAutoCorrect AutoCorrect Severity StyleGuide Details Reference Include Exclude
13
+ Safe SafeAutoCorrect AutoCorrect
14
+ Severity
15
+ StyleGuide
16
+ Details
17
+ Reference References
18
+ Include Exclude
14
19
  ].freeze
15
20
  RESTRICT_ON_SEND = %i[[] fetch].freeze
16
21
  MSG = '`%<name>s` is not defined in the configuration for `%<cop>s` ' \
@@ -73,8 +73,7 @@ module RuboCop
73
73
  # @!method block_end_align_target?(node, child)
74
74
  def_node_matcher :block_end_align_target?, <<~PATTERN
75
75
  {assignment?
76
- def
77
- defs
76
+ any_def
78
77
  splat
79
78
  and
80
79
  or
@@ -48,7 +48,7 @@ module RuboCop
48
48
  def on_send(node)
49
49
  return unless node.def_modifier?
50
50
 
51
- method_def = node.each_descendant(:def, :defs).first
51
+ method_def = node.each_descendant(:any_def).first
52
52
  expr = node.source_range
53
53
 
54
54
  line_start = range_between(expr.begin_pos, method_def.loc.keyword.end_pos)
@@ -131,7 +131,7 @@ module RuboCop
131
131
 
132
132
  def next_sibling_parent_empty_or_else?(node)
133
133
  next_sibling = node.right_sibling
134
- return true if next_sibling.nil?
134
+ return true unless next_sibling.is_a?(AST::Node)
135
135
 
136
136
  parent = next_sibling.parent
137
137
 
@@ -180,7 +180,7 @@ module RuboCop
180
180
  end
181
181
 
182
182
  def method_candidate?(node)
183
- cop_config['EmptyLineBetweenMethodDefs'] && node.type?(:def, :defs)
183
+ cop_config['EmptyLineBetweenMethodDefs'] && node.any_def_type?
184
184
  end
185
185
 
186
186
  def class_candidate?(node)
@@ -252,7 +252,7 @@ module RuboCop
252
252
  end
253
253
 
254
254
  def end_loc(node)
255
- if node.type?(:def, :defs) && node.endless?
255
+ if node.any_def_type? && node.endless?
256
256
  node.source_range.end
257
257
  else
258
258
  node.loc.end
@@ -19,7 +19,7 @@ module RuboCop
19
19
  # * ignore_implicit (without curly braces)
20
20
  #
21
21
  # Alternatively you can specify multiple allowed styles. That's done by
22
- # passing a list of styles to EnforcedStyles.
22
+ # passing a list of styles to EnforcedHashRocketStyle and EnforcedColonStyle.
23
23
  #
24
24
  # @example EnforcedHashRocketStyle: key (default)
25
25
  # # bad
@@ -250,7 +250,7 @@ module RuboCop
250
250
  reset!
251
251
 
252
252
  alignment_for(first_pair).each do |alignment|
253
- delta = alignment.deltas_for_first_pair(first_pair, node)
253
+ delta = alignment.deltas_for_first_pair(first_pair)
254
254
  check_delta delta, node: first_pair, alignment: alignment
255
255
  end
256
256
 
@@ -58,6 +58,12 @@ module RuboCop
58
58
  # attr_reader :name #: String
59
59
  # attr_reader :age #: Integer?
60
60
  #
61
+ # #: (
62
+ # #| Integer,
63
+ # #| String
64
+ # #| ) -> void
65
+ # def foo; end
66
+ #
61
67
  # @example AllowRBSInlineAnnotation: true
62
68
  #
63
69
  # # good
@@ -67,6 +73,12 @@ module RuboCop
67
73
  # attr_reader :name #: String
68
74
  # attr_reader :age #: Integer?
69
75
  #
76
+ # #: (
77
+ # #| Integer,
78
+ # #| String
79
+ # #| ) -> void
80
+ # def foo; end
81
+ #
70
82
  # @example AllowSteepAnnotation: false (default)
71
83
  #
72
84
  # # bad
@@ -175,7 +187,7 @@ module RuboCop
175
187
  end
176
188
 
177
189
  def rbs_inline_annotation?(comment)
178
- allow_rbs_inline_annotation? && comment.text.start_with?(/#:|#\[.+\]/)
190
+ allow_rbs_inline_annotation? && comment.text.start_with?(/#:|#\[.+\]|#\|/)
179
191
  end
180
192
 
181
193
  def allow_steep_annotation?
@@ -118,7 +118,7 @@ module RuboCop
118
118
  end
119
119
 
120
120
  def right_hand_side(send_node)
121
- send_node.first_argument.source_range
121
+ send_node.first_argument&.source_range
122
122
  end
123
123
  end
124
124
  end
@@ -29,8 +29,7 @@ module RuboCop
29
29
  MSG = '`%<kw_loc>s` at %<kw_loc_line>d, %<kw_loc_column>d is not ' \
30
30
  'aligned with `%<beginning>s` at ' \
31
31
  '%<begin_loc_line>d, %<begin_loc_column>d.'
32
- ANCESTOR_TYPES = %i[kwbegin def defs class module any_block].freeze
33
- ANCESTOR_TYPES_WITH_ACCESS_MODIFIERS = %i[def defs].freeze
32
+ ANCESTOR_TYPES = %i[kwbegin any_def class module any_block].freeze
34
33
  ALTERNATIVE_ACCESS_MODIFIERS = %i[public_class_method private_class_method].freeze
35
34
 
36
35
  def on_resbody(node)
@@ -162,8 +161,7 @@ module RuboCop
162
161
  end
163
162
 
164
163
  def access_modifier_node(node)
165
- return nil unless
166
- ANCESTOR_TYPES_WITH_ACCESS_MODIFIERS.include?(node.type)
164
+ return nil unless node.any_def_type?
167
165
 
168
166
  access_modifier_node = node.ancestors.first
169
167
  return nil unless access_modifier?(access_modifier_node)
@@ -23,6 +23,16 @@ module RuboCop
23
23
  def kind(token)
24
24
  'semicolon' if token.semicolon?
25
25
  end
26
+
27
+ def space_missing?(token1, token2)
28
+ super && !semicolon_sequence?(token1, token2)
29
+ end
30
+
31
+ private
32
+
33
+ def semicolon_sequence?(token, next_token)
34
+ token.semicolon? && next_token.semicolon?
35
+ end
26
36
  end
27
37
  end
28
38
  end
@@ -6,6 +6,8 @@ module RuboCop
6
6
  # Checks that brackets used for array literals have or don't have
7
7
  # surrounding space depending on configuration.
8
8
  #
9
+ # Array pattern matching is handled in the same way.
10
+ #
9
11
  # @example EnforcedStyle: no_space (default)
10
12
  # # The `no_space` style enforces that array literals have
11
13
  # # no surrounding space.
@@ -82,9 +84,10 @@ module RuboCop
82
84
  EMPTY_MSG = '%<command>s space inside empty array brackets.'
83
85
 
84
86
  def on_array(node)
85
- return unless node.square_brackets?
87
+ return if node.array_type? && !node.square_brackets?
86
88
 
87
89
  tokens, left, right = array_brackets(node)
90
+ return unless left && right
88
91
 
89
92
  if empty_brackets?(left, right, tokens: tokens)
90
93
  return empty_offenses(node, left, right, EMPTY_MSG)
@@ -95,6 +98,7 @@ module RuboCop
95
98
 
96
99
  issue_offenses(node, left, right, start_ok, end_ok)
97
100
  end
101
+ alias on_array_pattern on_array
98
102
 
99
103
  private
100
104
 
@@ -6,6 +6,8 @@ module RuboCop
6
6
  # Checks that braces used for hash literals have or don't have
7
7
  # surrounding space depending on configuration.
8
8
  #
9
+ # Hash pattern matching is handled in the same way.
10
+ #
9
11
  # @example EnforcedStyle: space (default)
10
12
  # # The `space` style enforces that hash literals have
11
13
  # # surrounding space.
@@ -87,6 +89,7 @@ module RuboCop
87
89
  check(tokens[-2], tokens[-1]) if tokens.size > 2
88
90
  check_whitespace_only_hash(node) if enforce_no_space_style_for_empty_braces?
89
91
  end
92
+ alias on_hash_pattern on_hash
90
93
 
91
94
  private
92
95
 
@@ -51,10 +51,9 @@ module RuboCop
51
51
  'in a regexp.'
52
52
 
53
53
  def on_interpolation(begin_node)
54
- final_node = begin_node.children.last
55
-
56
- return unless begin_node.parent.regexp_type?
54
+ return unless (final_node = begin_node.children.last)
57
55
  return unless final_node.array_type?
56
+ return unless begin_node.parent.regexp_type?
58
57
 
59
58
  if array_of_literal_values?(final_node)
60
59
  register_array_of_literal_values(begin_node, final_node)
@@ -48,7 +48,7 @@ module RuboCop
48
48
  def autocorrect(corrector, node)
49
49
  boolean_literal = node.source.delete(':')
50
50
  parent = node.parent
51
- if parent&.pair_type? && node.equal?(parent.children[0])
51
+ if parent&.pair_type? && parent.colon? && node.equal?(parent.children[0])
52
52
  corrector.remove(parent.loc.operator)
53
53
  boolean_literal = "#{node.source} =>"
54
54
  end
@@ -6,9 +6,8 @@ module RuboCop
6
6
  # Checks for circular argument references in optional keyword
7
7
  # arguments and optional ordinal arguments.
8
8
  #
9
- # This cop mirrors a warning produced by MRI since 2.2.
10
- #
11
- # NOTE: This syntax is no longer valid on Ruby 2.7 or higher.
9
+ # NOTE: This syntax was made invalid on Ruby 2.7 - Ruby 3.3 but is allowed
10
+ # again since Ruby 3.4.
12
11
  #
13
12
  # @example
14
13
  #
@@ -41,8 +40,6 @@ module RuboCop
41
40
 
42
41
  MSG = 'Circular argument reference - `%<arg_name>s`.'
43
42
 
44
- maximum_target_ruby_version 2.6
45
-
46
43
  def on_kwoptarg(node)
47
44
  check_for_circular_argument_references(*node)
48
45
  end
@@ -43,7 +43,7 @@ module RuboCop
43
43
  dup: 'to_h',
44
44
  exists?: 'exist?',
45
45
  gethostbyaddr: 'Addrinfo#getnameinfo',
46
- gethostbyname: 'Addrinfo#getaddrinfo',
46
+ gethostbyname: 'Addrinfo.getaddrinfo',
47
47
  iterator?: 'block_given?'
48
48
  }.freeze
49
49
 
@@ -134,7 +134,7 @@ module RuboCop
134
134
  if NO_ARG_ALGORITHM.include?(algorithm_parts.first.upcase) && no_arguments
135
135
  "'#{algorithm_parts.first}'"
136
136
  else
137
- mode = 'cbc' unless size_and_mode == ['cbc']
137
+ mode = 'cbc' if size_and_mode.empty?
138
138
 
139
139
  "'#{(algorithm_parts + size_and_mode + [mode]).compact.take(3).join('-')}'"
140
140
  end
@@ -39,10 +39,35 @@ module RuboCop
39
39
  # end
40
40
  #
41
41
  # alias bar foo
42
+ #
43
+ # @example AllCops:ActiveSupportExtensionsEnabled: false (default)
44
+ #
45
+ # # good
46
+ # def foo
47
+ # 1
48
+ # end
49
+ #
50
+ # delegate :foo, to: :bar
51
+ #
52
+ # @example AllCops:ActiveSupportExtensionsEnabled: true
53
+ #
54
+ # # bad
55
+ # def foo
56
+ # 1
57
+ # end
58
+ #
59
+ # delegate :foo, to: :bar
60
+ #
61
+ # # good
62
+ # def foo
63
+ # 1
64
+ # end
65
+ #
66
+ # delegate :baz, to: :bar
42
67
  class DuplicateMethods < Base
43
68
  MSG = 'Method `%<method>s` is defined at both %<defined>s and %<current>s.'
44
- RESTRICT_ON_SEND = %i[alias_method attr_reader attr_writer attr_accessor attr].freeze
45
- DEF_TYPES = %i[def defs].freeze
69
+ RESTRICT_ON_SEND = %i[alias_method attr_reader attr_writer attr_accessor attr
70
+ delegate].freeze
46
71
 
47
72
  def initialize(config = nil, options = nil)
48
73
  super
@@ -86,15 +111,25 @@ module RuboCop
86
111
  (send nil? :alias_method (sym $_name) _)
87
112
  PATTERN
88
113
 
114
+ # @!method delegate_method?(node)
115
+ def_node_matcher :delegate_method?, <<~PATTERN
116
+ (send nil? :delegate (sym $_)+ (hash _))
117
+ PATTERN
118
+
89
119
  # @!method sym_name(node)
90
120
  def_node_matcher :sym_name, '(sym $_name)'
91
- def on_send(node)
121
+
122
+ def on_send(node) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
92
123
  if (name = alias_method?(node))
93
124
  return if node.ancestors.any?(&:if_type?)
94
125
 
95
126
  found_instance_method(node, name)
96
127
  elsif (attr = node.attribute_accessor?)
97
128
  on_attr(node, *attr)
129
+ elsif active_support_extensions_enabled? && (names = delegate_method?(node))
130
+ return if node.ancestors.any?(&:if_type?)
131
+
132
+ on_delegate(node, names)
98
133
  end
99
134
  end
100
135
 
@@ -119,6 +154,12 @@ module RuboCop
119
154
  current: source_location(node))
120
155
  end
121
156
 
157
+ def on_delegate(node, method_names)
158
+ method_names.each do |name|
159
+ found_instance_method(node, name)
160
+ end
161
+ end
162
+
122
163
  def found_instance_method(node, name)
123
164
  return found_sclass_method(node, name) unless (scope = node.parent_module_name)
124
165
 
@@ -162,7 +203,7 @@ module RuboCop
162
203
  end
163
204
 
164
205
  def method_key(node, method_name)
165
- if (ancestor_def = node.each_ancestor(*DEF_TYPES).first)
206
+ if (ancestor_def = node.each_ancestor(:any_def).first)
166
207
  "#{ancestor_def.method_name}.#{method_name}"
167
208
  else
168
209
  method_name
@@ -170,7 +211,7 @@ module RuboCop
170
211
  end
171
212
 
172
213
  def location(node)
173
- if DEF_TYPES.include?(node.type)
214
+ if node.any_def_type?
174
215
  node.loc.keyword.join(node.loc.name)
175
216
  else
176
217
  node.source_range