rubocop-rails 2.12.0 → 2.12.4
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/config/default.yml +9 -2
- data/lib/rubocop/cop/rails/active_record_aliases.rb +2 -2
- data/lib/rubocop/cop/rails/content_tag.rb +13 -6
- data/lib/rubocop/cop/rails/find_each.rb +13 -0
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +5 -3
- data/lib/rubocop/cop/rails/relative_date_constant.rb +1 -1
- data/lib/rubocop/cop/rails/reversible_migration.rb +10 -2
- data/lib/rubocop/cop/rails/unique_validation_without_index.rb +1 -1
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c247cc795386a013c8f1a9dd7a76a08ef8fbd3c729ebe69e2f99bcb28a7baf6
|
4
|
+
data.tar.gz: f85139a9ef4a5f1666672431285e6d34ca9a8c0a367bf6c1e2b8ed2d3d0acf63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd4893d903809e187a9094f84a14209aecfc931e4773df64e1c5a05c94fce22305ca0b0c899881545e697ceae8c6facb3400d0dc41415fed57a3b07244b7fdff
|
7
|
+
data.tar.gz: 91832638f61072047b0cf11b300d7be679a8fc7f708dc47cb5769eb1cd7852c8caf70452d6297cca122af4a53fd0599605d7221a8fc647e96352934fb0828684
|
data/config/default.yml
CHANGED
@@ -9,7 +9,7 @@ AllCops:
|
|
9
9
|
- bin/*
|
10
10
|
- db/schema.rb
|
11
11
|
# What version of Rails is the inspected code using? If a value is specified
|
12
|
-
# for TargetRailsVersion then it is used. Acceptable values are
|
12
|
+
# for TargetRailsVersion then it is used. Acceptable values are specified
|
13
13
|
# as a float (i.e. 5.1); the patch version of Rails should not be included.
|
14
14
|
# If TargetRailsVersion is not set, RuboCop will parse the Gemfile.lock or
|
15
15
|
# gems.locked file to find the version of Rails that has been bound to the
|
@@ -189,6 +189,9 @@ Rails/ContentTag:
|
|
189
189
|
Enabled: true
|
190
190
|
VersionAdded: '2.6'
|
191
191
|
VersionChanged: '2.12'
|
192
|
+
# This `Exclude` config prevents false positives for `tag` calls to `has_one: tag`. No helpers are used in normal models.
|
193
|
+
Exclude:
|
194
|
+
- app/models/**/*.rb
|
192
195
|
|
193
196
|
Rails/CreateTableWithTimestamps:
|
194
197
|
Description: >-
|
@@ -198,6 +201,10 @@ Rails/CreateTableWithTimestamps:
|
|
198
201
|
VersionAdded: '0.52'
|
199
202
|
Include:
|
200
203
|
- db/migrate/*.rb
|
204
|
+
Exclude:
|
205
|
+
# Respect the `active_storage_variant_records` table of `*_create_active_storage_tables.active_storage.rb`
|
206
|
+
# auto-generated by `bin/rails active_storage:install` even if `created_at` is not specified.
|
207
|
+
- db/migrate/*_create_active_storage_tables.active_storage.rb
|
201
208
|
|
202
209
|
Rails/Date:
|
203
210
|
Description: >-
|
@@ -816,7 +823,7 @@ Rails/UniqBeforePluck:
|
|
816
823
|
AutoCorrect: false
|
817
824
|
|
818
825
|
Rails/UniqueValidationWithoutIndex:
|
819
|
-
Description: 'Uniqueness validation should
|
826
|
+
Description: 'Uniqueness validation should have a unique index on the database column.'
|
820
827
|
Enabled: true
|
821
828
|
VersionAdded: '2.5'
|
822
829
|
Include:
|
@@ -8,10 +8,10 @@ module RuboCop
|
|
8
8
|
#
|
9
9
|
# @example
|
10
10
|
# #bad
|
11
|
-
#
|
11
|
+
# book.update_attributes!(author: 'Alice')
|
12
12
|
#
|
13
13
|
# #good
|
14
|
-
#
|
14
|
+
# book.update!(author: 'Alice')
|
15
15
|
class ActiveRecordAliases < Base
|
16
16
|
extend AutoCorrector
|
17
17
|
|
@@ -33,6 +33,9 @@ module RuboCop
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def on_send(node)
|
36
|
+
return unless node.receiver.nil?
|
37
|
+
return if node.arguments.count >= 3
|
38
|
+
|
36
39
|
first_argument = node.first_argument
|
37
40
|
return if !first_argument ||
|
38
41
|
allowed_argument?(first_argument) ||
|
@@ -41,12 +44,7 @@ module RuboCop
|
|
41
44
|
preferred_method = node.first_argument.value.to_s.underscore
|
42
45
|
message = format(MSG, preferred_method: preferred_method, current_argument: first_argument.source)
|
43
46
|
|
44
|
-
|
45
|
-
autocorrect(corrector, node, preferred_method)
|
46
|
-
|
47
|
-
@corrected_nodes ||= Set.new.compare_by_identity
|
48
|
-
@corrected_nodes.add(node)
|
49
|
-
end
|
47
|
+
register_offense(node, message, preferred_method)
|
50
48
|
end
|
51
49
|
|
52
50
|
private
|
@@ -63,6 +61,15 @@ module RuboCop
|
|
63
61
|
allowed_name?(argument)
|
64
62
|
end
|
65
63
|
|
64
|
+
def register_offense(node, message, preferred_method)
|
65
|
+
add_offense(node, message: message) do |corrector|
|
66
|
+
autocorrect(corrector, node, preferred_method)
|
67
|
+
|
68
|
+
@corrected_nodes ||= Set.new.compare_by_identity
|
69
|
+
@corrected_nodes.add(node)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
66
73
|
def autocorrect(corrector, node, preferred_method)
|
67
74
|
range = correction_range(node)
|
68
75
|
|
@@ -43,9 +43,22 @@ module RuboCop
|
|
43
43
|
private
|
44
44
|
|
45
45
|
def ignored?(node)
|
46
|
+
return true if active_model_error_where?(node.receiver)
|
47
|
+
|
46
48
|
method_chain = node.each_node(:send).map(&:method_name)
|
49
|
+
|
47
50
|
(cop_config['IgnoredMethods'].map(&:to_sym) & method_chain).any?
|
48
51
|
end
|
52
|
+
|
53
|
+
def active_model_error_where?(node)
|
54
|
+
node.method?(:where) && active_model_error?(node.receiver)
|
55
|
+
end
|
56
|
+
|
57
|
+
def active_model_error?(node)
|
58
|
+
return false if node.nil?
|
59
|
+
|
60
|
+
node.send_type? && node.method?(:errors)
|
61
|
+
end
|
49
62
|
end
|
50
63
|
end
|
51
64
|
end
|
@@ -45,7 +45,7 @@ module RuboCop
|
|
45
45
|
PATTERN
|
46
46
|
|
47
47
|
def_node_matcher :association_with_options?, <<~PATTERN
|
48
|
-
(send nil? {:has_many :has_one}
|
48
|
+
(send nil? {:has_many :has_one} ... (hash $...))
|
49
49
|
PATTERN
|
50
50
|
|
51
51
|
def_node_matcher :dependent_option?, <<~PATTERN
|
@@ -100,8 +100,8 @@ module RuboCop
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def contain_valid_options_in_with_options_block?(node)
|
103
|
-
if with_options_block(node)
|
104
|
-
return true if valid_options?(
|
103
|
+
if (options = with_options_block(node))
|
104
|
+
return true if valid_options?(options)
|
105
105
|
|
106
106
|
return false unless node.parent
|
107
107
|
|
@@ -114,6 +114,8 @@ module RuboCop
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def valid_options?(options)
|
117
|
+
return false if options.nil?
|
118
|
+
|
117
119
|
options = options.first.children.first.pairs if options.first.kwsplat_type?
|
118
120
|
|
119
121
|
return true unless options
|
@@ -317,16 +317,24 @@ module RuboCop
|
|
317
317
|
return if receiver != node.receiver &&
|
318
318
|
reversible_change_table_call?(node)
|
319
319
|
|
320
|
+
action = if method_name == :remove
|
321
|
+
target_rails_version >= 6.1 ? 't.remove (without type)' : 't.remove'
|
322
|
+
else
|
323
|
+
"change_table(with #{method_name})"
|
324
|
+
end
|
325
|
+
|
320
326
|
add_offense(
|
321
327
|
node,
|
322
|
-
message: format(MSG, action:
|
328
|
+
message: format(MSG, action: action)
|
323
329
|
)
|
324
330
|
end
|
325
331
|
|
326
332
|
def reversible_change_table_call?(node)
|
327
333
|
case node.method_name
|
328
|
-
when :change
|
334
|
+
when :change
|
329
335
|
false
|
336
|
+
when :remove
|
337
|
+
target_rails_version >= 6.1 && all_hash_key?(node.arguments.last, :type)
|
330
338
|
when :change_default, :change_column_default, :change_table_comment,
|
331
339
|
:change_column_comment
|
332
340
|
all_hash_key?(node.arguments.last, :from, :to)
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
class UniqueValidationWithoutIndex < Base
|
28
28
|
include ActiveRecordHelper
|
29
29
|
|
30
|
-
MSG = 'Uniqueness validation should
|
30
|
+
MSG = 'Uniqueness validation should have a unique index on the database column.'
|
31
31
|
RESTRICT_ON_SEND = %i[validates].freeze
|
32
32
|
|
33
33
|
def on_send(node)
|
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.12.
|
4
|
+
version: 2.12.4
|
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: 2021-
|
13
|
+
date: 2021-10-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -205,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
205
|
- !ruby/object:Gem::Version
|
206
206
|
version: '0'
|
207
207
|
requirements: []
|
208
|
-
rubygems_version: 3.2.
|
208
|
+
rubygems_version: 3.2.22
|
209
209
|
signing_key:
|
210
210
|
specification_version: 4
|
211
211
|
summary: Automatic Rails code style checking tool.
|