rubocop 1.75.3 → 1.75.8

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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +2 -0
  3. data/lib/rubocop/cop/autocorrect_logic.rb +18 -10
  4. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +49 -5
  5. data/lib/rubocop/cop/layout/class_structure.rb +35 -0
  6. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +6 -2
  7. data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
  8. data/lib/rubocop/cop/layout/hash_alignment.rb +1 -1
  9. data/lib/rubocop/cop/layout/leading_comment_space.rb +13 -1
  10. data/lib/rubocop/cop/layout/space_after_semicolon.rb +10 -0
  11. data/lib/rubocop/cop/layout/space_before_brackets.rb +6 -32
  12. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +5 -1
  13. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +3 -0
  14. data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +2 -3
  15. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
  16. data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -5
  17. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
  18. data/lib/rubocop/cop/lint/duplicate_methods.rb +84 -2
  19. data/lib/rubocop/cop/lint/float_comparison.rb +27 -0
  20. data/lib/rubocop/cop/lint/literal_as_condition.rb +25 -11
  21. data/lib/rubocop/cop/lint/useless_assignment.rb +2 -0
  22. data/lib/rubocop/cop/lint/void.rb +2 -2
  23. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  24. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +15 -14
  25. data/lib/rubocop/cop/mixin/trailing_comma.rb +6 -2
  26. data/lib/rubocop/cop/style/access_modifier_declarations.rb +32 -10
  27. data/lib/rubocop/cop/style/arguments_forwarding.rb +4 -1
  28. data/lib/rubocop/cop/style/class_and_module_children.rb +12 -2
  29. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  30. data/lib/rubocop/cop/style/comparable_between.rb +5 -2
  31. data/lib/rubocop/cop/style/data_inheritance.rb +7 -0
  32. data/lib/rubocop/cop/style/def_with_parentheses.rb +18 -5
  33. data/lib/rubocop/cop/style/identical_conditional_branches.rb +3 -3
  34. data/lib/rubocop/cop/style/if_unless_modifier.rb +20 -0
  35. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +4 -7
  36. data/lib/rubocop/cop/style/map_to_hash.rb +11 -0
  37. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +3 -0
  38. data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -0
  39. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  40. data/lib/rubocop/cop/style/redundant_format.rb +6 -1
  41. data/lib/rubocop/cop/style/redundant_parentheses.rb +11 -3
  42. data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
  43. data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
  44. data/lib/rubocop/cop/style/sole_nested_conditional.rb +4 -2
  45. data/lib/rubocop/cop/style/string_concatenation.rb +1 -2
  46. data/lib/rubocop/cop/style/struct_inheritance.rb +8 -1
  47. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +7 -1
  48. data/lib/rubocop/cop/team.rb +1 -1
  49. data/lib/rubocop/cop/variable_force/assignment.rb +7 -3
  50. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -0
  51. data/lib/rubocop/formatter/html_formatter.rb +1 -1
  52. data/lib/rubocop/rspec/cop_helper.rb +2 -2
  53. data/lib/rubocop/rspec/shared_contexts.rb +1 -2
  54. data/lib/rubocop/version.rb +1 -1
  55. metadata +3 -3
@@ -3,7 +3,8 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Style
6
- # Checks for inheritance from Struct.new.
6
+ # Checks for inheritance from `Struct.new`. Inheriting from `Struct.new`
7
+ # adds a superfluous level in inheritance tree.
7
8
  #
8
9
  # @safety
9
10
  # Autocorrection is unsafe because it will change the inheritance
@@ -17,12 +18,18 @@ module RuboCop
17
18
  # end
18
19
  # end
19
20
  #
21
+ # Person.ancestors
22
+ # # => [Person, #<Class:0x000000010b4e14a0>, Struct, (...)]
23
+ #
20
24
  # # good
21
25
  # Person = Struct.new(:first_name, :last_name) do
22
26
  # def age
23
27
  # 42
24
28
  # end
25
29
  # end
30
+ #
31
+ # Person.ancestors
32
+ # # => [Person, Struct, (...)]
26
33
  class StructInheritance < Base
27
34
  include RangeHelp
28
35
  extend AutoCorrector
@@ -79,10 +79,16 @@ module RuboCop
79
79
  # # bad
80
80
  # method(1, 2,)
81
81
  #
82
+ # # bad
83
+ # object[1, 2,]
84
+ #
82
85
  # # good
83
86
  # method(1, 2)
84
87
  #
85
88
  # # good
89
+ # object[1, 2]
90
+ #
91
+ # # good
86
92
  # method(
87
93
  # 1,
88
94
  # 2
@@ -96,7 +102,7 @@ module RuboCop
96
102
  end
97
103
 
98
104
  def on_send(node)
99
- return unless node.arguments? && node.parenthesized?
105
+ return unless node.arguments? && (node.parenthesized? || node.method?(:[]))
100
106
 
101
107
  check(node, node.arguments, 'parameter of %<article>s method call',
102
108
  node.last_argument.source_range.end_pos,
@@ -279,7 +279,7 @@ module RuboCop
279
279
  @errors << message
280
280
  warn message
281
281
  if debug?
282
- puts error.message, error.backtrace
282
+ puts error.full_message
283
283
  else
284
284
  warn 'To see the complete backtrace run rubocop -d.'
285
285
  end
@@ -110,8 +110,13 @@ module RuboCop
110
110
  end
111
111
 
112
112
  def multiple_assignment_node
113
- return nil unless node.parent&.mlhs_type?
114
- return nil unless (grandparent_node = node.parent&.parent)
113
+ return nil unless (candidate_mlhs_node = node.parent)
114
+
115
+ # In `(foo, bar), *baz`, the splat node must be traversed as well.
116
+ candidate_mlhs_node = candidate_mlhs_node.parent if candidate_mlhs_node.splat_type?
117
+
118
+ return nil unless candidate_mlhs_node.mlhs_type?
119
+ return nil unless (grandparent_node = node.parent.parent)
115
120
  if (node = find_multiple_assignment_node(grandparent_node))
116
121
  return node
117
122
  end
@@ -139,7 +144,6 @@ module RuboCop
139
144
 
140
145
  def find_multiple_assignment_node(grandparent_node)
141
146
  return unless grandparent_node.type == MULTIPLE_LEFT_HAND_SIDE_TYPE
142
- return if grandparent_node.children.any?(&:splat_type?)
143
147
 
144
148
  parent = grandparent_node.parent
145
149
  return parent if parent.type == MULTIPLE_ASSIGNMENT_TYPE
@@ -178,6 +178,7 @@ module RuboCop
178
178
  next unless value.is_a?(Array)
179
179
  next if value.empty?
180
180
 
181
+ value.map! { |v| v.nil? ? '~' : v } # Change nil back to ~ as in the YAML file.
181
182
  output_buffer.puts "# #{param}: #{value.uniq.join(', ')}"
182
183
  end
183
184
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cgi'
3
+ require 'cgi/escape'
4
4
  require 'erb'
5
5
 
6
6
  module RuboCop
@@ -11,8 +11,8 @@ module CopHelper
11
11
  ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : RuboCop::TargetRuby::DEFAULT_VERSION
12
12
  end
13
13
  let(:parser_engine) do
14
- # The maximum version Parser can parse is 3.4.
15
- ruby_version >= 3.5 ? :parser_prism : ENV.fetch('PARSER_ENGINE', :parser_whitequark).to_sym
14
+ # The maximum version Parser can correctly parse is 3.3.
15
+ ruby_version >= 3.4 ? :parser_prism : ENV.fetch('PARSER_ENGINE', :parser_whitequark).to_sym
16
16
  end
17
17
  let(:rails_version) { false }
18
18
 
@@ -267,6 +267,5 @@ RSpec.shared_context 'ruby 3.4' do
267
267
  end
268
268
 
269
269
  RSpec.shared_context 'ruby 3.5' do
270
- # Parser supports parsing Ruby <= 3.4.
271
- let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.5 : 3.4 }
270
+ let(:ruby_version) { 3.5 }
272
271
  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.3'
6
+ STRING = '1.75.8'
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.3
4
+ version: 1.75.8
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-22 00:00:00.000000000 Z
12
+ date: 2025-05-28 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.3
1083
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.8
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