rubocop-rails 2.5.0 → 2.5.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: 2ad01eddf8f7245cdbba5eef8c2c7f73656707bde4dd3e1dc08e6604284e2c5b
|
4
|
+
data.tar.gz: b4542ee0b28af39310b2fbf6e5b7e276249144050edf90208036b8b9dafe64da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3c643803fcbeb378b60bf8c811bda542445d03ded462975d2c89f3a49e3f36b0c4f46468adbbbc768923a4f01545e5b03159ee2a675687bd49906b81dd28912
|
7
|
+
data.tar.gz: a471837a24adbb346243c23a2e88d0daceb2214632e7b92fc075b4936897fec91b06cb56d6131e65ea9716a643f3a635317357053364f29f6a7663ccefd62f32
|
data/config/default.yml
CHANGED
@@ -57,22 +57,30 @@ Rails/ActiveSupportAliases:
|
|
57
57
|
Rails/ApplicationController:
|
58
58
|
Description: 'Check that controllers subclass ApplicationController.'
|
59
59
|
Enabled: true
|
60
|
+
SafeAutoCorrect: false
|
60
61
|
VersionAdded: '2.4'
|
62
|
+
VersionChanged: '2.5'
|
61
63
|
|
62
64
|
Rails/ApplicationJob:
|
63
65
|
Description: 'Check that jobs subclass ApplicationJob.'
|
64
66
|
Enabled: true
|
67
|
+
SafeAutoCorrect: false
|
65
68
|
VersionAdded: '0.49'
|
69
|
+
VersionChanged: '2.5'
|
66
70
|
|
67
71
|
Rails/ApplicationMailer:
|
68
72
|
Description: 'Check that mailers subclass ApplicationMailer.'
|
69
73
|
Enabled: true
|
74
|
+
SafeAutoCorrect: false
|
70
75
|
VersionAdded: '2.4'
|
76
|
+
VersionChanged: '2.5'
|
71
77
|
|
72
78
|
Rails/ApplicationRecord:
|
73
79
|
Description: 'Check that models subclass ApplicationRecord.'
|
74
80
|
Enabled: true
|
81
|
+
SafeAutoCorrect: false
|
75
82
|
VersionAdded: '0.49'
|
83
|
+
VersionChanged: '2.5'
|
76
84
|
|
77
85
|
Rails/AssertNot:
|
78
86
|
Description: 'Use `assert_not` instead of `assert !`.'
|
@@ -32,6 +32,7 @@ module RuboCop
|
|
32
32
|
def on_send(node)
|
33
33
|
return unless node.method?(:validates)
|
34
34
|
return unless uniqueness_part(node)
|
35
|
+
return if condition_part?(node)
|
35
36
|
return unless schema
|
36
37
|
return if with_index?(node)
|
37
38
|
|
@@ -50,8 +51,21 @@ module RuboCop
|
|
50
51
|
names = column_names(node)
|
51
52
|
return true unless names
|
52
53
|
|
53
|
-
|
54
|
-
|
54
|
+
# Compatibility for Rails 4.2.
|
55
|
+
add_indicies = schema.add_indicies_by(table_name: table_name(klass))
|
56
|
+
|
57
|
+
(table.indices + add_indicies).any? do |index|
|
58
|
+
index.unique &&
|
59
|
+
(index.columns.to_set == names ||
|
60
|
+
include_column_names_in_expression_index?(index, names))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def include_column_names_in_expression_index?(index, column_names)
|
65
|
+
return false unless (expression_index = index.expression)
|
66
|
+
|
67
|
+
column_names.all? do |column_name|
|
68
|
+
expression_index.include?(column_name)
|
55
69
|
end
|
56
70
|
end
|
57
71
|
|
@@ -113,6 +127,18 @@ module RuboCop
|
|
113
127
|
end
|
114
128
|
end
|
115
129
|
|
130
|
+
def condition_part?(node)
|
131
|
+
pairs = node.arguments.last
|
132
|
+
return unless pairs.hash_type?
|
133
|
+
|
134
|
+
pairs.each_pair.any? do |pair|
|
135
|
+
key = pair.key
|
136
|
+
next unless key.sym_type?
|
137
|
+
|
138
|
+
key.value == :if || key.value == :unless
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
116
142
|
def array_node_to_array(node)
|
117
143
|
node.values.map do |elm|
|
118
144
|
case elm.type
|
@@ -5,10 +5,12 @@ module RuboCop
|
|
5
5
|
module SchemaLoader
|
6
6
|
# Represent db/schema.rb
|
7
7
|
class Schema
|
8
|
-
attr_reader :tables
|
8
|
+
attr_reader :tables, :add_indicies
|
9
9
|
|
10
10
|
def initialize(ast)
|
11
11
|
@tables = []
|
12
|
+
@add_indicies = []
|
13
|
+
|
12
14
|
build!(ast)
|
13
15
|
end
|
14
16
|
|
@@ -18,6 +20,12 @@ module RuboCop
|
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
23
|
+
def add_indicies_by(table_name:)
|
24
|
+
add_indicies.select do |add_index|
|
25
|
+
add_index.table_name == table_name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
21
29
|
private
|
22
30
|
|
23
31
|
def build!(ast)
|
@@ -26,6 +34,11 @@ module RuboCop
|
|
26
34
|
each_table(ast) do |table_def|
|
27
35
|
@tables << Table.new(table_def)
|
28
36
|
end
|
37
|
+
|
38
|
+
# Compatibility for Rails 4.2.
|
39
|
+
each_add_index(ast) do |add_index_def|
|
40
|
+
@add_indicies << AddIndex.new(add_index_def)
|
41
|
+
end
|
29
42
|
end
|
30
43
|
|
31
44
|
def each_table(ast)
|
@@ -40,9 +53,17 @@ module RuboCop
|
|
40
53
|
yield ast.body
|
41
54
|
end
|
42
55
|
end
|
56
|
+
|
57
|
+
def each_add_index(ast)
|
58
|
+
ast.body.children.each do |node|
|
59
|
+
next if !node&.send_type? || !node.method?(:add_index)
|
60
|
+
|
61
|
+
yield(node)
|
62
|
+
end
|
63
|
+
end
|
43
64
|
end
|
44
65
|
|
45
|
-
#
|
66
|
+
# Represent a table
|
46
67
|
class Table
|
47
68
|
attr_reader :name, :columns, :indices
|
48
69
|
|
@@ -60,7 +81,7 @@ module RuboCop
|
|
60
81
|
|
61
82
|
def build_columns(node)
|
62
83
|
each_content(node).map do |child|
|
63
|
-
next unless child
|
84
|
+
next unless child&.send_type?
|
64
85
|
next if child.method?(:index)
|
65
86
|
|
66
87
|
Column.new(child)
|
@@ -69,7 +90,7 @@ module RuboCop
|
|
69
90
|
|
70
91
|
def build_indices(node)
|
71
92
|
each_content(node).map do |child|
|
72
|
-
next unless child
|
93
|
+
next unless child&.send_type?
|
73
94
|
next unless child.method?(:index)
|
74
95
|
|
75
96
|
Index.new(child)
|
@@ -79,7 +100,7 @@ module RuboCop
|
|
79
100
|
def each_content(node)
|
80
101
|
return enum_for(__method__, node) unless block_given?
|
81
102
|
|
82
|
-
case node.body
|
103
|
+
case node.body&.type
|
83
104
|
when :begin
|
84
105
|
node.body.children.each do |child|
|
85
106
|
yield(child)
|
@@ -90,7 +111,7 @@ module RuboCop
|
|
90
111
|
end
|
91
112
|
end
|
92
113
|
|
93
|
-
#
|
114
|
+
# Represent a column
|
94
115
|
class Column
|
95
116
|
attr_reader :name, :type, :not_null
|
96
117
|
|
@@ -116,13 +137,12 @@ module RuboCop
|
|
116
137
|
end
|
117
138
|
end
|
118
139
|
|
119
|
-
#
|
140
|
+
# Represent an index
|
120
141
|
class Index
|
121
142
|
attr_reader :name, :columns, :expression, :unique
|
122
143
|
|
123
144
|
def initialize(node)
|
124
|
-
node.first_argument
|
125
|
-
@columns, @expression = build_columns_or_expr(node)
|
145
|
+
@columns, @expression = build_columns_or_expr(node.first_argument)
|
126
146
|
@unique = nil
|
127
147
|
|
128
148
|
analyze_keywords!(node)
|
@@ -130,12 +150,11 @@ module RuboCop
|
|
130
150
|
|
131
151
|
private
|
132
152
|
|
133
|
-
def build_columns_or_expr(
|
134
|
-
|
135
|
-
|
136
|
-
[arg.values.map(&:value), nil]
|
153
|
+
def build_columns_or_expr(columns)
|
154
|
+
if columns.array_type?
|
155
|
+
[columns.values.map(&:value), nil]
|
137
156
|
else
|
138
|
-
[[],
|
157
|
+
[[], columns.value]
|
139
158
|
end
|
140
159
|
end
|
141
160
|
|
@@ -153,6 +172,19 @@ module RuboCop
|
|
153
172
|
end
|
154
173
|
end
|
155
174
|
end
|
175
|
+
|
176
|
+
# Represent an `add_index`
|
177
|
+
class AddIndex < Index
|
178
|
+
attr_reader :table_name
|
179
|
+
|
180
|
+
def initialize(node)
|
181
|
+
@table_name = node.first_argument.value
|
182
|
+
@columns, @expression = build_columns_or_expr(node.arguments[1])
|
183
|
+
@unique = nil
|
184
|
+
|
185
|
+
analyze_keywords!(node)
|
186
|
+
end
|
187
|
+
end
|
156
188
|
end
|
157
189
|
end
|
158
190
|
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.5.
|
4
|
+
version: 2.5.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-
|
13
|
+
date: 2020-04-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|