rubocop-migration 0.4.2 → 0.5.0

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: 18f0c1b4fa8be61ca159b11acf5593b9343c4696156171acb9ba5774c422dfab
4
- data.tar.gz: 7fd0e0b48fc9d98d1ba4a307a1bb41fbd8068240710954c0bf69e3aedb0c5d9c
3
+ metadata.gz: 74f6229f8d3cbb9c31aee226d95ed698edec1fb5cde69090bb8efd57179d8cfe
4
+ data.tar.gz: 85ea516f3e408ae2bfabd0d7bcd7162bbad88281b5e6513d6da71b0c14c3b2a6
5
5
  SHA512:
6
- metadata.gz: '090d29334bcef597b4b9a13f63b9b79494ef0190f458814ea01abeb8d0d48a374b58a60619f06b85737d258ebda0065647f91e96cb98601e0dd53a4847e494ea'
7
- data.tar.gz: f7992c9b8468c881508f5aaa091187c75f432368ba0f2e7c4db014fe81f233524c1536b184c067efdab12933ad0a3e0278f5ff3425120d29dc713d8b1478e6ad
6
+ metadata.gz: 7af4ce63e220e72a147c272df33ec7d5096868742edb42377871d73eaecd7c0f0ec50505274310b27b5385f1e6bef57e85ec7528df76b88351b3bdde8997a544
7
+ data.tar.gz: 28cdf473b50695099a1d847a482fd5de54cdbeacd8778dbf54389027095478d460b3c70532115b4c2e2dbeba1137f5191946f66a6c2b20eb302310734906f64c
data/.rubocop.yml CHANGED
@@ -48,11 +48,11 @@ Sevencop/MethodDefinitionKeywordArgumentOrdered:
48
48
  Sevencop/MethodDefinitionOrdered:
49
49
  Enabled: true
50
50
 
51
- Sevencop/RequireOrdered:
52
- Enabled: true
53
-
54
51
  Style/Documentation:
55
52
  Enabled: false
56
53
 
57
54
  Style/MultilineBlockChain:
58
55
  Enabled: false
56
+
57
+ Style/RequireOrder:
58
+ Enabled: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-migration (0.4.2)
4
+ rubocop-migration (0.5.0)
5
5
  activesupport
6
6
  rubocop (>= 1.34)
7
7
  rubocop-rails
@@ -9,68 +9,92 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (7.0.6)
12
+ activesupport (7.1.3)
13
+ base64
14
+ bigdecimal
13
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ connection_pool (>= 2.2.5)
17
+ drb
14
18
  i18n (>= 1.6, < 2)
15
19
  minitest (>= 5.1)
20
+ mutex_m
16
21
  tzinfo (~> 2.0)
17
22
  ast (2.4.2)
18
- concurrent-ruby (1.2.2)
23
+ base64 (0.2.0)
24
+ bigdecimal (3.1.6)
25
+ concurrent-ruby (1.2.3)
26
+ connection_pool (2.4.1)
19
27
  diff-lcs (1.5.0)
28
+ drb (2.2.0)
29
+ ruby2_keywords
20
30
  i18n (1.14.1)
21
31
  concurrent-ruby (~> 1.0)
22
- json (2.6.2)
23
- minitest (5.18.1)
24
- parallel (1.22.1)
25
- parser (3.1.2.1)
32
+ json (2.7.1)
33
+ language_server-protocol (3.17.0.3)
34
+ minitest (5.21.2)
35
+ mutex_m (0.2.0)
36
+ parallel (1.24.0)
37
+ parser (3.3.0.5)
26
38
  ast (~> 2.4.1)
39
+ racc
40
+ racc (1.7.3)
27
41
  rack (3.0.8)
28
42
  rainbow (3.1.1)
29
- rake (13.0.6)
30
- regexp_parser (2.6.0)
31
- rexml (3.2.5)
32
- rspec (3.11.0)
33
- rspec-core (~> 3.11.0)
34
- rspec-expectations (~> 3.11.0)
35
- rspec-mocks (~> 3.11.0)
36
- rspec-core (3.11.0)
37
- rspec-support (~> 3.11.0)
38
- rspec-expectations (3.11.1)
43
+ rake (13.1.0)
44
+ regexp_parser (2.9.0)
45
+ rexml (3.2.6)
46
+ rspec (3.12.0)
47
+ rspec-core (~> 3.12.0)
48
+ rspec-expectations (~> 3.12.0)
49
+ rspec-mocks (~> 3.12.0)
50
+ rspec-core (3.12.2)
51
+ rspec-support (~> 3.12.0)
52
+ rspec-expectations (3.12.3)
39
53
  diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.11.0)
41
- rspec-mocks (3.11.1)
54
+ rspec-support (~> 3.12.0)
55
+ rspec-mocks (3.12.6)
42
56
  diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.11.0)
44
- rspec-support (3.11.1)
45
- rubocop (1.36.0)
57
+ rspec-support (~> 3.12.0)
58
+ rspec-support (3.12.1)
59
+ rubocop (1.60.2)
46
60
  json (~> 2.3)
61
+ language_server-protocol (>= 3.17.0)
47
62
  parallel (~> 1.10)
48
- parser (>= 3.1.2.1)
63
+ parser (>= 3.3.0.2)
49
64
  rainbow (>= 2.2.2, < 4.0)
50
65
  regexp_parser (>= 1.8, < 3.0)
51
66
  rexml (>= 3.2.5, < 4.0)
52
- rubocop-ast (>= 1.20.1, < 2.0)
67
+ rubocop-ast (>= 1.30.0, < 2.0)
53
68
  ruby-progressbar (~> 1.7)
54
- unicode-display_width (>= 1.4.0, < 3.0)
55
- rubocop-ast (1.21.0)
56
- parser (>= 3.1.1.0)
57
- rubocop-performance (1.15.0)
58
- rubocop (>= 1.7.0, < 2.0)
59
- rubocop-ast (>= 0.4.0)
60
- rubocop-rails (2.20.2)
69
+ unicode-display_width (>= 2.4.0, < 3.0)
70
+ rubocop-ast (1.30.0)
71
+ parser (>= 3.2.1.0)
72
+ rubocop-capybara (2.20.0)
73
+ rubocop (~> 1.41)
74
+ rubocop-factory_bot (2.25.1)
75
+ rubocop (~> 1.41)
76
+ rubocop-performance (1.20.2)
77
+ rubocop (>= 1.48.1, < 2.0)
78
+ rubocop-ast (>= 1.30.0, < 2.0)
79
+ rubocop-rails (2.23.1)
61
80
  activesupport (>= 4.2.0)
62
81
  rack (>= 1.1)
63
82
  rubocop (>= 1.33.0, < 2.0)
83
+ rubocop-ast (>= 1.30.0, < 2.0)
64
84
  rubocop-rake (0.6.0)
65
85
  rubocop (~> 1.0)
66
- rubocop-rspec (2.13.2)
67
- rubocop (~> 1.33)
68
- ruby-progressbar (1.11.0)
69
- sevencop (0.21.0)
86
+ rubocop-rspec (2.26.1)
87
+ rubocop (~> 1.40)
88
+ rubocop-capybara (~> 2.17)
89
+ rubocop-factory_bot (~> 2.22)
90
+ ruby-progressbar (1.13.0)
91
+ ruby2_keywords (0.0.5)
92
+ sevencop (0.35.1)
93
+ activesupport
70
94
  rubocop
71
95
  tzinfo (2.0.6)
72
96
  concurrent-ruby (~> 1.0)
73
- unicode-display_width (2.3.0)
97
+ unicode-display_width (2.5.0)
74
98
 
75
99
  PLATFORMS
76
100
  x86_64-linux
@@ -209,7 +209,7 @@ module RuboCop
209
209
  corrector.remove(
210
210
  range_with_surrounding_comma(
211
211
  range_with_surrounding_space(
212
- node.location.expression,
212
+ node.source_range,
213
213
  side: :left
214
214
  ),
215
215
  :left
@@ -144,7 +144,7 @@ module RuboCop
144
144
  corrector.remove(
145
145
  range_with_surrounding_comma(
146
146
  range_with_surrounding_space(
147
- option_foreign_key_true_node_from_add_reference(node).location.expression,
147
+ option_foreign_key_true_node_from_add_reference(node).source_range,
148
148
  side: :left
149
149
  ),
150
150
  :left
@@ -108,7 +108,7 @@ module RuboCop
108
108
  indexed_columns_node = indexed_columns_node_from(node)
109
109
  case indexed_columns_node&.type
110
110
  when :array
111
- indexed_columns_node.children.map(&:value).map(&:to_s)
111
+ indexed_columns_node.children.map { |child| child.value.to_s }
112
112
  when :str, :sym
113
113
  [indexed_columns_node.value.to_s]
114
114
  end
@@ -121,7 +121,7 @@ module RuboCop
121
121
  when :add_index
122
122
  node.arguments[1]
123
123
  when :index
124
- node.arguments[0]
124
+ node.first_argument
125
125
  end
126
126
  end
127
127
 
@@ -26,7 +26,16 @@ module RuboCop
26
26
  # disable_ddl_transaction!
27
27
  #
28
28
  # def up
29
- # User.within_in_batches do |relation|
29
+ # User.in_batches.update_all(some_column: 'some value')
30
+ # end
31
+ # end
32
+ #
33
+ # # good
34
+ # class BackfillSomeColumnToUsers < ActiveRecord::Migration[7.0]
35
+ # disable_ddl_transaction!
36
+ #
37
+ # def up
38
+ # User.in_batches do |relation|
30
39
  # relation.update_all(some_column: 'some value')
31
40
  # end
32
41
  # end
@@ -62,32 +71,34 @@ module RuboCop
62
71
  corrector,
63
72
  node
64
73
  )
65
- range = node.location.selector.with(
66
- end_pos: node.location.expression.end_pos
67
- )
68
- corrector.replace(
69
- range,
70
- <<~TEXT.chomp
71
- in_batches do |relation|
72
- relation.#{range.source}
73
- end
74
- TEXT
75
- )
74
+ corrector.insert_before(node.location.selector, 'in_batches.')
76
75
  end
77
76
 
78
- # @param node [RuboCop::AST::Node]
77
+ # @param node [RuboCop::AST::SendNode]
79
78
  # @return [Boolean]
80
- def within_in_batches?(node)
79
+ def in_batches?(node)
80
+ in_block_batches?(node) || in_inline_batches?(node)
81
+ end
82
+
83
+ # @param node [RuboCop::AST::SendNode]
84
+ # @return [Boolean]
85
+ def in_block_batches?(node)
81
86
  node.each_ancestor(:block).any? do |ancestor|
82
87
  ancestor.method?(:in_batches)
83
88
  end
84
89
  end
85
90
 
91
+ # @param node [RuboCop::AST::SendNode]
92
+ # @return [Boolean]
93
+ def in_inline_batches?(node)
94
+ node.receiver.is_a?(::RuboCop::AST::SendNode) &&
95
+ node.receiver.method?(:in_batches)
96
+ end
97
+
86
98
  # @param node [RuboCop::AST::SendNode]
87
99
  # @return [Boolean]
88
100
  def wrong?(node)
89
- batch_processing?(node) &&
90
- !within_in_batches?(node)
101
+ batch_processing?(node) && !in_batches?(node)
91
102
  end
92
103
  end
93
104
  end
@@ -102,7 +102,7 @@ module RuboCop
102
102
  )
103
103
  corrector.replace(
104
104
  node.location.selector.with(
105
- end_pos: node.location.expression.end_pos
105
+ end_pos: node.source_range.end_pos
106
106
  ),
107
107
  format_check_constraint(
108
108
  column_name: find_column_name_from_change_null(node),
@@ -141,19 +141,19 @@ module RuboCop
141
141
  # @param node [RuboCop::AST::SendNode]
142
142
  # @return [String]
143
143
  def find_column_name_from_change_null(node)
144
- node.arguments[0].value.to_s
144
+ node.first_argument.value.to_s
145
145
  end
146
146
 
147
147
  # @parm node [RuboCop::AST::SendNode]
148
148
  # @return [String]
149
149
  def find_table_name_from_change_column_null(node)
150
- node.arguments[0].value.to_s
150
+ node.first_argument.value.to_s
151
151
  end
152
152
 
153
153
  # @param node [RuboCop::AST::SendNode]
154
154
  # @return [String]
155
155
  def find_table_name_from_change_null(node)
156
- find_ancestor_change_table(node).send_node.arguments[0].value.to_s
156
+ find_ancestor_change_table(node).send_node.first_argument.value.to_s
157
157
  end
158
158
 
159
159
  # @param column_name [String]
@@ -76,7 +76,7 @@ module RuboCop
76
76
  corrector.remove(
77
77
  range_with_surrounding_comma(
78
78
  range_with_surrounding_space(
79
- node.location.expression,
79
+ node.source_range,
80
80
  side: :left
81
81
  ),
82
82
  :left
@@ -111,8 +111,8 @@ module RuboCop
111
111
  when :send
112
112
  node.location.selector
113
113
  when :sym
114
- node.location.expression.with(
115
- begin_pos: node.location.expression.begin_pos + 1
114
+ node.source_range.with(
115
+ begin_pos: node.source_range.begin_pos + 1
116
116
  )
117
117
  end
118
118
  end
@@ -135,7 +135,7 @@ module RuboCop
135
135
  # @param node [RuboCop::AST::SendNode]
136
136
  # @return [String, nil]
137
137
  def find_table_name_from(node)
138
- table_name_node = node.arguments[0]
138
+ table_name_node = node.first_argument
139
139
  table_name_node.value&.to_s if table_name_node.respond_to?(:value)
140
140
  end
141
141
 
@@ -165,7 +165,7 @@ module RuboCop
165
165
  when :rename_column
166
166
  [node.arguments[2]]
167
167
  when *COLUMN_TYPE_METHOD_NAMES
168
- [node.arguments[0]]
168
+ [node.first_argument]
169
169
  else
170
170
  []
171
171
  end
@@ -203,7 +203,7 @@ module RuboCop
203
203
  when :create_join_table
204
204
  [table_name_option_from(node)].compact
205
205
  when :create_table
206
- [node.arguments[0]]
206
+ [node.first_argument]
207
207
  when :rename_table
208
208
  [node.arguments[1]]
209
209
  else
@@ -7,7 +7,7 @@ require_relative 'config_loader'
7
7
  RuboCop::ConfigLoader.instance_variable_set(
8
8
  :@default_configuration,
9
9
  RuboCop::Migration::ConfigLoader.call(
10
- path: ::File.expand_path(
10
+ path: File.expand_path(
11
11
  '../../../config/default.yml',
12
12
  __dir__
13
13
  )
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubocop
4
4
  module Migration
5
- VERSION = '0.4.2'
5
+ VERSION = '0.5.0'
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.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-14 00:00:00.000000000 Z
11
+ date: 2024-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport