rubocop 1.75.2 → 1.75.3

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +29 -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/undefined_config.rb +6 -1
  6. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  7. data/lib/rubocop/cop/layout/hash_alignment.rb +1 -1
  8. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +1 -1
  9. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -1
  10. data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
  11. data/lib/rubocop/cop/message_annotator.rb +7 -3
  12. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
  13. data/lib/rubocop/cop/mixin/trailing_comma.rb +3 -3
  14. data/lib/rubocop/cop/style/arguments_forwarding.rb +4 -4
  15. data/lib/rubocop/cop/style/class_and_module_children.rb +7 -1
  16. data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
  17. data/lib/rubocop/cop/style/conditional_assignment.rb +15 -6
  18. data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
  19. data/lib/rubocop/cop/style/hash_fetch_chain.rb +0 -1
  20. data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
  21. data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
  22. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
  23. data/lib/rubocop/cop/style/lambda_call.rb +7 -2
  24. data/lib/rubocop/cop/style/map_into_array.rb +3 -1
  25. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +1 -1
  26. data/lib/rubocop/cop/style/redundant_line_continuation.rb +0 -3
  27. data/lib/rubocop/cop/style/redundant_parentheses.rb +12 -3
  28. data/lib/rubocop/cop/style/safe_navigation.rb +18 -3
  29. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +1 -1
  30. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +1 -1
  31. data/lib/rubocop/cops_documentation_generator.rb +6 -2
  32. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  33. data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
  34. data/lib/rubocop/target_finder.rb +5 -1
  35. data/lib/rubocop/version.rb +1 -1
  36. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 707ab6b769b30dc2f2c34c7e879fde41cab6dd694820d8f071db17a1ef0ef48f
4
- data.tar.gz: abafc2d95cd2c358b4699211ce58e544852707630c55ec2950a3fd01899b8dd4
3
+ metadata.gz: a997a626f52ebff384613dfc5885815cf0bcee74a22f53485f77a5ea95205a60
4
+ data.tar.gz: b79e9c7f1b9b0716cf38b317174b49075c94dc39edd3d310a1a00d4fa6304a4f
5
5
  SHA512:
6
- metadata.gz: 290274c929ba840ebf66f9e2978f5853e04732ef05bfaee7dd45ab445ae4cc41e7913bc6204ef1e11618ec9bfb8fe1c234bc6febbcb3e65e7c651f73f31936ba
7
- data.tar.gz: 56f21668db3004f7a6846319911b3c7fe37d71a1d0ee43c9eee0f032ba324fc4745693fc4996907efd81975b23e1926c65f8129182e1f57e1b4c2e910af32984
6
+ metadata.gz: 9e2948dd0e2d446e78113d6575bf5fb2f96a2d40239db066b9e6476479efd22996081675bcf47925a8ce0fb6012495e678701ab7383cf1a534255747fc2a6d00
7
+ data.tar.gz: 944bf135b7e8855c53172f14e33b040326cde4b0c14a8cad3656434765f1b9f9c2097e455437317aba2026f51c0ff0beb2a119b5e262bb4173664ab408e8aa8a
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
@@ -4009,7 +4015,7 @@ Style/ExponentialNotation:
4009
4015
  Style/FetchEnvVar:
4010
4016
  Description: >-
4011
4017
  Suggests `ENV.fetch` for the replacement of `ENV[]`.
4012
- Reference:
4018
+ References:
4013
4019
  - https://rubystyle.guide/#hash-fetch-defaults
4014
4020
  Enabled: pending
4015
4021
  VersionAdded: '1.28'
@@ -4050,7 +4056,8 @@ Style/FileWrite:
4050
4056
  Style/FloatDivision:
4051
4057
  Description: 'For performing float division, coerce one side only.'
4052
4058
  StyleGuide: '#float-division'
4053
- Reference: 'https://blog.rubystyle.guide/ruby/2019/06/21/float-division.html'
4059
+ References:
4060
+ - 'https://blog.rubystyle.guide/ruby/2019/06/21/float-division.html'
4054
4061
  Enabled: true
4055
4062
  VersionAdded: '0.72'
4056
4063
  VersionChanged: '1.9'
@@ -4147,7 +4154,8 @@ Style/GlobalStdStream:
4147
4154
  Style/GlobalVars:
4148
4155
  Description: 'Do not introduce global variables.'
4149
4156
  StyleGuide: '#instance-vars'
4150
- Reference: 'https://www.zenspider.com/ruby/quickref.html'
4157
+ References:
4158
+ - 'https://www.zenspider.com/ruby/quickref.html'
4151
4159
  Enabled: true
4152
4160
  VersionAdded: '0.13'
4153
4161
  # Built-in global variables are allowed by default.
@@ -4958,7 +4966,7 @@ Style/OpenStructUse:
4958
4966
  Description: >-
4959
4967
  Avoid using OpenStruct. As of Ruby 3.0, use is officially discouraged due to performance,
4960
4968
  version compatibility, and potential security issues.
4961
- Reference:
4969
+ References:
4962
4970
  - https://docs.ruby-lang.org/en/3.0.0/OpenStruct.html#class-OpenStruct-label-Caveats
4963
4971
 
4964
4972
  Enabled: pending
@@ -5203,7 +5211,8 @@ Style/RedundantFetchBlock:
5203
5211
  Description: >-
5204
5212
  Use `fetch(key, value)` instead of `fetch(key) { value }`
5205
5213
  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'
5214
+ References:
5215
+ - 'https://github.com/fastruby/fast-ruby#hashfetch-with-argument-vs-hashfetch--block-code'
5207
5216
  Enabled: true
5208
5217
  Safe: false
5209
5218
  # If enabled, this cop will autocorrect usages of
@@ -5445,7 +5454,8 @@ Style/Sample:
5445
5454
  Description: >-
5446
5455
  Use `sample` instead of `shuffle.first`,
5447
5456
  `shuffle.last`, and `shuffle[Integer]`.
5448
- Reference: 'https://github.com/fastruby/fast-ruby#arrayshufflefirst-vs-arraysample-code'
5457
+ References:
5458
+ - 'https://github.com/fastruby/fast-ruby#arrayshufflefirst-vs-arraysample-code'
5449
5459
  Enabled: true
5450
5460
  VersionAdded: '0.30'
5451
5461
 
@@ -5940,7 +5950,8 @@ Style/YAMLFileRead:
5940
5950
 
5941
5951
  Style/YodaCondition:
5942
5952
  Description: 'Forbid or enforce yoda conditions.'
5943
- Reference: 'https://en.wikipedia.org/wiki/Yoda_conditions'
5953
+ References:
5954
+ - 'https://en.wikipedia.org/wiki/Yoda_conditions'
5944
5955
  Enabled: true
5945
5956
  EnforcedStyle: forbid_for_all_comparison_operators
5946
5957
  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
  )
@@ -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` ' \
@@ -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
 
@@ -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
@@ -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
@@ -52,7 +52,7 @@ module RuboCop
52
52
  each_missing_enable do |cop, line_range|
53
53
  next if acceptable_range?(cop, line_range)
54
54
 
55
- range = source_range(processed_source.buffer, line_range.min, (0..0))
55
+ range = source_range(processed_source.buffer, line_range.min, 0..0)
56
56
  comment = processed_source.comment_at_line(line_range.begin)
57
57
 
58
58
  add_offense(range, message: message(cop, comment))
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Lint
6
- # Checks for useless `rescue`s, which only reraise rescued exceptions.
6
+ # Checks for useless ``rescue``s, which only reraise rescued exceptions.
7
7
  #
8
8
  # @example
9
9
  # # bad
@@ -32,7 +32,7 @@ module RuboCop
32
32
  # @param [String] cop_name for specific cop name
33
33
  # @param [Hash] cop_config configs for specific cop, from config#for_cop
34
34
  # @option cop_config [String] :StyleGuide Extension of base styleguide URL
35
- # @option cop_config [String] :Reference Full reference URL
35
+ # @option cop_config [String] :References Full reference URLs
36
36
  # @option cop_config [String] :Details
37
37
  #
38
38
  # @param [Hash, nil] options optional
@@ -100,8 +100,12 @@ module RuboCop
100
100
  end
101
101
 
102
102
  def reference_urls
103
- urls = Array(cop_config['Reference'])
104
- urls.nil? || urls.empty? ? nil : urls.reject(&:empty?)
103
+ urls = cop_config
104
+ .values_at('References', 'Reference') # Support legacy Reference key
105
+ .flat_map { Array(_1) }
106
+ .reject(&:empty?)
107
+
108
+ urls unless urls.empty?
105
109
  end
106
110
 
107
111
  def extra_details?
@@ -17,6 +17,8 @@ module RuboCop
17
17
 
18
18
  lhs = left_hand_side(node.receiver)
19
19
  rhs = right_hand_side(node)
20
+ return unless rhs
21
+
20
22
  range = offending_range(node, lhs, rhs, style)
21
23
  check(range, node, lhs, rhs)
22
24
  end
@@ -136,9 +136,9 @@ module RuboCop
136
136
  end
137
137
 
138
138
  def last_item_precedes_newline?(node)
139
- after_last_item =
140
- range_between(node.children.last.source_range.end_pos, node.loc.end.begin_pos)
141
- after_last_item.source =~ /\A,?\s*\n/
139
+ after_last_item = node.children.last.source_range.end.join(node.loc.end.begin)
140
+
141
+ after_last_item.source.start_with?(/,?\s*(#.*)?\n/)
142
142
  end
143
143
 
144
144
  def avoid_comma(kind, comma_begin_pos, extra_info)
@@ -16,16 +16,16 @@ module RuboCop
16
16
  #
17
17
  # In Ruby 3.2, anonymous args/kwargs forwarding has been added.
18
18
  #
19
- # This cop also identifies places where `use_args(*args)`/`use_kwargs(**kwargs)` can be
20
- # replaced by `use_args(*)`/`use_kwargs(**)`; if desired, this functionality can be disabled
21
- # by setting `UseAnonymousForwarding: false`.
19
+ # This cop also identifies places where `+use_args(*args)+`/`+use_kwargs(**kwargs)+` can be
20
+ # replaced by `+use_args(*)+`/`+use_kwargs(**)+`; if desired, this functionality can be
21
+ # disabled by setting `UseAnonymousForwarding: false`.
22
22
  #
23
23
  # And this cop has `RedundantRestArgumentNames`, `RedundantKeywordRestArgumentNames`,
24
24
  # and `RedundantBlockArgumentNames` options. This configuration is a list of redundant names
25
25
  # that are sufficient for anonymizing meaningless naming.
26
26
  #
27
27
  # Meaningless names that are commonly used can be anonymized by default:
28
- # e.g., `*args`, `**options`, `&block`, and so on.
28
+ # e.g., `+*args+`, `+**options+`, `&block`, and so on.
29
29
  #
30
30
  # Names not on this list are likely to be meaningful and are allowed by default.
31
31
  #
@@ -131,13 +131,19 @@ module RuboCop
131
131
  "#{node.body.children.first.const_name}"
132
132
  end
133
133
 
134
+ # rubocop:disable Metrics/AbcSize
134
135
  def remove_end(corrector, body)
135
- remove_begin_pos = body.loc.end.begin_pos - leading_spaces(body).size
136
+ remove_begin_pos = if same_line?(body.loc.name, body.loc.end)
137
+ body.loc.name.end_pos
138
+ else
139
+ body.loc.end.begin_pos - leading_spaces(body).size
140
+ end
136
141
  adjustment = processed_source.raw_source[remove_begin_pos] == ';' ? 0 : 1
137
142
  range = range_between(remove_begin_pos, body.loc.end.end_pos + adjustment)
138
143
 
139
144
  corrector.remove(range)
140
145
  end
146
+ # rubocop:enable Metrics/AbcSize
141
147
 
142
148
  def unindent(corrector, node)
143
149
  return unless node.body.children.last
@@ -58,7 +58,7 @@ module RuboCop
58
58
  REGEXP = /(?<keyword>\S+).*#/.freeze
59
59
 
60
60
  SUBCLASS_DEFINITION = /\A\s*class\s+(\w|::)+\s*<\s*(\w|::)+/.freeze
61
- METHOD_DEFINITION = /\A\s*def\s/.freeze
61
+ METHOD_OR_END_DEFINITIONS = /\A\s*(def\s|end)/.freeze
62
62
 
63
63
  STEEP_REGEXP = /#\ssteep:ignore(\s|\z)/.freeze
64
64
 
@@ -102,7 +102,7 @@ module RuboCop
102
102
  case line
103
103
  when SUBCLASS_DEFINITION
104
104
  comment.text.start_with?(/#\[.+\]/)
105
- when METHOD_DEFINITION
105
+ when METHOD_OR_END_DEFINITIONS
106
106
  comment.text.start_with?('#:')
107
107
  else
108
108
  false
@@ -314,6 +314,7 @@ module RuboCop
314
314
 
315
315
  def assignment_node(node)
316
316
  assignment = node.send_type? ? node.last_argument : node.expression
317
+ return unless assignment
317
318
 
318
319
  # ignore pseudo-assignments without rhs in for nodes
319
320
  return if node.parent&.for_type?
@@ -436,7 +437,7 @@ module RuboCop
436
437
  # Helper module to provide common methods to ConditionalAssignment
437
438
  # correctors
438
439
  module ConditionalCorrectorHelper
439
- # rubocop:disable Metrics/AbcSize
440
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
440
441
  def remove_whitespace_in_branches(corrector, branch, condition, column)
441
442
  branch.each_node do |child|
442
443
  next if child.source_range.nil?
@@ -446,13 +447,19 @@ module RuboCop
446
447
  corrector.remove(white_space) if white_space.source.strip.empty?
447
448
  end
448
449
 
449
- [condition.loc.else, condition.loc.end].each do |loc|
450
- next unless loc
451
-
452
- corrector.remove_preceding(loc, loc.column - column)
450
+ if condition.loc.else && !same_line?(condition.else_branch, condition)
451
+ corrector.remove_preceding(condition.loc.else, condition.loc.else.column - column)
453
452
  end
453
+
454
+ return unless condition.loc.end && !same_line?(condition.loc.end, condition)
455
+
456
+ corrector.remove_preceding(condition.loc.end, condition.loc.end.column - column)
457
+ end
458
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
459
+
460
+ def same_line?(node1, node2)
461
+ RuboCop::Cop::Util.same_line?(node1, node2)
454
462
  end
455
- # rubocop:enable Metrics/AbcSize
456
463
 
457
464
  def white_space_range(node, column)
458
465
  expression = node.source_range
@@ -598,6 +605,8 @@ module RuboCop
598
605
 
599
606
  return unless (branch_else = branch.parent.loc.else)
600
607
 
608
+ return if same_line?(branch_else, condition)
609
+
601
610
  corrector.remove_preceding(branch_else, branch_else.column - column)
602
611
  end
603
612
  end
@@ -4,12 +4,12 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  # Ensures that eval methods (`eval`, `instance_eval`, `class_eval`
7
- # and `module_eval`) are given filename and line number values (`\_\_FILE\_\_`
8
- # and `\_\_LINE\_\_`). This data is used to ensure that any errors raised
7
+ # and `module_eval`) are given filename and line number values (`+__FILE__+`
8
+ # and `+__LINE__+`). This data is used to ensure that any errors raised
9
9
  # within the evaluated code will be given the correct identification
10
10
  # in a backtrace.
11
11
  #
12
- # The cop also checks that the line number given relative to `\_\_LINE\_\_` is
12
+ # The cop also checks that the line number given relative to `+__LINE__+` is
13
13
  # correct.
14
14
  #
15
15
  # This cop will autocorrect incorrect or missing filename and line number
@@ -40,7 +40,6 @@ module RuboCop
40
40
  class HashFetchChain < Base
41
41
  extend AutoCorrector
42
42
  extend TargetRubyVersion
43
- include IgnoredNode
44
43
 
45
44
  MSG = 'Use `%<replacement>s` instead.'
46
45
  RESTRICT_ON_SEND = %i[fetch].freeze
@@ -3,8 +3,8 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Style
6
- # Looks for uses of `\_.each_with_object({}) {...}`,
7
- # `\_.map {...}.to_h`, and `Hash[\_.map {...}]` that are actually just
6
+ # Looks for uses of `+_.each_with_object({}) {...}+`,
7
+ # `+_.map {...}.to_h+`, and `+Hash[_.map {...}]+` that are actually just
8
8
  # transforming the keys of a hash, and tries to use a simpler & faster
9
9
  # call to `transform_keys` instead.
10
10
  # It should only be enabled on Ruby version 2.5 or newer.
@@ -3,8 +3,8 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Style
6
- # Looks for uses of `\_.each_with_object({}) {...}`,
7
- # `\_.map {...}.to_h`, and `Hash[\_.map {...}]` that are actually just
6
+ # Looks for uses of `+_.each_with_object({}) {...}+`,
7
+ # `+_.map {...}.to_h+`, and `+Hash[_.map {...}]+` that are actually just
8
8
  # transforming the values of a hash, and tries to use a simpler & faster
9
9
  # call to `transform_values` instead.
10
10
  #
@@ -10,7 +10,7 @@ module RuboCop
10
10
  # `nonzero?` method is allowed by default.
11
11
  # These are customizable with `AllowedMethods` option.
12
12
  #
13
- # This cop targets only `if`s with a single `elsif` or `else` branch. The following
13
+ # This cop targets only ``if``s with a single `elsif` or `else` branch. The following
14
14
  # code will be allowed, because it has two `elsif` branches:
15
15
  #
16
16
  # [source,ruby]
@@ -54,9 +54,14 @@ module RuboCop
54
54
 
55
55
  def prefer(node)
56
56
  receiver = node.receiver.source
57
- arguments = node.arguments.map(&:source).join(', ')
58
57
  dot = node.loc.dot.source
59
- method = explicit_style? ? "call(#{arguments})" : "(#{arguments})"
58
+ call_arguments = if node.arguments.empty?
59
+ ''
60
+ else
61
+ arguments = node.arguments.map(&:source).join(', ')
62
+ "(#{arguments})"
63
+ end
64
+ method = explicit_style? ? "call#{call_arguments}" : "(#{arguments})"
60
65
 
61
66
  "#{receiver}#{dot}#{method}"
62
67
  end
@@ -212,9 +212,11 @@ module RuboCop
212
212
  end
213
213
 
214
214
  def correct_push_node(corrector, push_node)
215
+ arg_node = push_node.first_argument
215
216
  range = push_node.source_range
216
- arg_range = push_node.first_argument.source_range
217
+ arg_range = arg_node.source_range
217
218
 
219
+ corrector.wrap(arg_node, '{ ', ' }') if arg_node.hash_type? && !arg_node.braces?
218
220
  corrector.remove(range_between(range.begin_pos, arg_range.begin_pos))
219
221
  corrector.remove(range_between(arg_range.end_pos, range.end_pos))
220
222
  end
@@ -20,7 +20,7 @@ module RuboCop
20
20
 
21
21
  MSG = 'Remove the redundant current directory path.'
22
22
  RESTRICT_ON_SEND = %i[require_relative].freeze
23
- CURRENT_DIRECTORY_PREFIX = %r{./+}.freeze
23
+ CURRENT_DIRECTORY_PREFIX = %r{\./+}.freeze
24
24
  REDUNDANT_CURRENT_DIRECTORY_PREFIX = /\A#{CURRENT_DIRECTORY_PREFIX}/.freeze
25
25
 
26
26
  def on_send(node)
@@ -181,9 +181,7 @@ module RuboCop
181
181
  ARGUMENT_TYPES.include?(next_token.type)
182
182
  end
183
183
 
184
- # rubocop:disable Metrics/AbcSize
185
184
  def argument_newline?(node)
186
- node = node.to_a.last if node.assignment?
187
185
  return false if node.parenthesized_call?
188
186
 
189
187
  node = node.children.first if node.root? && node.begin_type?
@@ -196,7 +194,6 @@ module RuboCop
196
194
  node.loc.selector.line != node.first_argument.loc.line
197
195
  end
198
196
  end
199
- # rubocop:enable Metrics/AbcSize
200
197
 
201
198
  def find_node_for_line(last_line)
202
199
  processed_source.ast.each_node do |node|
@@ -78,7 +78,7 @@ module RuboCop
78
78
  ancestor = node.ancestors.first
79
79
  return false unless ancestor
80
80
 
81
- !ancestor.type?(:begin, :def, :any_block)
81
+ !ancestor.type?(:begin, :any_def, :any_block)
82
82
  end
83
83
 
84
84
  def allowed_ternary?(node)
@@ -98,7 +98,7 @@ module RuboCop
98
98
  return false unless node.type?(:send, :super, :yield)
99
99
 
100
100
  node.arguments.one? && !node.parenthesized? &&
101
- !node.arithmetic_operation? && node.first_argument.begin_type?
101
+ !node.operator_method? && node.first_argument.begin_type?
102
102
  end
103
103
 
104
104
  def multiline_control_flow_statements?(node)
@@ -134,7 +134,9 @@ module RuboCop
134
134
  node = begin_node.children.first
135
135
 
136
136
  if (message = find_offense_message(begin_node, node))
137
- begin_node = begin_node.parent if node.range_type?
137
+ if node.range_type? && !argument_of_parenthesized_method_call?(begin_node)
138
+ begin_node = begin_node.parent
139
+ end
138
140
 
139
141
  return offense(begin_node, message)
140
142
  end
@@ -155,6 +157,7 @@ module RuboCop
155
157
  return 'an expression'
156
158
  end
157
159
  return 'an interpolated expression' if interpolation?(begin_node)
160
+ return 'a method argument' if argument_of_parenthesized_method_call?(begin_node)
158
161
 
159
162
  return if begin_node.chained?
160
163
 
@@ -177,6 +180,12 @@ module RuboCop
177
180
  # @!method interpolation?(node)
178
181
  def_node_matcher :interpolation?, '[^begin ^^dstr]'
179
182
 
183
+ def argument_of_parenthesized_method_call?(node)
184
+ return false unless (parent = node.parent)
185
+
186
+ parent.call_type? && parent.parenthesized? && parent.receiver != node
187
+ end
188
+
180
189
  def allow_in_multiline_conditions?
181
190
  !!config.for_enabled_cop('Style/ParenthesesAroundCondition')['AllowInMultilineConditions']
182
191
  end
@@ -174,12 +174,17 @@ module RuboCop
174
174
  range_with_surrounding_space(range: lhs.source_range, side: :right),
175
175
  range_with_surrounding_space(range: lhs_operator_range, side: :right),
176
176
  offense_range: range_between(lhs.source_range.begin_pos, rhs.source_range.end_pos)
177
- )
177
+ ) do |corrector|
178
+ corrector.replace(rhs_receiver, lhs_receiver.source)
179
+ end
180
+ ignore_node(node)
178
181
  end
179
182
  end
180
183
 
181
184
  def report_offense(node, rhs, rhs_receiver, *removal_ranges, offense_range: node)
182
185
  add_offense(offense_range) do |corrector|
186
+ next if ignored_node?(node)
187
+
183
188
  # If the RHS is an `or` we cannot safely autocorrect because in order to remove
184
189
  # the non-nil check we need to add safe-navs to all clauses where the receiver is used
185
190
  next if and_with_rhs_or?(node)
@@ -227,7 +232,7 @@ module RuboCop
227
232
  end
228
233
 
229
234
  def offending_node?(node, lhs_receiver, rhs, rhs_receiver) # rubocop:disable Metrics/CyclomaticComplexity
230
- return false if lhs_receiver != rhs_receiver || rhs_receiver.nil?
235
+ return false if !matching_nodes?(lhs_receiver, rhs_receiver) || rhs_receiver.nil?
231
236
  return false if use_var_only_in_unless_modifier?(node, lhs_receiver)
232
237
  return false if chain_length(rhs, rhs_receiver) > max_chain_length
233
238
  return false if unsafe_method_used?(rhs, rhs_receiver.parent)
@@ -306,11 +311,21 @@ module RuboCop
306
311
 
307
312
  receiver = method_chain.receiver
308
313
 
309
- return receiver if receiver == checked_variable
314
+ return receiver if matching_nodes?(receiver, checked_variable)
310
315
 
311
316
  find_matching_receiver_invocation(receiver, checked_variable)
312
317
  end
313
318
 
319
+ def matching_nodes?(left, right)
320
+ left == right || matching_call_nodes?(left, right)
321
+ end
322
+
323
+ def matching_call_nodes?(left, right)
324
+ return false unless left && right
325
+
326
+ left.call_type? && right.call_type? && left.children == right.children
327
+ end
328
+
314
329
  def chain_length(method_chain, method)
315
330
  method.each_ancestor(:call).inject(0) do |total, ancestor|
316
331
  break total + 1 if ancestor == method_chain
@@ -11,7 +11,7 @@ module RuboCop
11
11
  # * `comma`: Requires a comma after the last item in an array, but only when each item is on
12
12
  # its own line.
13
13
  # * `diff_comma`: Requires a comma after the last item in an array, but only when that item is
14
- # followed by an immediate newline.
14
+ # followed by an immediate newline, even if there is an inline comment on the same line.
15
15
  # * `no_comma`: Does not require a comma after the last item in an array
16
16
  #
17
17
  # @example EnforcedStyleForMultiline: consistent_comma
@@ -11,7 +11,7 @@ module RuboCop
11
11
  # * `comma`: Requires a comma after the last item in a hash, but only when each item is on its
12
12
  # own line.
13
13
  # * `diff_comma`: Requires a comma after the last item in a hash, but only when that item is
14
- # followed by an immediate newline.
14
+ # followed by an immediate newline, even if there is an inline comment on the same line.
15
15
  # * `no_comma`: Does not require a comma after the last item in a hash
16
16
  #
17
17
  # @example EnforcedStyleForMultiline: consistent_comma
@@ -327,8 +327,12 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
327
327
  def print_cop_with_doc(cop) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
328
328
  cop_config = config.for_cop(cop)
329
329
  non_display_keys = %w[
330
- AutoCorrect Description Enabled StyleGuide Reference Safe SafeAutoCorrect VersionAdded
331
- VersionChanged
330
+ Enabled
331
+ Description
332
+ StyleGuide
333
+ Reference References
334
+ Safe SafeAutoCorrect AutoCorrect
335
+ VersionAdded VersionChanged
332
336
  ]
333
337
  parameters = cop_config.reject { |k| non_display_keys.include? k }
334
338
  description = 'No documentation'
@@ -164,7 +164,7 @@ module RuboCop
164
164
 
165
165
  def cop_config_params(default_cfg, cfg)
166
166
  default_cfg.keys -
167
- %w[Description StyleGuide Reference Enabled Exclude Safe
167
+ %w[Description StyleGuide Reference References Enabled Exclude Safe
168
168
  SafeAutoCorrect VersionAdded VersionChanged VersionRemoved] -
169
169
  cfg.keys
170
170
  end
@@ -58,7 +58,7 @@ module RuboCop
58
58
  return pacdots(@total_files) unless @total_files > cols
59
59
  return pacdots(cols) unless (@total_files / cols).eql?(@repetitions)
60
60
 
61
- pacdots((@total_files - (cols * @repetitions)))
61
+ pacdots(@total_files - (cols * @repetitions))
62
62
  end
63
63
 
64
64
  def pacdots(number)
@@ -46,7 +46,11 @@ module RuboCop
46
46
  hidden_files = all_files.select { |file| file.include?(HIDDEN_PATH_SUBSTRING) }.sort
47
47
  base_dir_config = @config_store.for(base_dir)
48
48
 
49
- target_files = all_files.select { |file| to_inspect?(file, hidden_files, base_dir_config) }
49
+ target_files = if base_dir.include?(HIDDEN_PATH_SUBSTRING)
50
+ all_files.select { |file| ruby_file?(file) }
51
+ else
52
+ all_files.select { |file| to_inspect?(file, hidden_files, base_dir_config) }
53
+ end
50
54
 
51
55
  target_files.sort_by!(&order)
52
56
  end
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.75.2'
6
+ STRING = '1.75.3'
7
7
 
8
8
  MSG = '%<version>s (using %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.75.2
4
+ version: 1.75.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -9,7 +9,7 @@ authors:
9
9
  - Yuji Nakayama
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2025-04-03 00:00:00.000000000 Z
12
+ date: 2025-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -1080,7 +1080,7 @@ licenses:
1080
1080
  - MIT
1081
1081
  metadata:
1082
1082
  homepage_uri: https://rubocop.org/
1083
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.2
1083
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.3
1084
1084
  source_code_uri: https://github.com/rubocop/rubocop/
1085
1085
  documentation_uri: https://docs.rubocop.org/rubocop/1.75/
1086
1086
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues