rubocop-migration 0.4.0 → 0.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa5e7fda6eeffbf26f8c9bd1a4433a689416e0a2098ce9193f93c72564b8b4f2
|
4
|
+
data.tar.gz: 4907939dbd5ba1a39cf76d838824bfa8574fe527b6a8985588bd7897eb5a3a1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6885d3a799806f1a3699cf892eb2a9855b66b8d29f9578fe9a0d8f98e84ab0526683710a35b22dbb1601cc6b52c015421aa163c6f671a4366ceb3d5a582dedba
|
7
|
+
data.tar.gz: 8838e0d3758231c59a844e26d4b7795dd7abf74743a16f25075f9804f3de51248d2c6893614ecfdee8cdf075af46430b3723b3e10f62a57a39f42ef31b326489
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rubocop-migration (0.4.
|
4
|
+
rubocop-migration (0.4.1)
|
5
5
|
activesupport
|
6
6
|
rubocop (>= 1.34)
|
7
7
|
rubocop-rails
|
@@ -9,22 +9,22 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (7.0.
|
12
|
+
activesupport (7.0.5)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 1.6, < 2)
|
15
15
|
minitest (>= 5.1)
|
16
16
|
tzinfo (~> 2.0)
|
17
17
|
ast (2.4.2)
|
18
|
-
concurrent-ruby (1.
|
18
|
+
concurrent-ruby (1.2.2)
|
19
19
|
diff-lcs (1.5.0)
|
20
|
-
i18n (1.
|
20
|
+
i18n (1.14.1)
|
21
21
|
concurrent-ruby (~> 1.0)
|
22
22
|
json (2.6.2)
|
23
|
-
minitest (5.
|
23
|
+
minitest (5.18.0)
|
24
24
|
parallel (1.22.1)
|
25
25
|
parser (3.1.2.1)
|
26
26
|
ast (~> 2.4.1)
|
27
|
-
rack (3.0.
|
27
|
+
rack (3.0.7)
|
28
28
|
rainbow (3.1.1)
|
29
29
|
rake (13.0.6)
|
30
30
|
regexp_parser (2.6.0)
|
@@ -57,7 +57,7 @@ GEM
|
|
57
57
|
rubocop-performance (1.15.0)
|
58
58
|
rubocop (>= 1.7.0, < 2.0)
|
59
59
|
rubocop-ast (>= 0.4.0)
|
60
|
-
rubocop-rails (2.
|
60
|
+
rubocop-rails (2.19.1)
|
61
61
|
activesupport (>= 4.2.0)
|
62
62
|
rack (>= 1.1)
|
63
63
|
rubocop (>= 1.33.0, < 2.0)
|
@@ -68,7 +68,7 @@ GEM
|
|
68
68
|
ruby-progressbar (1.11.0)
|
69
69
|
sevencop (0.21.0)
|
70
70
|
rubocop
|
71
|
-
tzinfo (2.0.
|
71
|
+
tzinfo (2.0.6)
|
72
72
|
concurrent-ruby (~> 1.0)
|
73
73
|
unicode-display_width (2.3.0)
|
74
74
|
|
data/README.md
CHANGED
@@ -30,9 +30,12 @@ module RuboCop
|
|
30
30
|
extend AutoCorrector
|
31
31
|
|
32
32
|
include ::RuboCop::Migration::CopConcerns::DisableDdlTransaction
|
33
|
+
include RangeHelp
|
33
34
|
|
34
35
|
MSG = 'Use `algorithm: :concurrently` on adding indexes to existing tables in PostgreSQL.'
|
35
36
|
|
37
|
+
MESSAGE_FOR_DUPLICATED_DISABLE_DDL_TRANSACTION = 'Remove duplicated `disable_ddl_transaction!`.'
|
38
|
+
|
36
39
|
RESTRICT_ON_SEND = %i[
|
37
40
|
add_index
|
38
41
|
index
|
@@ -41,10 +44,21 @@ module RuboCop
|
|
41
44
|
# @param node [RuboCop::AST::SendNode]
|
42
45
|
# @return [void]
|
43
46
|
def on_send(node)
|
44
|
-
|
47
|
+
if add_index_without_concurrency?(node)
|
48
|
+
add_offense(node) do |corrector|
|
49
|
+
autocorrect(corrector, node)
|
50
|
+
end
|
51
|
+
end
|
45
52
|
|
46
|
-
|
47
|
-
|
53
|
+
duplicated_disable_ddl_transactions_from(node).each do |disable_ddl_transactions_node|
|
54
|
+
add_offense(node, message: MESSAGE_FOR_DUPLICATED_DISABLE_DDL_TRANSACTION) do |corrector|
|
55
|
+
corrector.remove(
|
56
|
+
range_with_surrounding_space(
|
57
|
+
disable_ddl_transactions_node.source_range,
|
58
|
+
side: :left
|
59
|
+
)
|
60
|
+
)
|
61
|
+
end
|
48
62
|
end
|
49
63
|
end
|
50
64
|
|
@@ -116,6 +130,17 @@ module RuboCop
|
|
116
130
|
)
|
117
131
|
PATTERN
|
118
132
|
|
133
|
+
# @param node [RuboCop::AST::SendNode]
|
134
|
+
# @return [Boolean]
|
135
|
+
def add_index_without_concurrency?(node)
|
136
|
+
case node.method_name
|
137
|
+
when :add_index
|
138
|
+
add_index?(node) && !add_index_concurrently?(node)
|
139
|
+
when :index
|
140
|
+
index?(node) && in_change_table?(node) && !index_concurrently?(node)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
119
144
|
# @param corrector [RuboCop::Cop::Corrector]
|
120
145
|
# @param node [RuboCop::AST::SendNode]
|
121
146
|
# @return [void]
|
@@ -128,14 +153,9 @@ module RuboCop
|
|
128
153
|
end
|
129
154
|
|
130
155
|
# @param node [RuboCop::AST::SendNode]
|
131
|
-
# @return [
|
132
|
-
def
|
133
|
-
|
134
|
-
when :add_index
|
135
|
-
add_index?(node) && !add_index_concurrently?(node)
|
136
|
-
when :index
|
137
|
-
index?(node) && in_change_table?(node) && !index_concurrently?(node)
|
138
|
-
end
|
156
|
+
# @return [Array<RuboCop::AST::SendNode>]
|
157
|
+
def duplicated_disable_ddl_transactions_from(node)
|
158
|
+
disable_ddl_transactions_from(node)[1..] || []
|
139
159
|
end
|
140
160
|
|
141
161
|
# @param node [RuboCop::AST::SendNode]
|
@@ -24,6 +24,15 @@ module RuboCop
|
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
|
+
# @param node [RuboCop::AST::SendNode]
|
28
|
+
# @return [Array<RuboCop::AST::SendNode>]
|
29
|
+
def disable_ddl_transactions_from(node)
|
30
|
+
node.each_ancestor(:def).first&.left_siblings&.select do |sibling|
|
31
|
+
sibling.is_a?(::RuboCop::AST::SendNode) &&
|
32
|
+
disable_ddl_transaction?(sibling)
|
33
|
+
end || []
|
34
|
+
end
|
35
|
+
|
27
36
|
# @param corrector [RuboCop::Cop::Corrector]
|
28
37
|
# @param node [RuboCop::AST::SendNode]
|
29
38
|
# @return [void]
|
@@ -40,10 +49,7 @@ module RuboCop
|
|
40
49
|
# @param node [RuboCop::AST::SendNode]
|
41
50
|
# @return [Boolean]
|
42
51
|
def within_disable_ddl_transaction?(node)
|
43
|
-
node
|
44
|
-
sibling.is_a?(::RuboCop::AST::SendNode) &&
|
45
|
-
disable_ddl_transaction?(sibling)
|
46
|
-
end
|
52
|
+
!disable_ddl_transactions_from(node).empty?
|
47
53
|
end
|
48
54
|
end
|
49
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-migration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
|
-
rubygems_version: 3.3.
|
120
|
+
rubygems_version: 3.3.26
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: RuboCop extension focused on ActiveRecord migration.
|