rubocop-rails 2.30.2 → 2.31.0
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 +4 -4
- data/README.md +2 -1
- data/config/default.yml +17 -1
- data/lib/rubocop/cop/mixin/active_record_helper.rb +1 -1
- data/lib/rubocop/cop/mixin/active_record_migrations_helper.rb +2 -2
- data/lib/rubocop/cop/mixin/database_type_resolvable.rb +2 -2
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +6 -1
- data/lib/rubocop/cop/mixin/index_method.rb +2 -1
- data/lib/rubocop/cop/rails/arel_star.rb +5 -5
- data/lib/rubocop/cop/rails/delegate.rb +3 -0
- data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +1 -3
- data/lib/rubocop/cop/rails/index_by.rb +9 -0
- data/lib/rubocop/cop/rails/index_with.rb +9 -0
- data/lib/rubocop/cop/rails/output.rb +1 -2
- data/lib/rubocop/cop/rails/pluck.rb +10 -4
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +6 -1
- data/lib/rubocop/cop/rails/reflection_class_name.rb +2 -2
- data/lib/rubocop/cop/rails/relative_date_constant.rb +1 -1
- data/lib/rubocop/cop/rails/reversible_migration.rb +2 -1
- data/lib/rubocop/cop/rails/save_bang.rb +2 -2
- data/lib/rubocop/cop/rails/schema_comment.rb +1 -1
- data/lib/rubocop/cop/rails/transaction_exit_statement.rb +2 -2
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +1 -1
- data/lib/rubocop/rails/version.rb +1 -1
- data/lib/rubocop-rails.rb +0 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba4876948bedd432dc186a3c060c26c3808f1c7126b8fe69072e056a5f160d94
|
4
|
+
data.tar.gz: 7f890ec180a125abe4a40ad146661e71c088596eb093eacf12d322135c7f6907
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 719fd043fd8ae7738eebb0c78abba01a23f2bc30c6d8c9825c89c7cbcc6cd48fd0077918e9bc84c9c471afecd62b69597d3f046c757606ecaec4af9daf8ef183
|
7
|
+
data.tar.gz: b7173eeaf159ee8673fe2f2c16a1c92bcbb55601d1202db18e5b48d09d1d1ef0207c17a182dcfb2b39c6e686d2b82871b191d5f90c4416a1af7d7b038a12c218
|
data/README.md
CHANGED
@@ -5,7 +5,8 @@
|
|
5
5
|
|
6
6
|
A [RuboCop](https://github.com/rubocop/rubocop) extension focused on enforcing Rails best practices and coding conventions.
|
7
7
|
|
8
|
-
|
8
|
+
> [!IMPORTANT]
|
9
|
+
> This repository manages rubocop-rails gem (>= 2.0.0). rubocop-rails gem (<= 1.5.0) has been renamed to [rubocop-rails_config](https://rubygems.org/gems/rubocop-rails_config) gem.
|
9
10
|
|
10
11
|
## Installation
|
11
12
|
|
data/config/default.yml
CHANGED
@@ -77,6 +77,20 @@ Lint/SafeNavigationChain:
|
|
77
77
|
- try!
|
78
78
|
- in?
|
79
79
|
|
80
|
+
Lint/UselessAccessModifier:
|
81
|
+
# Add methods from `ActiveSupport::Concern` and `Module::Concerning`:
|
82
|
+
# https://api.rubyonrails.org/classes/ActiveSupport/Concern.html
|
83
|
+
# https://api.rubyonrails.org/classes/Module/Concerning
|
84
|
+
inherit_mode:
|
85
|
+
merge:
|
86
|
+
- ContextCreatingMethods
|
87
|
+
ContextCreatingMethods:
|
88
|
+
- class_methods
|
89
|
+
- included
|
90
|
+
- prepended
|
91
|
+
- concern
|
92
|
+
- concerning
|
93
|
+
|
80
94
|
Rails:
|
81
95
|
Enabled: true
|
82
96
|
DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails
|
@@ -353,11 +367,13 @@ Rails/Delegate:
|
|
353
367
|
Description: 'Prefer delegate method for delegations.'
|
354
368
|
Enabled: true
|
355
369
|
VersionAdded: '0.21'
|
356
|
-
VersionChanged: '
|
370
|
+
VersionChanged: '2.30'
|
357
371
|
# When set to true, using the target object as a prefix of the
|
358
372
|
# method name without using the `delegate` method will be a
|
359
373
|
# violation. When set to false, this case is legal.
|
360
374
|
EnforceForPrefixed: true
|
375
|
+
Exclude:
|
376
|
+
- app/controllers/**/*.rb
|
361
377
|
|
362
378
|
Rails/DelegateAllowBlank:
|
363
379
|
Description: 'Do not use allow_blank as an option to delegate.'
|
@@ -103,7 +103,7 @@ module RuboCop
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def in_where?(node)
|
106
|
-
send_node = node.each_ancestor(:
|
106
|
+
send_node = node.each_ancestor(:call).first
|
107
107
|
return false unless send_node
|
108
108
|
|
109
109
|
return true if WHERE_METHODS.include?(send_node.method_name)
|
@@ -1,7 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RuboCop
|
4
|
-
module Cop
|
4
|
+
module Cop # rubocop:disable Style/Documentation
|
5
|
+
# The EnforceSuperclass module is also defined in `rubocop` (for backwards
|
6
|
+
# compatibility), so here we remove it before (re)defining it, to avoid
|
7
|
+
# warnings about methods in the module being redefined.
|
8
|
+
remove_const(:EnforceSuperclass) if defined?(EnforceSuperclass)
|
9
|
+
|
5
10
|
# Common functionality for enforcing a specific superclass.
|
6
11
|
module EnforceSuperclass
|
7
12
|
def self.included(base)
|
@@ -58,7 +58,7 @@ module RuboCop
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def set_new_arg_name(transformed_argname, corrector)
|
61
|
-
return
|
61
|
+
return unless block_node.block_type?
|
62
62
|
|
63
63
|
corrector.replace(block_node.arguments, "|#{transformed_argname}|")
|
64
64
|
end
|
@@ -84,6 +84,7 @@ module RuboCop
|
|
84
84
|
end
|
85
85
|
|
86
86
|
alias on_numblock on_block
|
87
|
+
alias on_itblock on_block
|
87
88
|
|
88
89
|
def on_send(node)
|
89
90
|
on_bad_map_to_h(node) do |*match|
|
@@ -5,14 +5,14 @@ module RuboCop
|
|
5
5
|
module Rails
|
6
6
|
# Prevents usage of `"*"` on an Arel::Table column reference.
|
7
7
|
#
|
8
|
-
# Using `arel_table["
|
9
|
-
# quoted asterisk (e.g.
|
10
|
-
# database to look for a column named
|
8
|
+
# Using `arel_table["\*"]` causes the outputted string to be a literal
|
9
|
+
# quoted asterisk (e.g. `my_model`.`*`). This causes the
|
10
|
+
# database to look for a column named `\*` (or `"*"`) as opposed
|
11
11
|
# to expanding the column list as one would likely expect.
|
12
12
|
#
|
13
13
|
# @safety
|
14
|
-
# This cop's autocorrection is unsafe because it turns a quoted
|
15
|
-
# an SQL `*`, unquoted.
|
14
|
+
# This cop's autocorrection is unsafe because it turns a quoted `\*` into
|
15
|
+
# an SQL `*`, unquoted. `\*` is a valid column name in certain databases
|
16
16
|
# supported by Rails, and even though it is usually a mistake,
|
17
17
|
# it might denote legitimate access to a column named `*`.
|
18
18
|
#
|
@@ -15,6 +15,9 @@ module RuboCop
|
|
15
15
|
# without using the `delegate` method will be a violation.
|
16
16
|
# When set to `false`, this case is legal.
|
17
17
|
#
|
18
|
+
# It is disabled for controllers in order to keep controller actions
|
19
|
+
# explicitly defined.
|
20
|
+
#
|
18
21
|
# @example
|
19
22
|
# # bad
|
20
23
|
# def bar
|
@@ -45,12 +45,10 @@ module RuboCop
|
|
45
45
|
return if node.parent&.block_type?
|
46
46
|
|
47
47
|
interpolated_string_passed_to_debug(node) do |arguments|
|
48
|
-
message = format(MSG)
|
49
|
-
|
50
48
|
range = replacement_range(node)
|
51
49
|
replacement = replacement_source(node, arguments)
|
52
50
|
|
53
|
-
add_offense(range
|
51
|
+
add_offense(range) do |corrector|
|
54
52
|
corrector.replace(range, replacement)
|
55
53
|
end
|
56
54
|
end
|
@@ -37,6 +37,9 @@ module RuboCop
|
|
37
37
|
(numblock
|
38
38
|
(call _ :to_h) $1
|
39
39
|
(array $_ (lvar :_1)))
|
40
|
+
(itblock
|
41
|
+
(call _ :to_h) $:it
|
42
|
+
(array $_ (lvar :it)))
|
40
43
|
}
|
41
44
|
PATTERN
|
42
45
|
|
@@ -50,6 +53,9 @@ module RuboCop
|
|
50
53
|
(numblock
|
51
54
|
(call _ {:map :collect}) $1
|
52
55
|
(array $_ (lvar :_1)))
|
56
|
+
(itblock
|
57
|
+
(call _ {:map :collect}) $:it
|
58
|
+
(array $_ (lvar :it)))
|
53
59
|
}
|
54
60
|
:to_h)
|
55
61
|
PATTERN
|
@@ -66,6 +72,9 @@ module RuboCop
|
|
66
72
|
(numblock
|
67
73
|
(call _ {:map :collect}) $1
|
68
74
|
(array $_ (lvar :_1)))
|
75
|
+
(itblock
|
76
|
+
(call _ {:map :collect}) $:it
|
77
|
+
(array $_ (lvar :it)))
|
69
78
|
}
|
70
79
|
)
|
71
80
|
PATTERN
|
@@ -40,6 +40,9 @@ module RuboCop
|
|
40
40
|
(numblock
|
41
41
|
(call _ :to_h) $1
|
42
42
|
(array (lvar :_1) $_))
|
43
|
+
(itblock
|
44
|
+
(call _ :to_h) $:it
|
45
|
+
(array (lvar :it) $_))
|
43
46
|
}
|
44
47
|
PATTERN
|
45
48
|
|
@@ -53,6 +56,9 @@ module RuboCop
|
|
53
56
|
(numblock
|
54
57
|
(call _ {:map :collect}) $1
|
55
58
|
(array (lvar :_1) $_))
|
59
|
+
(itblock
|
60
|
+
(call _ {:map :collect}) $:it
|
61
|
+
(array (lvar :it) $_))
|
56
62
|
}
|
57
63
|
:to_h)
|
58
64
|
PATTERN
|
@@ -69,6 +75,9 @@ module RuboCop
|
|
69
75
|
(numblock
|
70
76
|
(call _ {:map :collect}) $1
|
71
77
|
(array (lvar :_1) $_))
|
78
|
+
(itblock
|
79
|
+
(call _ {:map :collect}) $:it
|
80
|
+
(array (lvar :it) $_))
|
72
81
|
}
|
73
82
|
)
|
74
83
|
PATTERN
|
@@ -23,7 +23,6 @@ module RuboCop
|
|
23
23
|
|
24
24
|
MSG = "Do not write to stdout. Use Rails's logger if you want to log."
|
25
25
|
RESTRICT_ON_SEND = %i[ap p pp pretty_print print puts binwrite syswrite write write_nonblock].freeze
|
26
|
-
ALLOWED_TYPES = %i[send csend block numblock].freeze
|
27
26
|
|
28
27
|
def_node_matcher :output?, <<~PATTERN
|
29
28
|
(send nil? {:ap :p :pp :pretty_print :print :puts} ...)
|
@@ -40,7 +39,7 @@ module RuboCop
|
|
40
39
|
PATTERN
|
41
40
|
|
42
41
|
def on_send(node)
|
43
|
-
return if
|
42
|
+
return if node.parent&.call_type? || node.block_node
|
44
43
|
return if !output?(node) && !io_output?(node)
|
45
44
|
|
46
45
|
range = offense_range(node)
|
@@ -59,8 +59,9 @@ module RuboCop
|
|
59
59
|
(any_block (call _ {:map :collect}) $_argument (send lvar :[] $_key))
|
60
60
|
PATTERN
|
61
61
|
|
62
|
+
# rubocop:disable Metrics/AbcSize
|
62
63
|
def on_block(node)
|
63
|
-
return if node.each_ancestor(:
|
64
|
+
return if node.each_ancestor(:any_block).any?
|
64
65
|
|
65
66
|
pluck_candidate?(node) do |argument, key|
|
66
67
|
next if key.regexp_type? || !use_one_block_argument?(argument)
|
@@ -68,20 +69,25 @@ module RuboCop
|
|
68
69
|
match = if node.block_type?
|
69
70
|
block_argument = argument.children.first.source
|
70
71
|
use_block_argument_in_key?(block_argument, key)
|
71
|
-
|
72
|
-
|
72
|
+
elsif node.numblock_type?
|
73
|
+
use_block_argument_in_key?('_1', key)
|
74
|
+
else # itblock
|
75
|
+
use_block_argument_in_key?('it', key)
|
73
76
|
end
|
74
77
|
next unless match
|
75
78
|
|
76
79
|
register_offense(node, key)
|
77
80
|
end
|
78
81
|
end
|
82
|
+
# rubocop:enable Metrics/AbcSize
|
79
83
|
alias on_numblock on_block
|
84
|
+
alias on_itblock on_block
|
80
85
|
|
81
86
|
private
|
82
87
|
|
83
88
|
def use_one_block_argument?(argument)
|
84
|
-
|
89
|
+
# Checks for numbered argument `_1` or `it block parameter.
|
90
|
+
return true if [1, :it].include?(argument)
|
85
91
|
|
86
92
|
argument.respond_to?(:one?) && argument.one?
|
87
93
|
end
|
@@ -85,18 +85,22 @@ module RuboCop
|
|
85
85
|
end
|
86
86
|
|
87
87
|
alias on_numblock on_block
|
88
|
+
alias on_itblock on_block
|
88
89
|
|
89
90
|
private
|
90
91
|
|
91
92
|
def autocorrect(corrector, send_node, node)
|
92
93
|
corrector.remove(send_node.receiver)
|
93
94
|
corrector.remove(send_node.loc.dot)
|
94
|
-
corrector.remove(block_argument_range(send_node))
|
95
|
+
corrector.remove(block_argument_range(send_node)) if node.block_type?
|
95
96
|
end
|
96
97
|
|
98
|
+
# rubocop:disable Metrics/AbcSize
|
97
99
|
def redundant_receiver?(send_nodes, node)
|
98
100
|
proc = if node.numblock_type?
|
99
101
|
->(n) { n.receiver.lvar_type? && n.receiver.source == '_1' }
|
102
|
+
elsif node.itblock_type?
|
103
|
+
->(n) { n.receiver.lvar_type? && n.receiver.source == 'it' }
|
100
104
|
else
|
101
105
|
return false if node.arguments.empty?
|
102
106
|
|
@@ -106,6 +110,7 @@ module RuboCop
|
|
106
110
|
|
107
111
|
send_nodes.all?(&proc)
|
108
112
|
end
|
113
|
+
# rubocop:enable Metrics/AbcSize
|
109
114
|
|
110
115
|
def block_argument_range(node)
|
111
116
|
block_node = node.each_ancestor(:block).first
|
@@ -40,7 +40,7 @@ module RuboCop
|
|
40
40
|
|
41
41
|
def on_send(node)
|
42
42
|
association_with_reflection(node) do |reflection_class_name|
|
43
|
-
return if reflection_class_name.value.send_type? && reflection_class_name.value.receiver
|
43
|
+
return if reflection_class_name.value.send_type? && !reflection_class_name.value.receiver&.const_type?
|
44
44
|
return if reflection_class_name.value.lvar_type? && str_assigned?(reflection_class_name)
|
45
45
|
|
46
46
|
add_offense(reflection_class_name) do |corrector|
|
@@ -76,7 +76,7 @@ module RuboCop
|
|
76
76
|
def autocorrect(corrector, class_config)
|
77
77
|
class_value = class_config.value
|
78
78
|
replacement = const_or_string(class_value)
|
79
|
-
return unless replacement
|
79
|
+
return unless replacement
|
80
80
|
|
81
81
|
corrector.replace(class_value, replacement.source.inspect)
|
82
82
|
end
|
@@ -205,6 +205,7 @@ module RuboCop
|
|
205
205
|
end
|
206
206
|
|
207
207
|
alias on_numblock on_block
|
208
|
+
alias on_itblock on_block
|
208
209
|
|
209
210
|
private
|
210
211
|
|
@@ -218,7 +219,7 @@ module RuboCop
|
|
218
219
|
return unless (last_argument = node.last_argument)
|
219
220
|
|
220
221
|
drop_table_call(node) do
|
221
|
-
unless node.parent.
|
222
|
+
unless node.parent.any_block_type? || last_argument.block_pass_type?
|
222
223
|
add_offense(node, message: format(MSG, action: 'drop_table(without block)'))
|
223
224
|
end
|
224
225
|
end
|
@@ -182,7 +182,7 @@ module RuboCop
|
|
182
182
|
def right_assignment_node(assignment)
|
183
183
|
node = assignment.node.child_nodes.first
|
184
184
|
|
185
|
-
return node unless node&.
|
185
|
+
return node unless node&.any_block_type?
|
186
186
|
|
187
187
|
node.send_node
|
188
188
|
end
|
@@ -305,7 +305,7 @@ module RuboCop
|
|
305
305
|
|
306
306
|
node = assignable_node(node)
|
307
307
|
method, sibling_index = find_method_with_sibling_index(node.parent)
|
308
|
-
return false unless method&.type?(:def, :
|
308
|
+
return false unless method&.type?(:def, :any_block)
|
309
309
|
|
310
310
|
method.children.size == node.sibling_index + sibling_index
|
311
311
|
end
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
|
40
40
|
# @!method comment_present?(node)
|
41
41
|
def_node_matcher :comment_present?, <<~PATTERN
|
42
|
-
(hash <(pair {(sym :comment) (str "comment")} (_
|
42
|
+
(hash <(pair {(sym :comment) (str "comment")} (_ !blank?)) ...>)
|
43
43
|
PATTERN
|
44
44
|
|
45
45
|
# @!method add_column?(node)
|
@@ -99,7 +99,7 @@ module RuboCop
|
|
99
99
|
return false unless transaction_method_name?(node.method_name)
|
100
100
|
return false unless (parent = node.parent)
|
101
101
|
|
102
|
-
parent.
|
102
|
+
parent.any_block_type? && parent.body
|
103
103
|
end
|
104
104
|
|
105
105
|
def statement(statement_node)
|
@@ -113,7 +113,7 @@ module RuboCop
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def nested_block?(statement_node)
|
116
|
-
name = statement_node.ancestors.find(&:
|
116
|
+
name = statement_node.ancestors.find(&:any_block_type?).children.first.method_name
|
117
117
|
!transaction_method_name?(name)
|
118
118
|
end
|
119
119
|
|
@@ -52,7 +52,7 @@ module RuboCop
|
|
52
52
|
MSG = 'Use `distinct` before `pluck`.'
|
53
53
|
RESTRICT_ON_SEND = %i[uniq].freeze
|
54
54
|
|
55
|
-
def_node_matcher :uniq_before_pluck, '[!^
|
55
|
+
def_node_matcher :uniq_before_pluck, '[!^any_block $(send $(send _ :pluck ...) :uniq ...)]'
|
56
56
|
|
57
57
|
def on_send(node)
|
58
58
|
uniq_before_pluck(node) do |uniq_node, pluck_node|
|
data/lib/rubocop-rails.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.31.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
- Yuji Nakayama
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-
|
12
|
+
date: 2025-04-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 1.
|
62
|
+
version: 1.75.0
|
63
63
|
- - "<"
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '2.0'
|
@@ -69,7 +69,7 @@ dependencies:
|
|
69
69
|
requirements:
|
70
70
|
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: 1.
|
72
|
+
version: 1.75.0
|
73
73
|
- - "<"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '2.0'
|
@@ -264,7 +264,7 @@ metadata:
|
|
264
264
|
homepage_uri: https://docs.rubocop.org/rubocop-rails/
|
265
265
|
changelog_uri: https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md
|
266
266
|
source_code_uri: https://github.com/rubocop/rubocop-rails/
|
267
|
-
documentation_uri: https://docs.rubocop.org/rubocop-rails/2.
|
267
|
+
documentation_uri: https://docs.rubocop.org/rubocop-rails/2.31/
|
268
268
|
bug_tracker_uri: https://github.com/rubocop/rubocop-rails/issues
|
269
269
|
rubygems_mfa_required: 'true'
|
270
270
|
default_lint_roller_plugin: RuboCop::Rails::Plugin
|