rubocop-rails 2.11.3 → 2.12.3
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/bin/console +11 -0
- data/config/default.yml +22 -3
- data/lib/rubocop/cop/rails/content_tag.rb +39 -29
- data/lib/rubocop/cop/rails/delegate.rb +1 -1
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +1 -1
- data/lib/rubocop/cop/rails/find_each.rb +11 -0
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +7 -3
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +8 -1
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +23 -2
- data/lib/rubocop/cop/rails/link_to_blank.rb +2 -2
- data/lib/rubocop/cop/rails/output.rb +17 -3
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +2 -2
- data/lib/rubocop/cop/rails/redundant_travel_back.rb +57 -0
- data/lib/rubocop/cop/rails/relative_date_constant.rb +1 -1
- data/lib/rubocop/cop/rails/reversible_migration.rb +12 -4
- data/lib/rubocop/cop/rails/scope_args.rb +5 -1
- data/lib/rubocop/cop/rails/unique_validation_without_index.rb +1 -1
- data/lib/rubocop/cop/rails_cops.rb +1 -0
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +6 -4
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/bin/console
ADDED
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
|
@@ -181,12 +181,17 @@ Rails/BulkChangeTable:
|
|
181
181
|
- db/migrate/*.rb
|
182
182
|
|
183
183
|
Rails/ContentTag:
|
184
|
-
Description: 'Use `tag` instead of `
|
184
|
+
Description: 'Use `tag.something` instead of `tag(:something)`.'
|
185
185
|
Reference:
|
186
|
+
- 'https://github.com/rubocop/rubocop-rails/issues/260'
|
186
187
|
- 'https://github.com/rails/rails/issues/25195'
|
187
188
|
- 'https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag'
|
188
189
|
Enabled: true
|
189
190
|
VersionAdded: '2.6'
|
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
|
190
195
|
|
191
196
|
Rails/CreateTableWithTimestamps:
|
192
197
|
Description: >-
|
@@ -196,6 +201,10 @@ Rails/CreateTableWithTimestamps:
|
|
196
201
|
VersionAdded: '0.52'
|
197
202
|
Include:
|
198
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
|
199
208
|
|
200
209
|
Rails/Date:
|
201
210
|
Description: >-
|
@@ -499,6 +508,7 @@ Rails/OrderById:
|
|
499
508
|
Rails/Output:
|
500
509
|
Description: 'Checks for calls to puts, print, etc.'
|
501
510
|
Enabled: true
|
511
|
+
SafeAutoCorrect: false
|
502
512
|
VersionAdded: '0.15'
|
503
513
|
VersionChanged: '0.19'
|
504
514
|
Include:
|
@@ -607,6 +617,14 @@ Rails/RedundantReceiverInWithOptions:
|
|
607
617
|
Enabled: true
|
608
618
|
VersionAdded: '0.52'
|
609
619
|
|
620
|
+
Rails/RedundantTravelBack:
|
621
|
+
Description: This cop checks for redundant `travel_back` calls.
|
622
|
+
Enabled: pending
|
623
|
+
VersionAdded: '2.12'
|
624
|
+
Include:
|
625
|
+
- spec/**/*.rb
|
626
|
+
- test/**/*.rb
|
627
|
+
|
610
628
|
Rails/ReflectionClassName:
|
611
629
|
Description: 'Use a string for `class_name` option value in the definition of a reflection.'
|
612
630
|
Enabled: true
|
@@ -713,6 +731,7 @@ Rails/ScopeArgs:
|
|
713
731
|
Description: 'Checks the arguments of ActiveRecord scopes.'
|
714
732
|
Enabled: true
|
715
733
|
VersionAdded: '0.19'
|
734
|
+
VersionChanged: '2.12'
|
716
735
|
Include:
|
717
736
|
- app/models/**/*.rb
|
718
737
|
|
@@ -804,7 +823,7 @@ Rails/UniqBeforePluck:
|
|
804
823
|
AutoCorrect: false
|
805
824
|
|
806
825
|
Rails/UniqueValidationWithoutIndex:
|
807
|
-
Description: 'Uniqueness validation should
|
826
|
+
Description: 'Uniqueness validation should have a unique index on the database column.'
|
808
827
|
Enabled: true
|
809
828
|
VersionAdded: '2.5'
|
810
829
|
Include:
|
@@ -3,21 +3,21 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
# This cop checks
|
7
|
-
# because `content_tag` is legacy syntax.
|
6
|
+
# This cop checks legacy syntax usage of `tag`
|
8
7
|
#
|
9
|
-
# NOTE: Allow `
|
10
|
-
#
|
8
|
+
# NOTE: Allow `tag` when the first argument is a variable because
|
9
|
+
# `tag(name)` is simpler rather than `tag.public_send(name)`.
|
10
|
+
# And this cop will be renamed to something like `LegacyTag` in the future. (e.g. RuboCop Rails 2.0)
|
11
11
|
#
|
12
12
|
# @example
|
13
13
|
# # bad
|
14
|
-
#
|
15
|
-
#
|
14
|
+
# tag(:p)
|
15
|
+
# tag(:br, class: 'classname')
|
16
16
|
#
|
17
17
|
# # good
|
18
|
-
# tag.p
|
19
|
-
# tag.br
|
20
|
-
#
|
18
|
+
# tag.p
|
19
|
+
# tag.br(class: 'classname')
|
20
|
+
# tag(name, class: 'classname')
|
21
21
|
class ContentTag < Base
|
22
22
|
include RangeHelp
|
23
23
|
extend AutoCorrector
|
@@ -25,25 +25,26 @@ module RuboCop
|
|
25
25
|
|
26
26
|
minimum_target_rails_version 5.1
|
27
27
|
|
28
|
-
MSG = 'Use `tag` instead of `
|
29
|
-
RESTRICT_ON_SEND = %i[
|
28
|
+
MSG = 'Use `tag.%<preferred_method>s` instead of `tag(%<current_argument>s)`.'
|
29
|
+
RESTRICT_ON_SEND = %i[tag].freeze
|
30
30
|
|
31
31
|
def on_new_investigation
|
32
32
|
@corrected_nodes = nil
|
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) ||
|
39
42
|
corrected_ancestor?(node)
|
40
43
|
|
41
|
-
|
42
|
-
|
44
|
+
preferred_method = node.first_argument.value.to_s.underscore
|
45
|
+
message = format(MSG, preferred_method: preferred_method, current_argument: first_argument.source)
|
43
46
|
|
44
|
-
|
45
|
-
@corrected_nodes.add(node)
|
46
|
-
end
|
47
|
+
register_offense(node, message, preferred_method)
|
47
48
|
end
|
48
49
|
|
49
50
|
private
|
@@ -53,26 +54,35 @@ module RuboCop
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def allowed_argument?(argument)
|
56
|
-
argument.variable? ||
|
57
|
+
argument.variable? ||
|
58
|
+
argument.send_type? ||
|
59
|
+
argument.const_type? ||
|
60
|
+
argument.splat_type? ||
|
61
|
+
allowed_name?(argument)
|
57
62
|
end
|
58
63
|
|
59
|
-
def
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
rest_args = node.arguments.drop(1)
|
64
|
-
replacement = "tag.#{node.first_argument.value.to_s.underscore}(#{rest_args.map(&:source).join(', ')})"
|
64
|
+
def register_offense(node, message, preferred_method)
|
65
|
+
add_offense(node, message: message) do |corrector|
|
66
|
+
autocorrect(corrector, node, preferred_method)
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
corrector.replace(node.loc.selector, 'tag')
|
68
|
+
@corrected_nodes ||= Set.new.compare_by_identity
|
69
|
+
@corrected_nodes.add(node)
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
72
|
-
def
|
73
|
-
|
73
|
+
def autocorrect(corrector, node, preferred_method)
|
74
|
+
range = correction_range(node)
|
75
|
+
|
76
|
+
rest_args = node.arguments.drop(1)
|
77
|
+
replacement = "tag.#{preferred_method}(#{rest_args.map(&:source).join(', ')})"
|
78
|
+
|
79
|
+
corrector.replace(range, replacement)
|
80
|
+
end
|
81
|
+
|
82
|
+
def allowed_name?(argument)
|
83
|
+
return false unless argument.str_type? || argument.sym_type?
|
74
84
|
|
75
|
-
|
85
|
+
!/^[a-zA-Z\-][a-zA-Z\-0-9]*$/.match?(argument.value)
|
76
86
|
end
|
77
87
|
|
78
88
|
def correction_range(node)
|
@@ -100,7 +100,7 @@ module RuboCop
|
|
100
100
|
|
101
101
|
def method_name_matches?(method_name, body)
|
102
102
|
method_name == body.method_name ||
|
103
|
-
include_prefix_case? && method_name == prefixed_method_name(body)
|
103
|
+
(include_prefix_case? && method_name == prefixed_method_name(body))
|
104
104
|
end
|
105
105
|
|
106
106
|
def include_prefix_case?
|
@@ -40,7 +40,7 @@ module RuboCop
|
|
40
40
|
IGNORED_ARGUMENT_TYPES = %i[hash splat].freeze
|
41
41
|
|
42
42
|
def on_send(node)
|
43
|
-
return if node.receiver.nil? && !inherit_active_record_base?(node) || allowed_invocation?(node)
|
43
|
+
return if (node.receiver.nil? && !inherit_active_record_base?(node)) || allowed_invocation?(node)
|
44
44
|
|
45
45
|
method_name = node.method_name
|
46
46
|
static_name = static_method_name(method_name)
|
@@ -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
|
@@ -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,10 @@ module RuboCop
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def valid_options?(options)
|
117
|
+
return false if options.nil?
|
118
|
+
|
119
|
+
options = options.first.children.first.pairs if options.first.kwsplat_type?
|
120
|
+
|
117
121
|
return true unless options
|
118
122
|
return true if options.any? do |o|
|
119
123
|
dependent_option?(o) || present_option?(o)
|
@@ -27,6 +27,7 @@ module RuboCop
|
|
27
27
|
KEYWORD_ARGS = %i[
|
28
28
|
method params session body flash xhr as headers env to
|
29
29
|
].freeze
|
30
|
+
ROUTING_METHODS = %i[draw routes].freeze
|
30
31
|
RESTRICT_ON_SEND = %i[get post put patch delete head].freeze
|
31
32
|
|
32
33
|
minimum_target_rails_version 5.0
|
@@ -40,6 +41,8 @@ module RuboCop
|
|
40
41
|
PATTERN
|
41
42
|
|
42
43
|
def on_send(node)
|
44
|
+
return if in_routing_block?(node)
|
45
|
+
|
43
46
|
http_request?(node) do |data|
|
44
47
|
return unless needs_conversion?(data)
|
45
48
|
|
@@ -63,13 +66,17 @@ module RuboCop
|
|
63
66
|
|
64
67
|
private
|
65
68
|
|
69
|
+
def in_routing_block?(node)
|
70
|
+
!!node.each_ancestor(:block).detect { |block| ROUTING_METHODS.include?(block.send_node.method_name) }
|
71
|
+
end
|
72
|
+
|
66
73
|
def needs_conversion?(data)
|
67
74
|
return true unless data.hash_type?
|
68
75
|
return false if kwsplat_hash?(data)
|
69
76
|
|
70
77
|
data.each_pair.none? do |pair|
|
71
78
|
special_keyword_arg?(pair.key) ||
|
72
|
-
format_arg?(pair.key) && data.pairs.one?
|
79
|
+
(format_arg?(pair.key) && data.pairs.one?)
|
73
80
|
end
|
74
81
|
end
|
75
82
|
|
@@ -124,9 +124,10 @@ module RuboCop
|
|
124
124
|
block = parent.each_child_node(:begin).first
|
125
125
|
return unless block
|
126
126
|
|
127
|
-
|
127
|
+
defined_action_methods = defined_action_methods(block)
|
128
|
+
|
128
129
|
methods = array_values(methods_node).reject do |method|
|
129
|
-
|
130
|
+
defined_action_methods.include?(method)
|
130
131
|
end
|
131
132
|
|
132
133
|
message = message(methods, parent)
|
@@ -135,6 +136,26 @@ module RuboCop
|
|
135
136
|
|
136
137
|
private
|
137
138
|
|
139
|
+
def defined_action_methods(block)
|
140
|
+
defined_methods = block.each_child_node(:def).map(&:method_name)
|
141
|
+
|
142
|
+
defined_methods + aliased_action_methods(block, defined_methods)
|
143
|
+
end
|
144
|
+
|
145
|
+
def aliased_action_methods(node, defined_methods)
|
146
|
+
alias_methods = node.each_child_node(:send).select { |send_node| send_node.method?(:alias_method) }
|
147
|
+
|
148
|
+
hash_of_alias_methods = alias_methods.each_with_object({}) do |alias_method, result|
|
149
|
+
result[alias_method.last_argument.value] = alias_method.first_argument.value
|
150
|
+
end
|
151
|
+
|
152
|
+
defined_methods.each_with_object([]) do |defined_method, aliased_method|
|
153
|
+
if (new_method_name = hash_of_alias_methods[defined_method])
|
154
|
+
aliased_method << new_method_name
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
138
159
|
# @param node [RuboCop::AST::Node]
|
139
160
|
# @return [Array<Symbol>]
|
140
161
|
def array_values(node) # rubocop:disable Metrics/MethodLength
|
@@ -75,8 +75,8 @@ module RuboCop
|
|
75
75
|
corrector.replace(str_range, "#{existing_rel} noopener")
|
76
76
|
end
|
77
77
|
|
78
|
-
def add_rel(send_node,
|
79
|
-
opening_quote =
|
78
|
+
def add_rel(send_node, offense_node, corrector)
|
79
|
+
opening_quote = offense_node.children.last.source[0]
|
80
80
|
closing_quote = opening_quote == ':' ? '' : opening_quote
|
81
81
|
new_rel_exp = ", rel: #{opening_quote}noopener#{closing_quote}"
|
82
82
|
range = if (last_argument = send_node.last_argument).hash_type?
|
@@ -14,6 +14,9 @@ module RuboCop
|
|
14
14
|
# # good
|
15
15
|
# Rails.logger.debug 'A debug message'
|
16
16
|
class Output < Base
|
17
|
+
include RangeHelp
|
18
|
+
extend AutoCorrector
|
19
|
+
|
17
20
|
MSG = 'Do not write to stdout. ' \
|
18
21
|
"Use Rails's logger if you want to log."
|
19
22
|
RESTRICT_ON_SEND = %i[
|
@@ -35,10 +38,13 @@ module RuboCop
|
|
35
38
|
PATTERN
|
36
39
|
|
37
40
|
def on_send(node)
|
38
|
-
return unless (output?(node) || io_output?(node)) &&
|
39
|
-
|
41
|
+
return unless (output?(node) || io_output?(node)) && node.arguments?
|
42
|
+
|
43
|
+
range = offense_range(node)
|
40
44
|
|
41
|
-
add_offense(
|
45
|
+
add_offense(range) do |corrector|
|
46
|
+
corrector.replace(range, 'Rails.logger.debug')
|
47
|
+
end
|
42
48
|
end
|
43
49
|
|
44
50
|
private
|
@@ -46,6 +52,14 @@ module RuboCop
|
|
46
52
|
def match_gvar?(sym)
|
47
53
|
%i[$stdout $stderr].include?(sym)
|
48
54
|
end
|
55
|
+
|
56
|
+
def offense_range(node)
|
57
|
+
if node.receiver
|
58
|
+
range_between(node.loc.expression.begin_pos, node.loc.selector.end_pos)
|
59
|
+
else
|
60
|
+
node.loc.selector
|
61
|
+
end
|
62
|
+
end
|
49
63
|
end
|
50
64
|
end
|
51
65
|
end
|
@@ -61,8 +61,8 @@ module RuboCop
|
|
61
61
|
def offense?(node)
|
62
62
|
number, = *node.receiver
|
63
63
|
|
64
|
-
singular_receiver?(number) && plural_method?(node.method_name) ||
|
65
|
-
plural_receiver?(number) && singular_method?(node.method_name)
|
64
|
+
(singular_receiver?(number) && plural_method?(node.method_name)) ||
|
65
|
+
(plural_receiver?(number) && singular_method?(node.method_name))
|
66
66
|
end
|
67
67
|
|
68
68
|
def plural_method?(method_name)
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rails
|
6
|
+
# This cop checks for redundant `travel_back` calls.
|
7
|
+
# Since Rails 5.2, `travel_back` is automatically called at the end of the test.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# def teardown
|
13
|
+
# do_something
|
14
|
+
# travel_back
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# def teardown
|
19
|
+
# do_something
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# # bad
|
23
|
+
# after do
|
24
|
+
# do_something
|
25
|
+
# travel_back
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# # good
|
29
|
+
# after do
|
30
|
+
# do_something
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
class RedundantTravelBack < Base
|
34
|
+
include RangeHelp
|
35
|
+
extend AutoCorrector
|
36
|
+
extend TargetRailsVersion
|
37
|
+
|
38
|
+
minimum_target_rails_version 5.2
|
39
|
+
|
40
|
+
MSG = 'Redundant `travel_back` detected.'
|
41
|
+
RESTRICT_ON_SEND = %i[travel_back].freeze
|
42
|
+
|
43
|
+
def on_send(node)
|
44
|
+
return unless node.each_ancestor(:def, :block).any? do |ancestor|
|
45
|
+
method_name = ancestor.def_type? ? :teardown : :after
|
46
|
+
|
47
|
+
ancestor.method?(method_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
add_offense(node) do |corrector|
|
51
|
+
corrector.remove(range_by_whole_lines(node.source_range, include_final_newline: true))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
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)
|
@@ -343,8 +351,8 @@ module RuboCop
|
|
343
351
|
|
344
352
|
def within_reversible_or_up_only_block?(node)
|
345
353
|
node.each_ancestor(:block).any? do |ancestor|
|
346
|
-
ancestor.block_type? &&
|
347
|
-
ancestor.send_node.method?(:reversible) ||
|
354
|
+
(ancestor.block_type? &&
|
355
|
+
ancestor.send_node.method?(:reversible)) ||
|
348
356
|
ancestor.send_node.method?(:up_only)
|
349
357
|
end
|
350
358
|
end
|
@@ -14,6 +14,8 @@ module RuboCop
|
|
14
14
|
# # good
|
15
15
|
# scope :something, -> { where(something: true) }
|
16
16
|
class ScopeArgs < Base
|
17
|
+
extend AutoCorrector
|
18
|
+
|
17
19
|
MSG = 'Use `lambda`/`proc` instead of a plain method call.'
|
18
20
|
RESTRICT_ON_SEND = %i[scope].freeze
|
19
21
|
|
@@ -21,7 +23,9 @@ module RuboCop
|
|
21
23
|
|
22
24
|
def on_send(node)
|
23
25
|
scope?(node) do |second_arg|
|
24
|
-
add_offense(second_arg)
|
26
|
+
add_offense(second_arg) do |corrector|
|
27
|
+
corrector.replace(second_arg, "-> { #{second_arg.source} }")
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -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)
|
@@ -72,6 +72,7 @@ require_relative 'rails/read_write_attribute'
|
|
72
72
|
require_relative 'rails/redundant_allow_nil'
|
73
73
|
require_relative 'rails/redundant_foreign_key'
|
74
74
|
require_relative 'rails/redundant_receiver_in_with_options'
|
75
|
+
require_relative 'rails/redundant_travel_back'
|
75
76
|
require_relative 'rails/reflection_class_name'
|
76
77
|
require_relative 'rails/refute_methods'
|
77
78
|
require_relative 'rails/relative_date_constant'
|
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.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
|
@@ -72,6 +72,7 @@ extra_rdoc_files:
|
|
72
72
|
files:
|
73
73
|
- LICENSE.txt
|
74
74
|
- README.md
|
75
|
+
- bin/console
|
75
76
|
- bin/setup
|
76
77
|
- config/default.yml
|
77
78
|
- config/obsoletion.yml
|
@@ -147,6 +148,7 @@ files:
|
|
147
148
|
- lib/rubocop/cop/rails/redundant_allow_nil.rb
|
148
149
|
- lib/rubocop/cop/rails/redundant_foreign_key.rb
|
149
150
|
- lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb
|
151
|
+
- lib/rubocop/cop/rails/redundant_travel_back.rb
|
150
152
|
- lib/rubocop/cop/rails/reflection_class_name.rb
|
151
153
|
- lib/rubocop/cop/rails/refute_methods.rb
|
152
154
|
- lib/rubocop/cop/rails/relative_date_constant.rb
|
@@ -186,7 +188,7 @@ metadata:
|
|
186
188
|
homepage_uri: https://docs.rubocop.org/rubocop-rails/
|
187
189
|
changelog_uri: https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md
|
188
190
|
source_code_uri: https://github.com/rubocop/rubocop-rails/
|
189
|
-
documentation_uri: https://docs.rubocop.org/rubocop-rails/2.
|
191
|
+
documentation_uri: https://docs.rubocop.org/rubocop-rails/2.12/
|
190
192
|
bug_tracker_uri: https://github.com/rubocop/rubocop-rails/issues
|
191
193
|
post_install_message:
|
192
194
|
rdoc_options: []
|
@@ -203,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
205
|
- !ruby/object:Gem::Version
|
204
206
|
version: '0'
|
205
207
|
requirements: []
|
206
|
-
rubygems_version: 3.2.
|
208
|
+
rubygems_version: 3.2.22
|
207
209
|
signing_key:
|
208
210
|
specification_version: 4
|
209
211
|
summary: Automatic Rails code style checking tool.
|