rubocop-rails 2.12.2 → 2.12.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +9 -2
- data/lib/rubocop/cop/rails/content_tag.rb +13 -6
- data/lib/rubocop/cop/rails/find_each.rb +11 -0
- 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: f6f12cb9a10c2b1cf1ffe2a4713ccfdd4d88885378bde05d3988d829bf73218d
|
4
|
+
data.tar.gz: e60c60867234af9be31f066397aa23ddfedf8b167fa86269761717a81ad89f75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b002f9f18331d8f4fe34f69dd0226e2ae607e632360e370dec3b5f2df39e4c1d10426ca5b9a574f83d579a841e705cb8b2332b6a2956dc76f6b130d56f824b30
|
7
|
+
data.tar.gz: 5e84d9ed3b6a8991fa8b905d38e30a6c26828d8b9a73b0db552485872b0a31bff17aab3b6109170a98950b132eb1929be16552b27143f56567daf4e2ef9e7d16
|
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:
|
@@ -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,20 @@ 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
|
+
node.send_type? && node.method?(:errors)
|
59
|
+
end
|
49
60
|
end
|
50
61
|
end
|
51
62
|
end
|
@@ -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.3
|
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-06 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.
|