rubocop-rails 2.11.2 → 2.11.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/lib/rubocop/cop/mixin/active_record_helper.rb +14 -2
- data/lib/rubocop/cop/rails/active_record_callbacks_order.rb +1 -9
- data/lib/rubocop/cop/rails/redundant_allow_nil.rb +2 -10
- data/lib/rubocop/cop/rails/unique_validation_without_index.rb +1 -1
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afc20a9d5f0799fab1f02a5a05c3b297a47b1713f6b948a25511da46b2e5a332
|
4
|
+
data.tar.gz: d71033e04f2cd0b1f7801d1ab80d99859af6e3d1bfba9551dec1d18a0e7b40dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eab328cf38c0f4957b79c3722175edd1a259af69f6c7c4a4501bc72a245b70ef3d4290b4daf4ef6925bf643dcffb1370a50ccfc5e7e870e138c3df675598df54
|
7
|
+
data.tar.gz: 7fb02325ab085ed0d716718dc02da92b39da5710b117b49a722f8f0d4de4d2e47648278a39aff455b81d2186b4914eed7f797fbdfd86d2ff4ee570dc20543309
|
@@ -57,12 +57,13 @@ module RuboCop
|
|
57
57
|
# Resolve relation into column name.
|
58
58
|
# It just returns column_name if the column exists.
|
59
59
|
# Or it tries to resolve column_name as a relation.
|
60
|
+
# Returns an array of column names if the relation is polymorphic.
|
60
61
|
# It returns `nil` if it can't resolve.
|
61
62
|
#
|
62
63
|
# @param name [String]
|
63
64
|
# @param class_node [RuboCop::AST::Node]
|
64
65
|
# @param table [RuboCop::Rails::SchemaLoader::Table]
|
65
|
-
# @return [String, nil]
|
66
|
+
# @return [Array, String, nil]
|
66
67
|
def resolve_relation_into_column(name:, class_node:, table:)
|
67
68
|
return unless table
|
68
69
|
return name if table.with_column?(name: name)
|
@@ -71,7 +72,9 @@ module RuboCop
|
|
71
72
|
next unless belongs_to.first_argument.value.to_s == name
|
72
73
|
|
73
74
|
fk = foreign_key_of(belongs_to) || "#{name}_id"
|
74
|
-
|
75
|
+
next unless table.with_column?(name: fk)
|
76
|
+
|
77
|
+
return polymorphic?(belongs_to) ? [fk, "#{name}_type"] : fk
|
75
78
|
end
|
76
79
|
nil
|
77
80
|
end
|
@@ -88,6 +91,15 @@ module RuboCop
|
|
88
91
|
end
|
89
92
|
end
|
90
93
|
|
94
|
+
def polymorphic?(belongs_to)
|
95
|
+
options = belongs_to.last_argument
|
96
|
+
return false unless options.hash_type?
|
97
|
+
|
98
|
+
options.each_pair.any? do |pair|
|
99
|
+
pair.key.sym_type? && pair.key.value == :polymorphic && pair.value.true_type?
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
91
103
|
def in_where?(node)
|
92
104
|
send_node = node.each_ancestor(:send).first
|
93
105
|
send_node && WHERE_METHODS.include?(send_node.method_name)
|
@@ -71,7 +71,7 @@ module RuboCop
|
|
71
71
|
|
72
72
|
# Autocorrect by swapping between two nodes autocorrecting them
|
73
73
|
def autocorrect(corrector, node)
|
74
|
-
previous =
|
74
|
+
previous = node.left_siblings.reverse_each.find do |sibling|
|
75
75
|
callback?(sibling)
|
76
76
|
end
|
77
77
|
|
@@ -96,14 +96,6 @@ module RuboCop
|
|
96
96
|
node.send_type? && CALLBACKS_ORDER_MAP.key?(node.method_name)
|
97
97
|
end
|
98
98
|
|
99
|
-
def left_siblings_of(node)
|
100
|
-
siblings_of(node)[0, node.sibling_index]
|
101
|
-
end
|
102
|
-
|
103
|
-
def siblings_of(node)
|
104
|
-
node.parent.children
|
105
|
-
end
|
106
|
-
|
107
99
|
def source_range_with_comment(node)
|
108
100
|
begin_pos = begin_pos_with_comment(node)
|
109
101
|
end_pos = end_position_for(node)
|
@@ -56,8 +56,8 @@ module RuboCop
|
|
56
56
|
|
57
57
|
def register_offense(allow_nil, message)
|
58
58
|
add_offense(allow_nil, message: message) do |corrector|
|
59
|
-
prv_sib =
|
60
|
-
nxt_sib =
|
59
|
+
prv_sib = allow_nil.left_sibling
|
60
|
+
nxt_sib = allow_nil.right_sibling
|
61
61
|
|
62
62
|
if nxt_sib
|
63
63
|
corrector.remove(range_between(node_beg(allow_nil), node_beg(nxt_sib)))
|
@@ -88,14 +88,6 @@ module RuboCop
|
|
88
88
|
nil
|
89
89
|
end
|
90
90
|
|
91
|
-
def previous_sibling(node)
|
92
|
-
node.parent.children[node.sibling_index - 1]
|
93
|
-
end
|
94
|
-
|
95
|
-
def next_sibling(node)
|
96
|
-
node.parent.children[node.sibling_index + 1]
|
97
|
-
end
|
98
|
-
|
99
91
|
def node_beg(node)
|
100
92
|
node.loc.expression.begin_pos
|
101
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.11.
|
4
|
+
version: 2.11.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-07-
|
13
|
+
date: 2021-07-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|