rubocop-rails 2.22.0 → 2.22.2
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 +1 -1
- data/lib/rubocop/cop/rails/action_filter.rb +1 -1
- data/lib/rubocop/cop/rails/active_record_aliases.rb +2 -2
- data/lib/rubocop/cop/rails/after_commit_override.rb +1 -1
- data/lib/rubocop/cop/rails/bulk_change_table.rb +3 -3
- data/lib/rubocop/cop/rails/dangerous_column_names.rb +1 -1
- data/lib/rubocop/cop/rails/duplicate_association.rb +5 -4
- data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +2 -2
- data/lib/rubocop/cop/rails/file_path.rb +5 -5
- data/lib/rubocop/cop/rails/inverse_of.rb +1 -1
- data/lib/rubocop/cop/rails/rake_environment.rb +2 -2
- data/lib/rubocop/cop/rails/redundant_active_record_all_method.rb +43 -30
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -1
- data/lib/rubocop/cop/rails/reversible_migration.rb +2 -2
- data/lib/rubocop/cop/rails/save_bang.rb +4 -4
- data/lib/rubocop/cop/rails/unique_validation_without_index.rb +1 -1
- data/lib/rubocop/cop/rails/unknown_env.rb +3 -3
- data/lib/rubocop/cop/rails/validation.rb +1 -1
- data/lib/rubocop/rails/schema_loader/schema.rb +2 -2
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54ac592e4d6ccfd065a9f61d33b9305f0a54cc879af4963b7a0a5f13e34ef5f7
|
4
|
+
data.tar.gz: e7d9a2dc53b76a3b8308b4cb1c2023f1a18d133efd7e14ad0efd43733cb5ffe1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5b230f2623f63afcdba2fd1fd5dc415538e47ab283bc78c40715c3e6d10c8b8af92bd3597c87aa7105aded11dde0ec66e79f857675e57ebff7a3455e59a102e
|
7
|
+
data.tar.gz: 27092e6dc744ce084d4b1eb8eb85c339bc389de861ab6f82cb2956a550921500d4eb012dc74ff702315c6a39dde7b71b7a43ebec70bd8834ba9314365c45b8ea
|
data/README.md
CHANGED
@@ -82,7 +82,7 @@ module YourCoolApp
|
|
82
82
|
end
|
83
83
|
```
|
84
84
|
|
85
|
-
It uses `rubocop -A` to apply `Style/FrozenStringLiteralComment` and other unsafe
|
85
|
+
It uses `rubocop -A` to apply `Style/FrozenStringLiteralComment` and other unsafe autocorrection cops.
|
86
86
|
`rubocop -A` is unsafe autocorrection, but code generated by default is simple and less likely to
|
87
87
|
be incompatible with `rubocop -A`. If you have problems you can replace it with `rubocop -a` instead.
|
88
88
|
|
@@ -9,7 +9,7 @@ module RuboCop
|
|
9
9
|
# something_filter methods or the newer something_action methods.
|
10
10
|
#
|
11
11
|
# IMPORTANT: This cop is deprecated. Because the `*_filter` methods were removed in Rails 4.2,
|
12
|
-
# and that
|
12
|
+
# and that Rails version is no longer supported by RuboCop Rails. This cop will be removed in RuboCop Rails 3.0.
|
13
13
|
#
|
14
14
|
# @example EnforcedStyle: action (default)
|
15
15
|
# # bad
|
@@ -11,10 +11,10 @@ module RuboCop
|
|
11
11
|
# `update` but the method name remained same in the method definition.
|
12
12
|
#
|
13
13
|
# @example
|
14
|
-
# #bad
|
14
|
+
# # bad
|
15
15
|
# book.update_attributes!(author: 'Alice')
|
16
16
|
#
|
17
|
-
# #good
|
17
|
+
# # good
|
18
18
|
# book.update!(author: 'Alice')
|
19
19
|
class ActiveRecordAliases < Base
|
20
20
|
extend AutoCorrector
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
seen_callback_names = {}
|
49
49
|
|
50
50
|
each_after_commit_callback(class_node) do |node|
|
51
|
-
callback_name = node.
|
51
|
+
callback_name = node.first_argument.value
|
52
52
|
if seen_callback_names.key?(callback_name)
|
53
53
|
add_offense(node, message: format(MSG, name: callback_name))
|
54
54
|
else
|
@@ -212,7 +212,7 @@ module RuboCop
|
|
212
212
|
# @param node [RuboCop::AST::SendNode]
|
213
213
|
def add_offense_for_alter_methods(node)
|
214
214
|
# arguments: [{(sym :table)(str "table")} ...]
|
215
|
-
table_node = node.
|
215
|
+
table_node = node.first_argument
|
216
216
|
return unless table_node.is_a? RuboCop::AST::BasicLiteralNode
|
217
217
|
|
218
218
|
message = format(MSG_FOR_ALTER_METHODS, table: table_node.value)
|
@@ -234,10 +234,10 @@ module RuboCop
|
|
234
234
|
# @param new_node [RuboCop::AST::SendNode]
|
235
235
|
def process(new_node)
|
236
236
|
# arguments: [{(sym :table)(str "table")} ...]
|
237
|
-
table_node = new_node.
|
237
|
+
table_node = new_node.first_argument
|
238
238
|
if table_node.is_a? RuboCop::AST::BasicLiteralNode
|
239
239
|
flush unless @nodes.all? do |node|
|
240
|
-
node.
|
240
|
+
node.first_argument.value.to_s == table_node.value.to_s
|
241
241
|
end
|
242
242
|
@nodes << new_node
|
243
243
|
else
|
@@ -21,12 +21,12 @@ module RuboCop
|
|
21
21
|
# has_one :foo
|
22
22
|
#
|
23
23
|
# # bad
|
24
|
-
#
|
25
|
-
#
|
24
|
+
# has_many :foo, class_name: 'Foo'
|
25
|
+
# has_many :bar, class_name: 'Foo'
|
26
26
|
# has_one :baz
|
27
27
|
#
|
28
28
|
# # good
|
29
|
-
#
|
29
|
+
# has_many :bar, class_name: 'Foo'
|
30
30
|
# has_one :foo
|
31
31
|
#
|
32
32
|
class DuplicateAssociation < Base
|
@@ -87,7 +87,8 @@ module RuboCop
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def duplicated_class_name_nodes(association_nodes)
|
90
|
-
|
90
|
+
filtered_nodes = association_nodes.reject { |node| node.method?(:belongs_to) }
|
91
|
+
grouped_associations = filtered_nodes.group_by do |node|
|
91
92
|
arguments = association(node).last
|
92
93
|
next unless arguments.count == 1
|
93
94
|
|
@@ -14,10 +14,10 @@ module RuboCop
|
|
14
14
|
# when no output would be produced anyway.
|
15
15
|
#
|
16
16
|
# @example
|
17
|
-
# #bad
|
17
|
+
# # bad
|
18
18
|
# Rails.logger.debug "The time is #{Time.zone.now}."
|
19
19
|
#
|
20
|
-
# #good
|
20
|
+
# # good
|
21
21
|
# Rails.logger.debug { "The time is #{Time.zone.now}." }
|
22
22
|
#
|
23
23
|
class EagerEvaluationLogMessage < Base
|
@@ -163,9 +163,9 @@ module RuboCop
|
|
163
163
|
|
164
164
|
def autocorrect_extension_after_rails_root_join_in_dstr(corrector, node, rails_root_index, extension_node)
|
165
165
|
rails_root_node = node.children[rails_root_index].children.first
|
166
|
-
return unless rails_root_node.
|
166
|
+
return unless rails_root_node.last_argument.str_type?
|
167
167
|
|
168
|
-
corrector.insert_before(rails_root_node.
|
168
|
+
corrector.insert_before(rails_root_node.last_argument.location.end, extension_node.source)
|
169
169
|
corrector.remove(extension_node)
|
170
170
|
end
|
171
171
|
|
@@ -174,7 +174,7 @@ module RuboCop
|
|
174
174
|
corrector.remove(
|
175
175
|
range_with_surrounding_space(
|
176
176
|
range_with_surrounding_comma(
|
177
|
-
node.
|
177
|
+
node.first_argument.source_range,
|
178
178
|
:right
|
179
179
|
),
|
180
180
|
side: :right
|
@@ -187,7 +187,7 @@ module RuboCop
|
|
187
187
|
end
|
188
188
|
|
189
189
|
def autocorrect_rails_root_join_with_string_arguments(corrector, node)
|
190
|
-
corrector.replace(node.
|
190
|
+
corrector.replace(node.first_argument, %("#{node.arguments.map(&:value).join('/')}"))
|
191
191
|
node.arguments[1..].each do |argument|
|
192
192
|
corrector.remove(
|
193
193
|
range_with_surrounding_comma(
|
@@ -221,7 +221,7 @@ module RuboCop
|
|
221
221
|
end
|
222
222
|
|
223
223
|
def append_argument(corrector, node, argument_source)
|
224
|
-
corrector.insert_after(node.
|
224
|
+
corrector.insert_after(node.last_argument, %(, "#{argument_source}"))
|
225
225
|
end
|
226
226
|
|
227
227
|
def replace_with_rails_root_join(corrector, node, argument_source)
|
@@ -222,7 +222,7 @@ module RuboCop
|
|
222
222
|
|
223
223
|
def with_options_arguments(recv, node)
|
224
224
|
blocks = node.each_ancestor(:block).select do |block|
|
225
|
-
block.send_node.command?(:with_options) && same_context_in_with_options?(block.
|
225
|
+
block.send_node.command?(:with_options) && same_context_in_with_options?(block.first_argument, recv)
|
226
226
|
end
|
227
227
|
blocks.flat_map { |n| n.send_node.arguments }
|
228
228
|
end
|
@@ -72,7 +72,7 @@ module RuboCop
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def task_name(node)
|
75
|
-
first_arg = node.
|
75
|
+
first_arg = node.first_argument
|
76
76
|
case first_arg&.type
|
77
77
|
when :sym, :str
|
78
78
|
first_arg.value.to_sym
|
@@ -97,7 +97,7 @@ module RuboCop
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def with_dependencies?(node)
|
100
|
-
first_arg = node.
|
100
|
+
first_arg = node.first_argument
|
101
101
|
return false unless first_arg
|
102
102
|
|
103
103
|
if first_arg.hash_type?
|
@@ -3,8 +3,44 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
+
# TODO: In the future, please support only RuboCop 1.52+ and use `RuboCop::Cop::AllowedReceivers`:
|
7
|
+
# https://github.com/rubocop/rubocop/blob/v1.52.0/lib/rubocop/cop/mixin/allowed_receivers.rb
|
8
|
+
# At that time, this duplicated module implementation can be removed.
|
9
|
+
module AllowedReceivers
|
10
|
+
def allowed_receiver?(receiver)
|
11
|
+
receiver_name = receiver_name(receiver)
|
12
|
+
|
13
|
+
allowed_receivers.include?(receiver_name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def receiver_name(receiver)
|
17
|
+
return receiver_name(receiver.receiver) if receiver.receiver && !receiver.receiver.const_type?
|
18
|
+
|
19
|
+
if receiver.send_type?
|
20
|
+
if receiver.receiver
|
21
|
+
"#{receiver_name(receiver.receiver)}.#{receiver.method_name}"
|
22
|
+
else
|
23
|
+
receiver.method_name.to_s
|
24
|
+
end
|
25
|
+
else
|
26
|
+
receiver.source
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def allowed_receivers
|
31
|
+
cop_config.fetch('AllowedReceivers', [])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
6
35
|
# Detect redundant `all` used as a receiver for Active Record query methods.
|
7
36
|
#
|
37
|
+
# NOTE: For the methods `delete_all` and `destroy_all`,
|
38
|
+
# this cop will only check cases where the receiver is a model.
|
39
|
+
# It will ignore cases where the receiver is an association (e.g., `user.articles.all.delete_all`).
|
40
|
+
# This is because omitting `all` from an association changes the methods
|
41
|
+
# from `ActiveRecord::Relation` to `ActiveRecord::Associations::CollectionProxy`,
|
42
|
+
# which can affect their behavior.
|
43
|
+
#
|
8
44
|
# @safety
|
9
45
|
# This cop is unsafe for autocorrection if the receiver for `all` is not an Active Record object.
|
10
46
|
#
|
@@ -144,13 +180,15 @@ module RuboCop
|
|
144
180
|
].to_set.freeze
|
145
181
|
|
146
182
|
POSSIBLE_ENUMERABLE_BLOCK_METHODS = %i[any? count find none? one? select sum].freeze
|
183
|
+
SENSITIVE_METHODS_ON_ASSOCIATION = %i[delete_all destroy_all].freeze
|
147
184
|
|
148
185
|
def_node_matcher :followed_by_query_method?, <<~PATTERN
|
149
186
|
(send (send _ :all) QUERYING_METHODS ...)
|
150
187
|
PATTERN
|
151
188
|
|
152
189
|
def on_send(node)
|
153
|
-
return
|
190
|
+
return unless followed_by_query_method?(node.parent)
|
191
|
+
return if possible_enumerable_block_method?(node) || sensitive_association_method?(node)
|
154
192
|
return if node.receiver ? allowed_receiver?(node.receiver) : !inherit_active_record_base?(node)
|
155
193
|
|
156
194
|
range_of_all_method = offense_range(node)
|
@@ -169,37 +207,12 @@ module RuboCop
|
|
169
207
|
parent.parent&.block_type? || parent.parent&.numblock_type? || parent.first_argument&.block_pass_type?
|
170
208
|
end
|
171
209
|
|
172
|
-
def
|
173
|
-
|
210
|
+
def sensitive_association_method?(node)
|
211
|
+
!node.receiver&.const_type? && SENSITIVE_METHODS_ON_ASSOCIATION.include?(node.parent.method_name)
|
174
212
|
end
|
175
213
|
|
176
|
-
|
177
|
-
|
178
|
-
# At that time, this duplicated module implementation can be removed.
|
179
|
-
module AllowedReceivers
|
180
|
-
def allowed_receiver?(receiver)
|
181
|
-
receiver_name = receiver_name(receiver)
|
182
|
-
|
183
|
-
allowed_receivers.include?(receiver_name)
|
184
|
-
end
|
185
|
-
|
186
|
-
def receiver_name(receiver)
|
187
|
-
return receiver_name(receiver.receiver) if receiver.receiver && !receiver.receiver.const_type?
|
188
|
-
|
189
|
-
if receiver.send_type?
|
190
|
-
if receiver.receiver
|
191
|
-
"#{receiver_name(receiver.receiver)}.#{receiver.method_name}"
|
192
|
-
else
|
193
|
-
receiver.method_name.to_s
|
194
|
-
end
|
195
|
-
else
|
196
|
-
receiver.source
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
def allowed_receivers
|
201
|
-
cop_config.fetch('AllowedReceivers', [])
|
202
|
-
end
|
214
|
+
def offense_range(node)
|
215
|
+
range_between(node.loc.selector.begin_pos, node.source_range.end_pos)
|
203
216
|
end
|
204
217
|
end
|
205
218
|
end
|
@@ -290,10 +290,10 @@ module RuboCop
|
|
290
290
|
when :change
|
291
291
|
false
|
292
292
|
when :remove
|
293
|
-
target_rails_version >= 6.1 && all_hash_key?(node.
|
293
|
+
target_rails_version >= 6.1 && all_hash_key?(node.last_argument, :type)
|
294
294
|
when :change_default, :change_column_default, :change_table_comment,
|
295
295
|
:change_column_comment
|
296
|
-
all_hash_key?(node.
|
296
|
+
all_hash_key?(node.last_argument, :from, :to)
|
297
297
|
else
|
298
298
|
true
|
299
299
|
end
|
@@ -336,10 +336,10 @@ module RuboCop
|
|
336
336
|
|
337
337
|
# Check argument signature as no arguments or one hash
|
338
338
|
def expected_signature?(node)
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
339
|
+
return true unless node.arguments?
|
340
|
+
return false if !node.arguments.one? || node.method?(:destroy)
|
341
|
+
|
342
|
+
node.first_argument.hash_type? || !node.first_argument.literal?
|
343
343
|
end
|
344
344
|
end
|
345
345
|
end
|
@@ -87,9 +87,9 @@ module RuboCop
|
|
87
87
|
|
88
88
|
def environments
|
89
89
|
@environments ||= begin
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
environments = cop_config['Environments'] || []
|
91
|
+
environments << 'local' if target_rails_version >= 7.1
|
92
|
+
environments
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
@@ -60,7 +60,7 @@ module RuboCop
|
|
60
60
|
range = node.loc.selector
|
61
61
|
|
62
62
|
add_offense(range, message: message(node)) do |corrector|
|
63
|
-
last_argument = node.
|
63
|
+
last_argument = node.last_argument
|
64
64
|
return if !last_argument.literal? && !last_argument.splat_type? && !frozen_array_argument?(last_argument)
|
65
65
|
|
66
66
|
corrector.replace(range, 'validates')
|
@@ -127,7 +127,7 @@ module RuboCop
|
|
127
127
|
private
|
128
128
|
|
129
129
|
def analyze_keywords!(node)
|
130
|
-
pairs = node.
|
130
|
+
pairs = node.last_argument
|
131
131
|
return unless pairs.hash_type?
|
132
132
|
|
133
133
|
pairs.each_pair do |k, v|
|
@@ -158,7 +158,7 @@ module RuboCop
|
|
158
158
|
end
|
159
159
|
|
160
160
|
def analyze_keywords!(node)
|
161
|
-
pairs = node.
|
161
|
+
pairs = node.last_argument
|
162
162
|
return unless pairs.hash_type?
|
163
163
|
|
164
164
|
pairs.each_pair do |k, v|
|
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.22.
|
4
|
+
version: 2.22.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-
|
13
|
+
date: 2023-11-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -60,6 +60,26 @@ dependencies:
|
|
60
60
|
- - "<"
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '2.0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rubocop-ast
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.30.0
|
70
|
+
- - "<"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '2.0'
|
73
|
+
type: :runtime
|
74
|
+
prerelease: false
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.30.0
|
80
|
+
- - "<"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
63
83
|
description: |
|
64
84
|
Automatic Rails code style checking tool.
|
65
85
|
A RuboCop extension focused on enforcing Rails best practices and coding conventions.
|