rubocop-rails 2.4.0 → 2.4.1
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 +3 -2
- data/lib/rubocop/cop/rails/belongs_to.rb +1 -1
- data/lib/rubocop/cop/rails/blank.rb +2 -2
- data/lib/rubocop/cop/rails/bulk_change_table.rb +8 -3
- data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +4 -4
- data/lib/rubocop/cop/rails/date.rb +4 -4
- data/lib/rubocop/cop/rails/delegate.rb +1 -1
- data/lib/rubocop/cop/rails/delegate_allow_blank.rb +1 -1
- data/lib/rubocop/cop/rails/enum_hash.rb +12 -1
- data/lib/rubocop/cop/rails/environment_comparison.rb +3 -3
- data/lib/rubocop/cop/rails/file_path.rb +3 -3
- data/lib/rubocop/cop/rails/find_by.rb +1 -1
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +6 -6
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +1 -1
- data/lib/rubocop/cop/rails/http_status.rb +2 -2
- data/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +1 -1
- data/lib/rubocop/cop/rails/inverse_of.rb +9 -9
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +1 -1
- data/lib/rubocop/cop/rails/link_to_blank.rb +3 -3
- data/lib/rubocop/cop/rails/not_null_column.rb +4 -4
- data/lib/rubocop/cop/rails/output.rb +2 -2
- data/lib/rubocop/cop/rails/presence.rb +2 -2
- data/lib/rubocop/cop/rails/present.rb +2 -2
- data/lib/rubocop/cop/rails/rake_environment.rb +7 -7
- data/lib/rubocop/cop/rails/read_write_attribute.rb +1 -1
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +3 -3
- data/lib/rubocop/cop/rails/reflection_class_name.rb +2 -2
- data/lib/rubocop/cop/rails/relative_date_constant.rb +12 -3
- data/lib/rubocop/cop/rails/request_referer.rb +1 -1
- data/lib/rubocop/cop/rails/reversible_migration.rb +5 -5
- data/lib/rubocop/cop/rails/safe_navigation.rb +1 -1
- data/lib/rubocop/cop/rails/safe_navigation_with_blank.rb +1 -1
- data/lib/rubocop/cop/rails/skips_model_validations.rb +1 -1
- data/lib/rubocop/cop/rails/unknown_env.rb +1 -1
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9d8cbc9fa9fc0752a334a92dd7af50f2a33331ac1b9604dc7c1f27efbc141e6
|
4
|
+
data.tar.gz: 81833c9b0dbc71254f75f18eb59a13147025efdff95342c3ba1855e773301fc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5ffc7a5e763076a13e5addebf2b4321ebfddbbb19e752bfe9697003eb4451e5d5eebc4ced8c2f3f55e1e10f24a81670e14b7ec48ee748d1c15996085618b5c8
|
7
|
+
data.tar.gz: 0e8b3557bfa819b2fb1304f992a48845afbb52db0c8c7beb970bbcc09c4345c5f9d2f9f273efb2692374f3a03c28c6d615824af20ca669c40359299dca53f41a
|
data/config/default.yml
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
AllCops:
|
4
4
|
Exclude:
|
5
|
-
- bin
|
5
|
+
- bin/*
|
6
|
+
- db/schema.rb
|
6
7
|
# What version of Rails is the inspected code using? If a value is specified
|
7
8
|
# for TargetRailsVersion then it is used. Acceptable values are specificed
|
8
9
|
# as a float (i.e. 5.1); the patch version of Rails should not be included.
|
@@ -334,7 +335,7 @@ Rails/Present:
|
|
334
335
|
UnlessBlank: true
|
335
336
|
|
336
337
|
Rails/RakeEnvironment:
|
337
|
-
Description: '
|
338
|
+
Description: 'Include `:environment` as a dependency for all Rake tasks.'
|
338
339
|
Enabled: true
|
339
340
|
Safe: false
|
340
341
|
VersionAdded: '2.4'
|
@@ -65,7 +65,7 @@ module RuboCop
|
|
65
65
|
'In most configurations, this is the default and you can omit ' \
|
66
66
|
'this option altogether'
|
67
67
|
|
68
|
-
def_node_matcher :match_belongs_to_with_options,
|
68
|
+
def_node_matcher :match_belongs_to_with_options, <<~PATTERN
|
69
69
|
(send _ :belongs_to _
|
70
70
|
(hash <$(pair (sym :required) ${true false}) ...>)
|
71
71
|
)
|
@@ -63,7 +63,7 @@ module RuboCop
|
|
63
63
|
# that have a single method call on the left hand side
|
64
64
|
# (`bar || foo.empty?`) will blow up when checking
|
65
65
|
# `(send (:nil) :== $_)`.
|
66
|
-
def_node_matcher :nil_or_empty?,
|
66
|
+
def_node_matcher :nil_or_empty?, <<~PATTERN
|
67
67
|
(or
|
68
68
|
{
|
69
69
|
(send $_ :!)
|
@@ -82,7 +82,7 @@ module RuboCop
|
|
82
82
|
|
83
83
|
def_node_matcher :defining_blank?, '(def :blank? (args) ...)'
|
84
84
|
|
85
|
-
def_node_matcher :unless_present?,
|
85
|
+
def_node_matcher :unless_present?, <<~PATTERN
|
86
86
|
(:if $(send $_ :present?) {nil? (...)} ...)
|
87
87
|
PATTERN
|
88
88
|
|
@@ -138,9 +138,9 @@ module RuboCop
|
|
138
138
|
|
139
139
|
recorder = AlterMethodsRecorder.new
|
140
140
|
|
141
|
-
node.body.
|
142
|
-
if
|
143
|
-
recorder.process(
|
141
|
+
node.body.child_nodes.each do |child_node|
|
142
|
+
if call_to_combinable_alter_method? child_node
|
143
|
+
recorder.process(child_node)
|
144
144
|
else
|
145
145
|
recorder.flush
|
146
146
|
end
|
@@ -218,6 +218,11 @@ module RuboCop
|
|
218
218
|
end
|
219
219
|
end
|
220
220
|
|
221
|
+
def call_to_combinable_alter_method?(child_node)
|
222
|
+
child_node.send_type? &&
|
223
|
+
combinable_alter_methods.include?(child_node.method_name)
|
224
|
+
end
|
225
|
+
|
221
226
|
def combinable_alter_methods
|
222
227
|
case database
|
223
228
|
when MYSQL
|
@@ -43,22 +43,22 @@ module RuboCop
|
|
43
43
|
class CreateTableWithTimestamps < Cop
|
44
44
|
MSG = 'Add timestamps when creating a new table.'
|
45
45
|
|
46
|
-
def_node_matcher :create_table_with_block?,
|
46
|
+
def_node_matcher :create_table_with_block?, <<~PATTERN
|
47
47
|
(block
|
48
48
|
(send nil? :create_table ...)
|
49
49
|
(args (arg _var))
|
50
50
|
_)
|
51
51
|
PATTERN
|
52
52
|
|
53
|
-
def_node_matcher :create_table_with_timestamps_proc?,
|
53
|
+
def_node_matcher :create_table_with_timestamps_proc?, <<~PATTERN
|
54
54
|
(send nil? :create_table (sym _) ... (block-pass (sym :timestamps)))
|
55
55
|
PATTERN
|
56
56
|
|
57
|
-
def_node_search :timestamps_included?,
|
57
|
+
def_node_search :timestamps_included?, <<~PATTERN
|
58
58
|
(send _var :timestamps ...)
|
59
59
|
PATTERN
|
60
60
|
|
61
|
-
def_node_search :created_at_or_updated_at_included?,
|
61
|
+
def_node_search :created_at_or_updated_at_included?, <<~PATTERN
|
62
62
|
(send _var :datetime
|
63
63
|
{(sym {:created_at :updated_at})(str {"created_at" "updated_at"})}
|
64
64
|
...)
|
@@ -84,13 +84,13 @@ module RuboCop
|
|
84
84
|
private
|
85
85
|
|
86
86
|
def check_deprecated_methods(node)
|
87
|
-
DEPRECATED_METHODS.each do |
|
88
|
-
next unless node.method?(deprecated.to_sym)
|
87
|
+
DEPRECATED_METHODS.each do |method|
|
88
|
+
next unless node.method?(method[:deprecated].to_sym)
|
89
89
|
|
90
90
|
add_offense(node, location: :selector,
|
91
91
|
message: format(DEPRECATED_MSG,
|
92
|
-
deprecated: deprecated,
|
93
|
-
relevant: relevant))
|
92
|
+
deprecated: method[:deprecated],
|
93
|
+
relevant: method[:relevant]))
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
class DelegateAllowBlank < Cop
|
17
17
|
MSG = '`allow_blank` is not a valid option, use `allow_nil`.'
|
18
18
|
|
19
|
-
def_node_matcher :allow_blank_option,
|
19
|
+
def_node_matcher :allow_blank_option, <<~PATTERN
|
20
20
|
(send nil? :delegate _ (hash <$(pair (sym :allow_blank) true) ...>))
|
21
21
|
PATTERN
|
22
22
|
|
@@ -42,7 +42,7 @@ module RuboCop
|
|
42
42
|
|
43
43
|
def autocorrect(node)
|
44
44
|
hash = node.children.each_with_index.map do |elem, index|
|
45
|
-
"#{elem
|
45
|
+
"#{source(elem)} => #{index}"
|
46
46
|
end.join(', ')
|
47
47
|
|
48
48
|
->(corrector) { corrector.replace(node.loc.expression, "{#{hash}}") }
|
@@ -58,6 +58,17 @@ module RuboCop
|
|
58
58
|
key.source
|
59
59
|
end
|
60
60
|
end
|
61
|
+
|
62
|
+
def source(elem)
|
63
|
+
case elem.type
|
64
|
+
when :str
|
65
|
+
elem.value.dump
|
66
|
+
when :sym
|
67
|
+
elem.value.inspect
|
68
|
+
else
|
69
|
+
elem.source
|
70
|
+
end
|
71
|
+
end
|
61
72
|
end
|
62
73
|
end
|
63
74
|
end
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
SYM_MSG = 'Do not compare `Rails.env` with a symbol, it will always ' \
|
22
22
|
'evaluate to `false`.'
|
23
23
|
|
24
|
-
def_node_matcher :environment_str_comparison?,
|
24
|
+
def_node_matcher :environment_str_comparison?, <<~PATTERN
|
25
25
|
(send
|
26
26
|
(send (const {nil? cbase} :Rails) :env)
|
27
27
|
:==
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
)
|
30
30
|
PATTERN
|
31
31
|
|
32
|
-
def_node_matcher :environment_sym_comparison?,
|
32
|
+
def_node_matcher :environment_sym_comparison?, <<~PATTERN
|
33
33
|
(send
|
34
34
|
(send (const {nil? cbase} :Rails) :env)
|
35
35
|
:==
|
@@ -59,7 +59,7 @@ module RuboCop
|
|
59
59
|
"#{node.receiver.source}.#{content(node.first_argument)}?"
|
60
60
|
end
|
61
61
|
|
62
|
-
def_node_matcher :content,
|
62
|
+
def_node_matcher :content, <<~PATTERN
|
63
63
|
({str sym} $_)
|
64
64
|
PATTERN
|
65
65
|
end
|
@@ -34,15 +34,15 @@ module RuboCop
|
|
34
34
|
MSG_ARGUMENTS = 'Please use `Rails.root.join(\'path\', \'to\')` ' \
|
35
35
|
'instead.'
|
36
36
|
|
37
|
-
def_node_matcher :file_join_nodes?,
|
37
|
+
def_node_matcher :file_join_nodes?, <<~PATTERN
|
38
38
|
(send (const nil? :File) :join ...)
|
39
39
|
PATTERN
|
40
40
|
|
41
|
-
def_node_search :rails_root_nodes?,
|
41
|
+
def_node_search :rails_root_nodes?, <<~PATTERN
|
42
42
|
(send (const nil? :Rails) :root)
|
43
43
|
PATTERN
|
44
44
|
|
45
|
-
def_node_matcher :rails_root_join_nodes?,
|
45
|
+
def_node_matcher :rails_root_join_nodes?, <<~PATTERN
|
46
46
|
(send (send (const nil? :Rails) :root) :join ...)
|
47
47
|
PATTERN
|
48
48
|
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
MSG = 'Use `find_by` instead of `where.%<method>s`.'
|
20
20
|
TARGET_SELECTORS = %i[first take].freeze
|
21
21
|
|
22
|
-
def_node_matcher :where_first?,
|
22
|
+
def_node_matcher :where_first?, <<~PATTERN
|
23
23
|
(send ({send csend} _ :where ...) {:first :take})
|
24
24
|
PATTERN
|
25
25
|
|
@@ -23,27 +23,27 @@ module RuboCop
|
|
23
23
|
class HasManyOrHasOneDependent < Cop
|
24
24
|
MSG = 'Specify a `:dependent` option.'
|
25
25
|
|
26
|
-
def_node_search :active_resource_class?,
|
26
|
+
def_node_search :active_resource_class?, <<~PATTERN
|
27
27
|
(const (const nil? :ActiveResource) :Base)
|
28
28
|
PATTERN
|
29
29
|
|
30
|
-
def_node_matcher :association_without_options?,
|
30
|
+
def_node_matcher :association_without_options?, <<~PATTERN
|
31
31
|
(send nil? {:has_many :has_one} _)
|
32
32
|
PATTERN
|
33
33
|
|
34
|
-
def_node_matcher :association_with_options?,
|
34
|
+
def_node_matcher :association_with_options?, <<~PATTERN
|
35
35
|
(send nil? {:has_many :has_one} _ (hash $...))
|
36
36
|
PATTERN
|
37
37
|
|
38
|
-
def_node_matcher :dependent_option?,
|
38
|
+
def_node_matcher :dependent_option?, <<~PATTERN
|
39
39
|
(pair (sym :dependent) !nil)
|
40
40
|
PATTERN
|
41
41
|
|
42
|
-
def_node_matcher :present_option?,
|
42
|
+
def_node_matcher :present_option?, <<~PATTERN
|
43
43
|
(pair (sym :through) !nil)
|
44
44
|
PATTERN
|
45
45
|
|
46
|
-
def_node_matcher :with_options_block,
|
46
|
+
def_node_matcher :with_options_block, <<~PATTERN
|
47
47
|
(block
|
48
48
|
(send nil? :with_options
|
49
49
|
(hash $...))
|
@@ -34,14 +34,14 @@ module RuboCop
|
|
34
34
|
class HttpStatus < Cop
|
35
35
|
include ConfigurableEnforcedStyle
|
36
36
|
|
37
|
-
def_node_matcher :http_status,
|
37
|
+
def_node_matcher :http_status, <<~PATTERN
|
38
38
|
{
|
39
39
|
(send nil? {:render :redirect_to} _ $hash)
|
40
40
|
(send nil? {:render :redirect_to} $hash)
|
41
41
|
}
|
42
42
|
PATTERN
|
43
43
|
|
44
|
-
def_node_matcher :status_code,
|
44
|
+
def_node_matcher :status_code, <<~PATTERN
|
45
45
|
(hash <(pair (sym :status) ${int sym}) ...>)
|
46
46
|
PATTERN
|
47
47
|
|
@@ -137,39 +137,39 @@ module RuboCop
|
|
137
137
|
NIL_MSG = 'You specified `inverse_of: nil`, you probably meant to ' \
|
138
138
|
'use `inverse_of: false`.'
|
139
139
|
|
140
|
-
def_node_matcher :association_recv_arguments,
|
140
|
+
def_node_matcher :association_recv_arguments, <<~PATTERN
|
141
141
|
(send $_ {:has_many :has_one :belongs_to} _ $...)
|
142
142
|
PATTERN
|
143
143
|
|
144
|
-
def_node_matcher :options_from_argument,
|
144
|
+
def_node_matcher :options_from_argument, <<~PATTERN
|
145
145
|
(hash $...)
|
146
146
|
PATTERN
|
147
147
|
|
148
|
-
def_node_matcher :conditions_option?,
|
148
|
+
def_node_matcher :conditions_option?, <<~PATTERN
|
149
149
|
(pair (sym :conditions) !nil)
|
150
150
|
PATTERN
|
151
151
|
|
152
|
-
def_node_matcher :through_option?,
|
152
|
+
def_node_matcher :through_option?, <<~PATTERN
|
153
153
|
(pair (sym :through) !nil)
|
154
154
|
PATTERN
|
155
155
|
|
156
|
-
def_node_matcher :polymorphic_option?,
|
156
|
+
def_node_matcher :polymorphic_option?, <<~PATTERN
|
157
157
|
(pair (sym :polymorphic) !nil)
|
158
158
|
PATTERN
|
159
159
|
|
160
|
-
def_node_matcher :as_option?,
|
160
|
+
def_node_matcher :as_option?, <<~PATTERN
|
161
161
|
(pair (sym :as) !nil)
|
162
162
|
PATTERN
|
163
163
|
|
164
|
-
def_node_matcher :foreign_key_option?,
|
164
|
+
def_node_matcher :foreign_key_option?, <<~PATTERN
|
165
165
|
(pair (sym :foreign_key) !nil)
|
166
166
|
PATTERN
|
167
167
|
|
168
|
-
def_node_matcher :inverse_of_option?,
|
168
|
+
def_node_matcher :inverse_of_option?, <<~PATTERN
|
169
169
|
(pair (sym :inverse_of) !nil)
|
170
170
|
PATTERN
|
171
171
|
|
172
|
-
def_node_matcher :inverse_of_nil_option?,
|
172
|
+
def_node_matcher :inverse_of_nil_option?, <<~PATTERN
|
173
173
|
(pair (sym :inverse_of) nil)
|
174
174
|
PATTERN
|
175
175
|
|
@@ -23,15 +23,15 @@ module RuboCop
|
|
23
23
|
class LinkToBlank < Cop
|
24
24
|
MSG = 'Specify a `:rel` option containing noopener.'
|
25
25
|
|
26
|
-
def_node_matcher :blank_target?,
|
26
|
+
def_node_matcher :blank_target?, <<~PATTERN
|
27
27
|
(pair {(sym :target) (str "target")} {(str "_blank") (sym :_blank)})
|
28
28
|
PATTERN
|
29
29
|
|
30
|
-
def_node_matcher :includes_noopener?,
|
30
|
+
def_node_matcher :includes_noopener?, <<~PATTERN
|
31
31
|
(pair {(sym :rel) (str "rel")} ({str sym} #contains_noopener?))
|
32
32
|
PATTERN
|
33
33
|
|
34
|
-
def_node_matcher :rel_node?,
|
34
|
+
def_node_matcher :rel_node?, <<~PATTERN
|
35
35
|
(pair {(sym :rel) (str "rel")} (str _))
|
36
36
|
PATTERN
|
37
37
|
|
@@ -19,19 +19,19 @@ module RuboCop
|
|
19
19
|
class NotNullColumn < Cop
|
20
20
|
MSG = 'Do not add a NOT NULL column without a default value.'
|
21
21
|
|
22
|
-
def_node_matcher :add_not_null_column?,
|
22
|
+
def_node_matcher :add_not_null_column?, <<~PATTERN
|
23
23
|
(send nil? :add_column _ _ _ (hash $...))
|
24
24
|
PATTERN
|
25
25
|
|
26
|
-
def_node_matcher :add_not_null_reference?,
|
26
|
+
def_node_matcher :add_not_null_reference?, <<~PATTERN
|
27
27
|
(send nil? :add_reference _ _ (hash $...))
|
28
28
|
PATTERN
|
29
29
|
|
30
|
-
def_node_matcher :null_false?,
|
30
|
+
def_node_matcher :null_false?, <<~PATTERN
|
31
31
|
(pair (sym :null) (false))
|
32
32
|
PATTERN
|
33
33
|
|
34
|
-
def_node_matcher :default_option?,
|
34
|
+
def_node_matcher :default_option?, <<~PATTERN
|
35
35
|
(pair (sym :default) !nil)
|
36
36
|
PATTERN
|
37
37
|
|
@@ -17,11 +17,11 @@ module RuboCop
|
|
17
17
|
MSG = 'Do not write to stdout. ' \
|
18
18
|
"Use Rails's logger if you want to log."
|
19
19
|
|
20
|
-
def_node_matcher :output?,
|
20
|
+
def_node_matcher :output?, <<~PATTERN
|
21
21
|
(send nil? {:ap :p :pp :pretty_print :print :puts} ...)
|
22
22
|
PATTERN
|
23
23
|
|
24
|
-
def_node_matcher :io_output?,
|
24
|
+
def_node_matcher :io_output?, <<~PATTERN
|
25
25
|
(send
|
26
26
|
{
|
27
27
|
(gvar #match_gvar?)
|
@@ -42,7 +42,7 @@ module RuboCop
|
|
42
42
|
|
43
43
|
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
|
44
44
|
|
45
|
-
def_node_matcher :redundant_receiver_and_other,
|
45
|
+
def_node_matcher :redundant_receiver_and_other, <<~PATTERN
|
46
46
|
{
|
47
47
|
(if
|
48
48
|
(send $_recv :present?)
|
@@ -57,7 +57,7 @@ module RuboCop
|
|
57
57
|
}
|
58
58
|
PATTERN
|
59
59
|
|
60
|
-
def_node_matcher :redundant_negative_receiver_and_other,
|
60
|
+
def_node_matcher :redundant_negative_receiver_and_other, <<~PATTERN
|
61
61
|
{
|
62
62
|
(if
|
63
63
|
(send (send $_recv :present?) :!)
|
@@ -50,7 +50,7 @@ module RuboCop
|
|
50
50
|
MSG_UNLESS_BLANK = 'Use `if %<prefer>s` instead of ' \
|
51
51
|
'`%<current>s`.'
|
52
52
|
|
53
|
-
def_node_matcher :exists_and_not_empty?,
|
53
|
+
def_node_matcher :exists_and_not_empty?, <<~PATTERN
|
54
54
|
(and
|
55
55
|
{
|
56
56
|
(send (send $_ :nil?) :!)
|
@@ -66,7 +66,7 @@ module RuboCop
|
|
66
66
|
|
67
67
|
def_node_matcher :not_blank?, '(send (send $_ :blank?) :!)'
|
68
68
|
|
69
|
-
def_node_matcher :unless_blank?,
|
69
|
+
def_node_matcher :unless_blank?, <<~PATTERN
|
70
70
|
(:if $(send $_ :blank?) {nil? (...)} ...)
|
71
71
|
PATTERN
|
72
72
|
|
@@ -3,16 +3,16 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
# This cop checks
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# models
|
6
|
+
# This cop checks for Rake tasks without the `:environment` task
|
7
|
+
# dependency. The `:environment` task loads application code for other
|
8
|
+
# Rake tasks. Without it, tasks cannot make use of application code like
|
9
|
+
# models.
|
10
10
|
#
|
11
11
|
# You can ignore the offense if the task satisfies at least one of the
|
12
12
|
# following conditions:
|
13
13
|
#
|
14
14
|
# * The task does not need application code.
|
15
|
-
# * The task invokes
|
15
|
+
# * The task invokes the `:environment` task.
|
16
16
|
#
|
17
17
|
# @example
|
18
18
|
# # bad
|
@@ -26,9 +26,9 @@ module RuboCop
|
|
26
26
|
# end
|
27
27
|
#
|
28
28
|
class RakeEnvironment < Cop
|
29
|
-
MSG = '
|
29
|
+
MSG = 'Include `:environment` task as a dependency for all Rake tasks.'
|
30
30
|
|
31
|
-
def_node_matcher :task_definition?,
|
31
|
+
def_node_matcher :task_definition?, <<~PATTERN
|
32
32
|
(send nil? :task ...)
|
33
33
|
PATTERN
|
34
34
|
|
@@ -26,7 +26,7 @@ module RuboCop
|
|
26
26
|
class ReadWriteAttribute < Cop
|
27
27
|
MSG = 'Prefer `%<prefer>s` over `%<current>s`.'
|
28
28
|
|
29
|
-
def_node_matcher :read_write_attribute?,
|
29
|
+
def_node_matcher :read_write_attribute?, <<~PATTERN
|
30
30
|
{
|
31
31
|
(send nil? :read_attribute _)
|
32
32
|
(send nil? :write_attribute _ _)
|
@@ -62,7 +62,7 @@ module RuboCop
|
|
62
62
|
|
63
63
|
MSG = 'Redundant receiver in `with_options`.'
|
64
64
|
|
65
|
-
def_node_matcher :with_options?,
|
65
|
+
def_node_matcher :with_options?, <<~PATTERN
|
66
66
|
(block
|
67
67
|
(send nil? :with_options
|
68
68
|
(...))
|
@@ -71,11 +71,11 @@ module RuboCop
|
|
71
71
|
$_body)
|
72
72
|
PATTERN
|
73
73
|
|
74
|
-
def_node_search :all_block_nodes_in,
|
74
|
+
def_node_search :all_block_nodes_in, <<~PATTERN
|
75
75
|
(block ...)
|
76
76
|
PATTERN
|
77
77
|
|
78
|
-
def_node_search :all_send_nodes_in,
|
78
|
+
def_node_search :all_send_nodes_in, <<~PATTERN
|
79
79
|
(send ...)
|
80
80
|
PATTERN
|
81
81
|
|
@@ -16,13 +16,13 @@ module RuboCop
|
|
16
16
|
class ReflectionClassName < Cop
|
17
17
|
MSG = 'Use a string value for `class_name`.'
|
18
18
|
|
19
|
-
def_node_matcher :association_with_reflection,
|
19
|
+
def_node_matcher :association_with_reflection, <<~PATTERN
|
20
20
|
(send nil? {:has_many :has_one :belongs_to} _
|
21
21
|
(hash <$#reflection_class_name ...>)
|
22
22
|
)
|
23
23
|
PATTERN
|
24
24
|
|
25
|
-
def_node_matcher :reflection_class_name,
|
25
|
+
def_node_matcher :reflection_class_name, <<~PATTERN
|
26
26
|
(pair (sym :class_name) [!dstr !str !sym])
|
27
27
|
PATTERN
|
28
28
|
|
@@ -14,6 +14,15 @@ module RuboCop
|
|
14
14
|
#
|
15
15
|
# # good
|
16
16
|
# class SomeClass
|
17
|
+
# EXPIRES = 1.week
|
18
|
+
#
|
19
|
+
# def self.expired_at
|
20
|
+
# EXPIRES.since
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# # good
|
25
|
+
# class SomeClass
|
17
26
|
# def self.expired_at
|
18
27
|
# 1.week.since
|
19
28
|
# end
|
@@ -68,7 +77,7 @@ module RuboCop
|
|
68
77
|
|
69
78
|
private
|
70
79
|
|
71
|
-
def_node_matcher :relative_date_assignment?,
|
80
|
+
def_node_matcher :relative_date_assignment?, <<~PATTERN
|
72
81
|
{
|
73
82
|
(casgn _ _ (send _ ${:since :from_now :after :ago :until :before}))
|
74
83
|
(casgn _ _ ({erange irange} _ (send _ ${:since :from_now :after :ago :until :before})))
|
@@ -76,11 +85,11 @@ module RuboCop
|
|
76
85
|
}
|
77
86
|
PATTERN
|
78
87
|
|
79
|
-
def_node_matcher :relative_date_or_assignment?,
|
88
|
+
def_node_matcher :relative_date_or_assignment?, <<~PATTERN
|
80
89
|
(:or_asgn (casgn _ _) (send _ ${:since :from_now :after :ago :until :before}))
|
81
90
|
PATTERN
|
82
91
|
|
83
|
-
def_node_matcher :relative_date?,
|
92
|
+
def_node_matcher :relative_date?, <<~PATTERN
|
84
93
|
{
|
85
94
|
({erange irange} _ (send _ ${:since :from_now :after :ago :until :before}))
|
86
95
|
({erange irange} (send _ ${:since :from_now :after :ago :until :before}) _)
|
@@ -128,23 +128,23 @@ module RuboCop
|
|
128
128
|
class ReversibleMigration < Cop
|
129
129
|
MSG = '%<action>s is not reversible.'
|
130
130
|
|
131
|
-
def_node_matcher :irreversible_schema_statement_call,
|
131
|
+
def_node_matcher :irreversible_schema_statement_call, <<~PATTERN
|
132
132
|
(send nil? ${:execute :remove_belongs_to} ...)
|
133
133
|
PATTERN
|
134
134
|
|
135
|
-
def_node_matcher :drop_table_call,
|
135
|
+
def_node_matcher :drop_table_call, <<~PATTERN
|
136
136
|
(send nil? :drop_table ...)
|
137
137
|
PATTERN
|
138
138
|
|
139
|
-
def_node_matcher :remove_column_call,
|
139
|
+
def_node_matcher :remove_column_call, <<~PATTERN
|
140
140
|
(send nil? :remove_column $...)
|
141
141
|
PATTERN
|
142
142
|
|
143
|
-
def_node_matcher :remove_foreign_key_call,
|
143
|
+
def_node_matcher :remove_foreign_key_call, <<~PATTERN
|
144
144
|
(send nil? :remove_foreign_key _ $_)
|
145
145
|
PATTERN
|
146
146
|
|
147
|
-
def_node_matcher :change_table_call,
|
147
|
+
def_node_matcher :change_table_call, <<~PATTERN
|
148
148
|
(send nil? :change_table $_ ...)
|
149
149
|
PATTERN
|
150
150
|
|
@@ -24,7 +24,7 @@ module RuboCop
|
|
24
24
|
'Avoid calling `blank?` with the safe navigation operator ' \
|
25
25
|
'in conditionals.'
|
26
26
|
|
27
|
-
def_node_matcher :safe_navigation_blank_in_conditional?,
|
27
|
+
def_node_matcher :safe_navigation_blank_in_conditional?, <<~PATTERN
|
28
28
|
(if $(csend ... :blank?) ...)
|
29
29
|
PATTERN
|
30
30
|
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
(send #rails_env? $#unknown_env_predicate?)
|
32
32
|
PATTERN
|
33
33
|
|
34
|
-
def_node_matcher :unknown_environment_equal?,
|
34
|
+
def_node_matcher :unknown_environment_equal?, <<~PATTERN
|
35
35
|
{
|
36
36
|
(send #rails_env? {:== :===} $(str #unknown_env_name?))
|
37
37
|
(send $(str #unknown_env_name?) {:== :===} #rails_env?)
|
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.
|
4
|
+
version: 2.4.1
|
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: 2019-
|
13
|
+
date: 2019-12-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rack
|
@@ -40,9 +40,9 @@ dependencies:
|
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 0.72.0
|
43
|
-
description: |
|
44
|
-
|
45
|
-
|
43
|
+
description: |
|
44
|
+
Automatic Rails code style checking tool.
|
45
|
+
A RuboCop extension focused on enforcing Rails best practices and coding conventions.
|
46
46
|
email: rubocop@googlegroups.com
|
47
47
|
executables: []
|
48
48
|
extensions: []
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: '0'
|
143
143
|
requirements: []
|
144
|
-
rubygems_version: 3.
|
144
|
+
rubygems_version: 3.1.2
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: Automatic Rails code style checking tool.
|