rubocop-migration 0.4.0 → 0.4.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: 819776e7d688a0d112d1ad7ecc2994125de7bfa7e4b8fe27105f21d2a8061565
4
- data.tar.gz: fa2c6bfce21e4dd4ad206e6fb049162ee25b016bc2be01c22782d3dc0871e255
3
+ metadata.gz: fa5e7fda6eeffbf26f8c9bd1a4433a689416e0a2098ce9193f93c72564b8b4f2
4
+ data.tar.gz: 4907939dbd5ba1a39cf76d838824bfa8574fe527b6a8985588bd7897eb5a3a1c
5
5
  SHA512:
6
- metadata.gz: b9fecf517eab16cd9f6c16e302d7a392c0b263a75c164b53a99337b017d4416894fde4eac40874ca53e4fa61c77783f4ef5cbde64007b5388dc6ceefd79d644d
7
- data.tar.gz: da06bac2b33c7018964708c0aec62808262e14478b09ff2af0303f6ce00034a57d2331a64ed9fd973ec34012525ec7051b362c71843cbf23f27e17d6f30d5248
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.0)
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.4)
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.1.10)
18
+ concurrent-ruby (1.2.2)
19
19
  diff-lcs (1.5.0)
20
- i18n (1.12.0)
20
+ i18n (1.14.1)
21
21
  concurrent-ruby (~> 1.0)
22
22
  json (2.6.2)
23
- minitest (5.16.3)
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.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.17.0)
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.5)
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
@@ -21,7 +21,7 @@ require:
21
21
  - rubocop-migration
22
22
 
23
23
  Migration/AddCheckConstraint:
24
- Enabled: false
24
+ Enabled: true
25
25
  ```
26
26
 
27
27
  Note that all cops are `Enabled: false` by default.
@@ -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
- return unless bad?(node)
47
+ if add_index_without_concurrency?(node)
48
+ add_offense(node) do |corrector|
49
+ autocorrect(corrector, node)
50
+ end
51
+ end
45
52
 
46
- add_offense(node) do |corrector|
47
- autocorrect(corrector, node)
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 [Boolean]
132
- def bad?(node)
133
- case node.method_name
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.each_ancestor(:def).first&.left_siblings&.any? do |sibling|
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubocop
4
4
  module Migration
5
- VERSION = '0.4.0'
5
+ VERSION = '0.4.1'
6
6
  end
7
7
  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.0
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: 2022-10-22 00:00:00.000000000 Z
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.7
120
+ rubygems_version: 3.3.26
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: RuboCop extension focused on ActiveRecord migration.