rubocop 1.75.5 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9421b54201da724554271e44969dd9b78ea86635ba622fd5d3f1807d9e3e3530
4
- data.tar.gz: 6f76b18333faee3119a32957b72a5906a9a99cde620b95dc88014b1ebdbfa4f7
3
+ metadata.gz: 4692afe0e994fae9d158ac440d48f460623d28bbad07fc7ccf141aa3737e82a1
4
+ data.tar.gz: 3dba40c9526a877cdc7269d54b3c89e3d64f8147cb5e2b885146c1d02d94bc19
5
5
  SHA512:
6
- metadata.gz: bfbad1a5c263aa4de3704954e0835a71d4d6b56bbf564dfec23dc1cc7b75913ae064ddf70a01c942a1ebfb3502fe881d840826a306ce24ed450747058f59541e
7
- data.tar.gz: 88be3812e81036e0e8dde18c38548052f447ae76cf3195fc1b16189eb4c5d7e5b460f8425ecee663d96bfcb4c543f592f8471b7306906262426894fa76301da1
6
+ metadata.gz: acd7a48eac01d73747fb22cef86c75c4b2da8a910f341ddda19572eabd9126e8a42edac565df8ce0e6946e69f44d892e08c358dd9c6d72455974c05277731e3e
7
+ data.tar.gz: 2afef8e39089e476050a24aa63e4f637a4765759b31c74672740fb86067dada674140574c61a0d426950ea57e36c7b5bdc00db5cbab14e0000fa7aa065e83c6c
data/config/default.yml CHANGED
@@ -3702,7 +3702,9 @@ Style/CommentedKeyword:
3702
3702
  Style/ComparableBetween:
3703
3703
  Description: 'Enforces the use of `Comparable#between?` instead of logical comparison.'
3704
3704
  Enabled: pending
3705
+ Safe: false
3705
3706
  VersionAdded: '1.74'
3707
+ VersionChanged: '1.75'
3706
3708
  StyleGuide: '#ranges-or-between'
3707
3709
 
3708
3710
  Style/ComparableClamp:
@@ -87,6 +87,7 @@ module RuboCop
87
87
  return if node.array_type? && !node.square_brackets?
88
88
 
89
89
  tokens, left, right = array_brackets(node)
90
+ return unless left && right
90
91
 
91
92
  if empty_brackets?(left, right, tokens: tokens)
92
93
  return empty_offenses(node, left, right, EMPTY_MSG)
@@ -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
 
@@ -39,9 +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
69
+ RESTRICT_ON_SEND = %i[alias_method attr_reader attr_writer attr_accessor attr
70
+ delegate].freeze
45
71
 
46
72
  def initialize(config = nil, options = nil)
47
73
  super
@@ -85,15 +111,25 @@ module RuboCop
85
111
  (send nil? :alias_method (sym $_name) _)
86
112
  PATTERN
87
113
 
114
+ # @!method delegate_method?(node)
115
+ def_node_matcher :delegate_method?, <<~PATTERN
116
+ (send nil? :delegate (sym $_)+ (hash _))
117
+ PATTERN
118
+
88
119
  # @!method sym_name(node)
89
120
  def_node_matcher :sym_name, '(sym $_name)'
90
- def on_send(node)
121
+
122
+ def on_send(node) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
91
123
  if (name = alias_method?(node))
92
124
  return if node.ancestors.any?(&:if_type?)
93
125
 
94
126
  found_instance_method(node, name)
95
127
  elsif (attr = node.attribute_accessor?)
96
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)
97
133
  end
98
134
  end
99
135
 
@@ -118,6 +154,12 @@ module RuboCop
118
154
  current: source_location(node))
119
155
  end
120
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
+
121
163
  def found_instance_method(node, name)
122
164
  return found_sclass_method(node, name) unless (scope = node.parent_module_name)
123
165
 
@@ -104,6 +104,8 @@ module RuboCop
104
104
  end
105
105
 
106
106
  def chained_assignment?(node)
107
+ return true if node.lvasgn_type? && node.expression&.send_type?
108
+
107
109
  node.respond_to?(:expression) && node.expression&.lvasgn_type?
108
110
  end
109
111
 
@@ -9,6 +9,9 @@ module RuboCop
9
9
  # although the difference generally isn't observable. If you require maximum
10
10
  # performance, consider using logical comparison.
11
11
  #
12
+ # @safety
13
+ # This cop is unsafe because the receiver may not respond to `between?`.
14
+ #
12
15
  # @example
13
16
  #
14
17
  # # bad
@@ -4,6 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  # Checks for inheritance from `Data.define` to avoid creating the anonymous parent class.
7
+ # Inheriting from `Data.define` 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>, Data, (...)]
23
+ #
20
24
  # # good
21
25
  # Person = Data.define(:first_name, :last_name) do
22
26
  # def age
23
27
  # 42
24
28
  # end
25
29
  # end
30
+ #
31
+ # Person.ancestors
32
+ # # => [Person, Data, (...)]
26
33
  class DataInheritance < Base
27
34
  include RangeHelp
28
35
  extend AutoCorrector
@@ -23,6 +23,17 @@ module RuboCop
23
23
  # end
24
24
  # ----
25
25
  #
26
+ # The code `def method_name = body if condition` is considered a bad case by
27
+ # `Style/AmbiguousEndlessMethodDefinition` cop. So, to respect the user's intention to use
28
+ # an endless method definition in the `if` body, the following code is allowed:
29
+ #
30
+ # [source,ruby]
31
+ # ----
32
+ # if condition
33
+ # def method_name = body
34
+ # end
35
+ # ----
36
+ #
26
37
  # NOTE: It is allowed when `defined?` argument has an undefined value,
27
38
  # because using the modifier form causes the following incompatibility:
28
39
  #
@@ -77,10 +88,14 @@ module RuboCop
77
88
  [Style::SoleNestedConditional]
78
89
  end
79
90
 
91
+ # rubocop:disable Metrics/AbcSize
80
92
  def on_if(node)
93
+ return if endless_method?(node.body)
94
+
81
95
  condition = node.condition
82
96
  return if defined_nodes(condition).any? { |n| defined_argument_is_undefined?(node, n) } ||
83
97
  pattern_matching_nodes(condition).any?
98
+
84
99
  return unless (msg = message(node))
85
100
 
86
101
  add_offense(node.loc.keyword, message: format(msg, keyword: node.keyword)) do |corrector|
@@ -90,9 +105,14 @@ module RuboCop
90
105
  ignore_node(node)
91
106
  end
92
107
  end
108
+ # rubocop:enable Metrics/AbcSize
93
109
 
94
110
  private
95
111
 
112
+ def endless_method?(body)
113
+ body&.any_def_type? && body.endless?
114
+ end
115
+
96
116
  def defined_nodes(condition)
97
117
  if condition.defined_type?
98
118
  [condition]
@@ -23,11 +23,13 @@ module RuboCop
23
23
  'clause in a multiline statement.'
24
24
 
25
25
  def on_if(node)
26
+ return if part_of_ignored_node?(node)
26
27
  return unless node.modifier_form? && node.body.multiline?
27
28
 
28
29
  add_offense(node, message: format(MSG, keyword: node.keyword)) do |corrector|
29
30
  corrector.replace(node, to_normal_if(node))
30
31
  end
32
+ ignore_node(node)
31
33
  end
32
34
 
33
35
  private
@@ -45,7 +45,7 @@ module RuboCop
45
45
  # Report offense only if changing case doesn't change semantics,
46
46
  # i.e., if the string would become dynamic or has special characters.
47
47
  ast = parse(corrected(node.source)).ast
48
- return if node.children != ast.children
48
+ return if node.children != ast&.children
49
49
 
50
50
  add_offense(node.loc.begin) do |corrector|
51
51
  corrector.replace(node, corrected(node.source))
@@ -185,8 +185,10 @@ module RuboCop
185
185
  end
186
186
 
187
187
  def add_parentheses?(node)
188
- node.assignment? || (node.operator_keyword? && !node.and_type?) ||
189
- (node.call_type? && node.arguments.any? && !node.parenthesized?)
188
+ return true if node.assignment? || (node.operator_keyword? && !node.and_type?)
189
+ return false unless node.call_type?
190
+
191
+ (node.arguments.any? && !node.parenthesized?) || node.prefix_not?
190
192
  end
191
193
 
192
194
  def parenthesized_method_arguments(node)
@@ -51,7 +51,6 @@ module RuboCop
51
51
  # Pathname.new('/') + 'test'
52
52
  #
53
53
  class StringConcatenation < Base
54
- include RangeHelp
55
54
  extend AutoCorrector
56
55
 
57
56
  MSG = 'Prefer string interpolation to string concatenation.'
@@ -147,7 +146,7 @@ module RuboCop
147
146
  when :str
148
147
  adjust_str(part)
149
148
  when :dstr
150
- part.children.all?(&:str_type?) ? adjust_str(part) : contents_range(part).source
149
+ part.children.all?(&:str_type?) ? adjust_str(part) : part.value
151
150
  else
152
151
  "\#{#{part.source}}"
153
152
  end
@@ -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
@@ -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
@@ -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.5'
6
+ STRING = '1.75.6'
7
7
 
8
8
  MSG = '%<version>s (using %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.75.5
4
+ version: 1.75.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
8
8
  - Jonas Arvidsson
9
9
  - Yuji Nakayama
10
- autorequire:
11
10
  bindir: exe
12
11
  cert_chain: []
13
- date: 2025-05-05 00:00:00.000000000 Z
12
+ date: 2025-05-15 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: json
@@ -1081,12 +1080,11 @@ licenses:
1081
1080
  - MIT
1082
1081
  metadata:
1083
1082
  homepage_uri: https://rubocop.org/
1084
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.5
1083
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.6
1085
1084
  source_code_uri: https://github.com/rubocop/rubocop/
1086
1085
  documentation_uri: https://docs.rubocop.org/rubocop/1.75/
1087
1086
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
1088
1087
  rubygems_mfa_required: 'true'
1089
- post_install_message:
1090
1088
  rdoc_options: []
1091
1089
  require_paths:
1092
1090
  - lib
@@ -1101,8 +1099,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1101
1099
  - !ruby/object:Gem::Version
1102
1100
  version: '0'
1103
1101
  requirements: []
1104
- rubygems_version: 3.3.7
1105
- signing_key:
1102
+ rubygems_version: 3.6.2
1106
1103
  specification_version: 4
1107
1104
  summary: Automatic Ruby code style checking tool.
1108
1105
  test_files: []