rubocop-rails 2.9.0 → 2.9.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a4f37840f94de73bdcc15533ef3e5e95ee265a79fd0486b5e813ee926421d17
|
4
|
+
data.tar.gz: b2fee8ee1727d8cf33c1d0568f12378f1115d1ae00aa52295656d232de8c59af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4ceba3963546eaa994918f85d1558223de162f66de58ac48d1e466c2b126facf7548053c00fcbfcd4d05e2d1225eed32e15e6ff921627cfb2a14014119df757
|
7
|
+
data.tar.gz: af84d0f778766239432a0b599e21c0e6671b02739769570b2c8655df5f32770f796978747d02a321a5ad1ea2c009d60b7ec3e93b09f669106ad9305a4cc50c3e
|
@@ -30,7 +30,7 @@ module RuboCop
|
|
30
30
|
def on_send(node)
|
31
31
|
return unless node.receiver&.send_type?
|
32
32
|
return unless SCOPE_METHODS.include?(node.receiver.method_name)
|
33
|
-
return if
|
33
|
+
return if ignored?(node)
|
34
34
|
|
35
35
|
range = node.loc.selector
|
36
36
|
add_offense(range) do |corrector|
|
@@ -40,12 +40,9 @@ module RuboCop
|
|
40
40
|
|
41
41
|
private
|
42
42
|
|
43
|
-
def
|
44
|
-
node.each_node(:send).map(&:method_name)
|
45
|
-
|
46
|
-
|
47
|
-
def ignored?(relation_method)
|
48
|
-
cop_config['IgnoredMethods'].include?(relation_method)
|
43
|
+
def ignored?(node)
|
44
|
+
method_chain = node.each_node(:send).map(&:method_name)
|
45
|
+
(cop_config['IgnoredMethods'].map(&:to_sym) & method_chain).any?
|
49
46
|
end
|
50
47
|
end
|
51
48
|
end
|
@@ -13,6 +13,9 @@ module RuboCop
|
|
13
13
|
# variable, consider moving the behaviour elsewhere, for
|
14
14
|
# example to a model, decorator or presenter.
|
15
15
|
#
|
16
|
+
# Provided that a class inherits `ActionView::Helpers::FormBuilder`,
|
17
|
+
# an offense will not be registered.
|
18
|
+
#
|
16
19
|
# @example
|
17
20
|
# # bad
|
18
21
|
# def welcome_message
|
@@ -23,18 +26,41 @@ module RuboCop
|
|
23
26
|
# def welcome_message(user)
|
24
27
|
# "Hello #{user.name}"
|
25
28
|
# end
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
# class MyFormBuilder < ActionView::Helpers::FormBuilder
|
32
|
+
# @template.do_something
|
33
|
+
# end
|
26
34
|
class HelperInstanceVariable < Base
|
27
35
|
MSG = 'Do not use instance variables in helpers.'
|
28
36
|
|
37
|
+
def_node_matcher :form_builder_class?, <<~PATTERN
|
38
|
+
(const
|
39
|
+
(const
|
40
|
+
(const nil? :ActionView) :Helpers) :FormBuilder)
|
41
|
+
PATTERN
|
42
|
+
|
29
43
|
def on_ivar(node)
|
44
|
+
return if inherit_form_builder?(node)
|
45
|
+
|
30
46
|
add_offense(node)
|
31
47
|
end
|
32
48
|
|
33
49
|
def on_ivasgn(node)
|
34
|
-
return if node.parent.or_asgn_type?
|
50
|
+
return if node.parent.or_asgn_type? || inherit_form_builder?(node)
|
35
51
|
|
36
52
|
add_offense(node.loc.name)
|
37
53
|
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def inherit_form_builder?(node)
|
58
|
+
node.each_ancestor(:class) do |class_node|
|
59
|
+
return true if form_builder_class?(class_node.parent_class)
|
60
|
+
end
|
61
|
+
|
62
|
+
false
|
63
|
+
end
|
38
64
|
end
|
39
65
|
end
|
40
66
|
end
|
@@ -13,11 +13,13 @@ module RuboCop
|
|
13
13
|
# User.where('name IS NULL')
|
14
14
|
# User.where('name IN (?)', ['john', 'jane'])
|
15
15
|
# User.where('name IN (:names)', names: ['john', 'jane'])
|
16
|
+
# User.where('users.name = :name', name: 'Gabe')
|
16
17
|
#
|
17
18
|
# # good
|
18
19
|
# User.where(name: 'Gabe')
|
19
20
|
# User.where(name: nil)
|
20
21
|
# User.where(name: ['john', 'jane'])
|
22
|
+
# User.where(users: { name: 'Gabe' })
|
21
23
|
class WhereEquals < Base
|
22
24
|
include RangeHelp
|
23
25
|
extend AutoCorrector
|
@@ -68,7 +70,7 @@ module RuboCop
|
|
68
70
|
when EQ_ANONYMOUS_RE, IN_ANONYMOUS_RE
|
69
71
|
value_node.source
|
70
72
|
when EQ_NAMED_RE, IN_NAMED_RE
|
71
|
-
return unless value_node
|
73
|
+
return unless value_node&.hash_type?
|
72
74
|
|
73
75
|
pair = value_node.pairs.find { |p| p.key.value.to_sym == Regexp.last_match(2).to_sym }
|
74
76
|
pair.value.source
|
@@ -83,7 +85,9 @@ module RuboCop
|
|
83
85
|
|
84
86
|
def build_good_method(column, value)
|
85
87
|
if column.include?('.')
|
86
|
-
|
88
|
+
table, column = column.split('.')
|
89
|
+
|
90
|
+
"where(#{table}: { #{column}: #{value} })"
|
87
91
|
else
|
88
92
|
"where(#{column}: #{value})"
|
89
93
|
end
|
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.9.
|
4
|
+
version: 2.9.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: 2020-12-
|
13
|
+
date: 2020-12-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
|
-
rubygems_version: 3.2.
|
196
|
+
rubygems_version: 3.2.1
|
197
197
|
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Automatic Rails code style checking tool.
|