rubocop-powerhome 0.5.6 → 0.6.0
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/.rubocop.yml +0 -13
- data/CHANGELOG.md +6 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +12 -14
- data/gemfiles/rails_6_1.gemfile +2 -2
- data/gemfiles/rails_6_1.gemfile.lock +7 -7
- data/gemfiles/rails_7_0.gemfile +2 -2
- data/gemfiles/rails_7_0.gemfile.lock +7 -7
- data/gemfiles/rails_7_1.gemfile +2 -2
- data/gemfiles/rails_7_1.gemfile.lock +7 -7
- data/gemfiles/rails_7_2.gemfile +2 -2
- data/gemfiles/rails_7_2.gemfile.lock +7 -7
- data/lib/rubocop/cop/migration/acknowledge_ignored_column.rb +78 -0
- data/lib/rubocop/cop/migration/rename_column.rb +91 -0
- data/lib/rubocop/cop/migration/rename_table.rb +56 -0
- data/lib/rubocop/cop/migration_cops.rb +11 -0
- data/lib/rubocop/cop/style/no_helpers.rb +1 -1
- data/lib/rubocop/powerhome/version.rb +1 -1
- data/lib/rubocop/powerhome.rb +1 -1
- data/lib/rubocop-powerhome.rb +1 -0
- data/rubocop-powerhome.gemspec +52 -0
- metadata +10 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f1e6fcf08b38131fad2b3c123f3f76f96493f021c42109266704794dcc3f84b2
|
|
4
|
+
data.tar.gz: 453d0404cb7d79eb7db3fc6565d516f359a114aa3df8598f19d5e045b5a5e9b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '008635f380d6567d4215ee1884054e720362b50e8fad0d9a9357cc8615383538ca59d6381219dfcaace7e75b288bdb204a25f11f9e957e528bb0bd0ac6ecbaec'
|
|
7
|
+
data.tar.gz: 6a04ff2417848f4e3d64ba9b6bc8951f6ee0bc9f284d804e4c233e01ab57a71ed469727196a13b4561d395b44cf4f61cf3f6c017b610823e92e6b1a9047ed90f
|
data/.rubocop.yml
CHANGED
|
@@ -5,18 +5,5 @@ Naming/FileName:
|
|
|
5
5
|
Exclude:
|
|
6
6
|
- lib/rubocop-powerhome.rb
|
|
7
7
|
|
|
8
|
-
Metrics/BlockLength:
|
|
9
|
-
Exclude:
|
|
10
|
-
- 'spec/**/*'
|
|
11
|
-
- 'rubocop-powerhome.gemspec'
|
|
12
|
-
|
|
13
|
-
Style/FrozenStringLiteralComment:
|
|
14
|
-
Exclude:
|
|
15
|
-
- 'gemfiles/*'
|
|
16
|
-
|
|
17
|
-
Bundler/OrderedGems:
|
|
18
|
-
Exclude:
|
|
19
|
-
- 'gemfiles/*'
|
|
20
|
-
|
|
21
8
|
Rails:
|
|
22
9
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.6.0] - 2026-01-05
|
|
4
|
+
|
|
5
|
+
- Bump rubocop version with release of new cops
|
|
6
|
+
- Adds Migration/AcknowledgeIgnoredColumn cop [#382](https://github.com/powerhome/power-tools/pull/382)
|
|
7
|
+
- Extends Migration/RenameColumn to cover uses in a change_table [#381](https://github.com/powerhome/power-tools/pull/381)
|
|
8
|
+
- Adds Migration/RenameColumn and Migration/RenameTable cops [#380](https://github.com/powerhome/power-tools/pull/380)
|
|
3
9
|
- Standardize all libs to support ruby 3.0, ruby 3.3 x rails 6.1 through rails 7.2 [#359](https://github.com/powerhome/power-tools/pull/359)
|
|
4
10
|
|
|
5
11
|
## [0.5.6] - 2025-09-09
|
data/Gemfile
CHANGED
|
@@ -5,8 +5,8 @@ source "https://rubygems.org"
|
|
|
5
5
|
# Specify your gem's dependencies in rubocop-powerhome.gemspec
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
-
gem "erb", "<
|
|
8
|
+
gem "erb", "< 6"
|
|
9
9
|
gem "net-imap", "< 0.5.0"
|
|
10
|
-
gem "nokogiri", "< 1.18.
|
|
10
|
+
gem "nokogiri", "< 1.18.10"
|
|
11
11
|
gem "securerandom", "< 0.4.0"
|
|
12
12
|
gem "zeitwerk", "< 2.7.0"
|
data/Gemfile.lock
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
rubocop-powerhome (0.
|
|
5
|
-
rubocop (= 1.
|
|
4
|
+
rubocop-powerhome (0.6.0)
|
|
5
|
+
rubocop (= 1.82.1)
|
|
6
6
|
rubocop-performance
|
|
7
7
|
rubocop-rails
|
|
8
8
|
rubocop-rake
|
|
@@ -84,15 +84,13 @@ GEM
|
|
|
84
84
|
base64 (0.2.0)
|
|
85
85
|
builder (3.3.0)
|
|
86
86
|
byebug (11.1.3)
|
|
87
|
-
cgi (0.5.0)
|
|
88
87
|
coderay (1.1.3)
|
|
89
88
|
concurrent-ruby (1.3.5)
|
|
90
89
|
crass (1.0.6)
|
|
91
90
|
csv (3.3.2)
|
|
92
91
|
date (3.4.1)
|
|
93
92
|
diff-lcs (1.5.1)
|
|
94
|
-
erb (
|
|
95
|
-
cgi (>= 0.3.3)
|
|
93
|
+
erb (5.0.2)
|
|
96
94
|
erubi (1.13.1)
|
|
97
95
|
globalid (1.2.1)
|
|
98
96
|
activesupport (>= 6.1)
|
|
@@ -122,7 +120,7 @@ GEM
|
|
|
122
120
|
mini_mime (1.1.5)
|
|
123
121
|
mini_portile2 (2.8.9)
|
|
124
122
|
minitest (5.25.4)
|
|
125
|
-
net-imap (0.4.
|
|
123
|
+
net-imap (0.4.22)
|
|
126
124
|
date
|
|
127
125
|
net-protocol
|
|
128
126
|
net-pop (0.1.2)
|
|
@@ -132,12 +130,12 @@ GEM
|
|
|
132
130
|
net-smtp (0.5.0)
|
|
133
131
|
net-protocol
|
|
134
132
|
nio4r (2.7.4)
|
|
135
|
-
nokogiri (1.
|
|
133
|
+
nokogiri (1.18.9)
|
|
136
134
|
mini_portile2 (~> 2.8.2)
|
|
137
135
|
racc (~> 1.4)
|
|
138
|
-
nokogiri (1.
|
|
136
|
+
nokogiri (1.18.9-arm64-darwin)
|
|
139
137
|
racc (~> 1.4)
|
|
140
|
-
nokogiri (1.
|
|
138
|
+
nokogiri (1.18.9-x86_64-linux-gnu)
|
|
141
139
|
racc (~> 1.4)
|
|
142
140
|
parallel (1.26.3)
|
|
143
141
|
parser (3.3.9.0)
|
|
@@ -199,7 +197,7 @@ GEM
|
|
|
199
197
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
200
198
|
rspec-support (~> 3.13.0)
|
|
201
199
|
rspec-support (3.13.2)
|
|
202
|
-
rubocop (1.
|
|
200
|
+
rubocop (1.82.1)
|
|
203
201
|
json (~> 2.3)
|
|
204
202
|
language_server-protocol (~> 3.17.0.2)
|
|
205
203
|
lint_roller (~> 1.1.0)
|
|
@@ -207,10 +205,10 @@ GEM
|
|
|
207
205
|
parser (>= 3.3.0.2)
|
|
208
206
|
rainbow (>= 2.2.2, < 4.0)
|
|
209
207
|
regexp_parser (>= 2.9.3, < 3.0)
|
|
210
|
-
rubocop-ast (>= 1.
|
|
208
|
+
rubocop-ast (>= 1.48.0, < 2.0)
|
|
211
209
|
ruby-progressbar (~> 1.7)
|
|
212
210
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
213
|
-
rubocop-ast (1.
|
|
211
|
+
rubocop-ast (1.48.0)
|
|
214
212
|
parser (>= 3.3.7.2)
|
|
215
213
|
prism (~> 1.4)
|
|
216
214
|
rubocop-performance (1.23.1)
|
|
@@ -250,10 +248,10 @@ PLATFORMS
|
|
|
250
248
|
|
|
251
249
|
DEPENDENCIES
|
|
252
250
|
appraisal (~> 2.5.0)
|
|
253
|
-
erb (<
|
|
251
|
+
erb (< 6)
|
|
254
252
|
license_finder (~> 7.0)
|
|
255
253
|
net-imap (< 0.5.0)
|
|
256
|
-
nokogiri (< 1.18.
|
|
254
|
+
nokogiri (< 1.18.10)
|
|
257
255
|
pry (>= 0.14.2)
|
|
258
256
|
pry-byebug (= 3.10.1)
|
|
259
257
|
rails (>= 6.0.6.1, < 8)
|
data/gemfiles/rails_6_1.gemfile
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ..
|
|
3
3
|
specs:
|
|
4
|
-
rubocop-powerhome (0.
|
|
5
|
-
rubocop (= 1.
|
|
4
|
+
rubocop-powerhome (0.6.0)
|
|
5
|
+
rubocop (= 1.82.1)
|
|
6
6
|
rubocop-performance
|
|
7
7
|
rubocop-rails
|
|
8
8
|
rubocop-rake
|
|
@@ -194,7 +194,7 @@ GEM
|
|
|
194
194
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
195
195
|
rspec-support (~> 3.13.0)
|
|
196
196
|
rspec-support (3.13.4)
|
|
197
|
-
rubocop (1.
|
|
197
|
+
rubocop (1.82.1)
|
|
198
198
|
json (~> 2.3)
|
|
199
199
|
language_server-protocol (~> 3.17.0.2)
|
|
200
200
|
lint_roller (~> 1.1.0)
|
|
@@ -202,10 +202,10 @@ GEM
|
|
|
202
202
|
parser (>= 3.3.0.2)
|
|
203
203
|
rainbow (>= 2.2.2, < 4.0)
|
|
204
204
|
regexp_parser (>= 2.9.3, < 3.0)
|
|
205
|
-
rubocop-ast (>= 1.
|
|
205
|
+
rubocop-ast (>= 1.48.0, < 2.0)
|
|
206
206
|
ruby-progressbar (~> 1.7)
|
|
207
207
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
208
|
-
rubocop-ast (1.
|
|
208
|
+
rubocop-ast (1.48.0)
|
|
209
209
|
parser (>= 3.3.7.2)
|
|
210
210
|
prism (~> 1.4)
|
|
211
211
|
rubocop-performance (1.24.0)
|
|
@@ -259,10 +259,10 @@ PLATFORMS
|
|
|
259
259
|
|
|
260
260
|
DEPENDENCIES
|
|
261
261
|
appraisal (~> 2.5.0)
|
|
262
|
-
erb (<
|
|
262
|
+
erb (< 6)
|
|
263
263
|
license_finder (~> 7.0)
|
|
264
264
|
net-imap (< 0.5.0)
|
|
265
|
-
nokogiri (< 1.18.
|
|
265
|
+
nokogiri (< 1.18.10)
|
|
266
266
|
pry (>= 0.14.2)
|
|
267
267
|
pry-byebug (= 3.10.1)
|
|
268
268
|
rails (= 6.1.7.7)
|
data/gemfiles/rails_7_0.gemfile
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ..
|
|
3
3
|
specs:
|
|
4
|
-
rubocop-powerhome (0.
|
|
5
|
-
rubocop (= 1.
|
|
4
|
+
rubocop-powerhome (0.6.0)
|
|
5
|
+
rubocop (= 1.82.1)
|
|
6
6
|
rubocop-performance
|
|
7
7
|
rubocop-rails
|
|
8
8
|
rubocop-rake
|
|
@@ -199,7 +199,7 @@ GEM
|
|
|
199
199
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
200
200
|
rspec-support (~> 3.13.0)
|
|
201
201
|
rspec-support (3.13.4)
|
|
202
|
-
rubocop (1.
|
|
202
|
+
rubocop (1.82.1)
|
|
203
203
|
json (~> 2.3)
|
|
204
204
|
language_server-protocol (~> 3.17.0.2)
|
|
205
205
|
lint_roller (~> 1.1.0)
|
|
@@ -207,10 +207,10 @@ GEM
|
|
|
207
207
|
parser (>= 3.3.0.2)
|
|
208
208
|
rainbow (>= 2.2.2, < 4.0)
|
|
209
209
|
regexp_parser (>= 2.9.3, < 3.0)
|
|
210
|
-
rubocop-ast (>= 1.
|
|
210
|
+
rubocop-ast (>= 1.48.0, < 2.0)
|
|
211
211
|
ruby-progressbar (~> 1.7)
|
|
212
212
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
213
|
-
rubocop-ast (1.
|
|
213
|
+
rubocop-ast (1.48.0)
|
|
214
214
|
parser (>= 3.3.7.2)
|
|
215
215
|
prism (~> 1.4)
|
|
216
216
|
rubocop-performance (1.24.0)
|
|
@@ -256,10 +256,10 @@ PLATFORMS
|
|
|
256
256
|
|
|
257
257
|
DEPENDENCIES
|
|
258
258
|
appraisal (~> 2.5.0)
|
|
259
|
-
erb (<
|
|
259
|
+
erb (< 6)
|
|
260
260
|
license_finder (~> 7.0)
|
|
261
261
|
net-imap (< 0.5.0)
|
|
262
|
-
nokogiri (< 1.18.
|
|
262
|
+
nokogiri (< 1.18.10)
|
|
263
263
|
pry (>= 0.14.2)
|
|
264
264
|
pry-byebug (= 3.10.1)
|
|
265
265
|
rails (= 7.0.8.1)
|
data/gemfiles/rails_7_1.gemfile
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ..
|
|
3
3
|
specs:
|
|
4
|
-
rubocop-powerhome (0.
|
|
5
|
-
rubocop (= 1.
|
|
4
|
+
rubocop-powerhome (0.6.0)
|
|
5
|
+
rubocop (= 1.82.1)
|
|
6
6
|
rubocop-performance
|
|
7
7
|
rubocop-rails
|
|
8
8
|
rubocop-rake
|
|
@@ -241,7 +241,7 @@ GEM
|
|
|
241
241
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
242
242
|
rspec-support (~> 3.13.0)
|
|
243
243
|
rspec-support (3.13.4)
|
|
244
|
-
rubocop (1.
|
|
244
|
+
rubocop (1.82.1)
|
|
245
245
|
json (~> 2.3)
|
|
246
246
|
language_server-protocol (~> 3.17.0.2)
|
|
247
247
|
lint_roller (~> 1.1.0)
|
|
@@ -249,10 +249,10 @@ GEM
|
|
|
249
249
|
parser (>= 3.3.0.2)
|
|
250
250
|
rainbow (>= 2.2.2, < 4.0)
|
|
251
251
|
regexp_parser (>= 2.9.3, < 3.0)
|
|
252
|
-
rubocop-ast (>= 1.
|
|
252
|
+
rubocop-ast (>= 1.48.0, < 2.0)
|
|
253
253
|
ruby-progressbar (~> 1.7)
|
|
254
254
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
255
|
-
rubocop-ast (1.
|
|
255
|
+
rubocop-ast (1.48.0)
|
|
256
256
|
parser (>= 3.3.7.2)
|
|
257
257
|
prism (~> 1.4)
|
|
258
258
|
rubocop-performance (1.24.0)
|
|
@@ -304,10 +304,10 @@ PLATFORMS
|
|
|
304
304
|
|
|
305
305
|
DEPENDENCIES
|
|
306
306
|
appraisal (~> 2.5.0)
|
|
307
|
-
erb (<
|
|
307
|
+
erb (< 6)
|
|
308
308
|
license_finder (~> 7.0)
|
|
309
309
|
net-imap (< 0.5.0)
|
|
310
|
-
nokogiri (< 1.18.
|
|
310
|
+
nokogiri (< 1.18.10)
|
|
311
311
|
pry (>= 0.14.2)
|
|
312
312
|
pry-byebug (= 3.10.1)
|
|
313
313
|
rails (= 7.1.5.2)
|
data/gemfiles/rails_7_2.gemfile
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ..
|
|
3
3
|
specs:
|
|
4
|
-
rubocop-powerhome (0.
|
|
5
|
-
rubocop (= 1.
|
|
4
|
+
rubocop-powerhome (0.6.0)
|
|
5
|
+
rubocop (= 1.82.1)
|
|
6
6
|
rubocop-performance
|
|
7
7
|
rubocop-rails
|
|
8
8
|
rubocop-rake
|
|
@@ -234,7 +234,7 @@ GEM
|
|
|
234
234
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
235
235
|
rspec-support (~> 3.13.0)
|
|
236
236
|
rspec-support (3.13.4)
|
|
237
|
-
rubocop (1.
|
|
237
|
+
rubocop (1.82.1)
|
|
238
238
|
json (~> 2.3)
|
|
239
239
|
language_server-protocol (~> 3.17.0.2)
|
|
240
240
|
lint_roller (~> 1.1.0)
|
|
@@ -242,10 +242,10 @@ GEM
|
|
|
242
242
|
parser (>= 3.3.0.2)
|
|
243
243
|
rainbow (>= 2.2.2, < 4.0)
|
|
244
244
|
regexp_parser (>= 2.9.3, < 3.0)
|
|
245
|
-
rubocop-ast (>= 1.
|
|
245
|
+
rubocop-ast (>= 1.48.0, < 2.0)
|
|
246
246
|
ruby-progressbar (~> 1.7)
|
|
247
247
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
248
|
-
rubocop-ast (1.
|
|
248
|
+
rubocop-ast (1.48.0)
|
|
249
249
|
parser (>= 3.3.7.2)
|
|
250
250
|
prism (~> 1.4)
|
|
251
251
|
rubocop-performance (1.24.0)
|
|
@@ -298,10 +298,10 @@ PLATFORMS
|
|
|
298
298
|
|
|
299
299
|
DEPENDENCIES
|
|
300
300
|
appraisal (~> 2.5.0)
|
|
301
|
-
erb (<
|
|
301
|
+
erb (< 6)
|
|
302
302
|
license_finder (~> 7.0)
|
|
303
303
|
net-imap (< 0.5.0)
|
|
304
|
-
nokogiri (< 1.18.
|
|
304
|
+
nokogiri (< 1.18.10)
|
|
305
305
|
pry (>= 0.14.2)
|
|
306
306
|
pry-byebug (= 3.10.1)
|
|
307
307
|
rails (= 7.2.2.2)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
# rubocop:disable Lint/RedundantCopDisableDirective
|
|
6
|
+
module Migration
|
|
7
|
+
# Do not remove columns until they are first ignored in production.
|
|
8
|
+
# Verify you have deleted the 'ignored_columns' from the Model and
|
|
9
|
+
# then disable this cop to acknowledge.
|
|
10
|
+
|
|
11
|
+
# @example
|
|
12
|
+
# # good BEFORE
|
|
13
|
+
# # This code is deployed to production
|
|
14
|
+
# class User < ApplicationRecord
|
|
15
|
+
# self.ignored_columns += %w[some_column]
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# # good AFTER
|
|
19
|
+
# # Your changeset deletes the ignored_column
|
|
20
|
+
# class User < ApplicationRecord
|
|
21
|
+
# end
|
|
22
|
+
|
|
23
|
+
# class RemoveUsersSomeColumn < ActiveRecord::Migration[7.0]
|
|
24
|
+
# def change
|
|
25
|
+
# remove_column :users, :some_column # rubocop:disable Migration/AcknowledgeIgnoredColumn
|
|
26
|
+
# end
|
|
27
|
+
# end
|
|
28
|
+
class AcknowledgeIgnoredColumn < RuboCop::Cop::Base
|
|
29
|
+
MSG = "Do not remove a column until it is already ignored in production and " \
|
|
30
|
+
"all references to it are removed. Once done, remove the 'ignored_columns' " \
|
|
31
|
+
"from the Model and disable this cop to acknowledge this is safe."
|
|
32
|
+
|
|
33
|
+
def on_send(node)
|
|
34
|
+
return unless remove_column?(node)
|
|
35
|
+
|
|
36
|
+
add_offense(node)
|
|
37
|
+
end
|
|
38
|
+
alias on_csend on_send
|
|
39
|
+
|
|
40
|
+
def on_block(node)
|
|
41
|
+
return unless change_table_block?(node)
|
|
42
|
+
|
|
43
|
+
block_arg = node.arguments.first
|
|
44
|
+
return unless block_arg
|
|
45
|
+
|
|
46
|
+
remove_calls(node, block_arg.name) do |rename_node|
|
|
47
|
+
add_offense(rename_node)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def_node_matcher :change_table_block?, <<~PATTERN
|
|
52
|
+
(block
|
|
53
|
+
(send nil? :change_table ...)
|
|
54
|
+
(args (arg _))
|
|
55
|
+
_
|
|
56
|
+
)
|
|
57
|
+
PATTERN
|
|
58
|
+
|
|
59
|
+
def_node_search :remove_calls, <<~PATTERN
|
|
60
|
+
(send
|
|
61
|
+
(lvar %1)
|
|
62
|
+
:remove
|
|
63
|
+
...
|
|
64
|
+
)
|
|
65
|
+
PATTERN
|
|
66
|
+
|
|
67
|
+
def_node_matcher :remove_column?, <<~PATTERN
|
|
68
|
+
(send
|
|
69
|
+
nil?
|
|
70
|
+
:remove_column
|
|
71
|
+
...
|
|
72
|
+
)
|
|
73
|
+
PATTERN
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
# rubocop:enable Lint/RedundantCopDisableDirective
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Migration
|
|
6
|
+
# Do not rename columns that are in use. It will cause down time in your application
|
|
7
|
+
# and is unsafe for pt-online-schema-change.
|
|
8
|
+
# Instead:
|
|
9
|
+
#
|
|
10
|
+
# 1. Create a new column
|
|
11
|
+
# 2. Backfill and write to the new column
|
|
12
|
+
# 3. Add old column to `ignored_columns` in model
|
|
13
|
+
# 4. Drop the old column
|
|
14
|
+
#
|
|
15
|
+
# This is meaningful if the table has records in it.
|
|
16
|
+
# But even if the column is not in use, one can not rename it.
|
|
17
|
+
# ActiveRecord accesses old columns unless all queries explicitly SELECT other columns.
|
|
18
|
+
#
|
|
19
|
+
# @example
|
|
20
|
+
# # bad
|
|
21
|
+
# class RenameUsersSettingsToProperties < ActiveRecord::Migration[7.0]
|
|
22
|
+
# def change
|
|
23
|
+
# rename_column :users, :settings, :properties
|
|
24
|
+
# end
|
|
25
|
+
# end
|
|
26
|
+
#
|
|
27
|
+
# # good
|
|
28
|
+
# class AddUsersProperties < ActiveRecord::Migration[7.0]
|
|
29
|
+
# def change
|
|
30
|
+
# add_column :users, :properties, :jsonb
|
|
31
|
+
# end
|
|
32
|
+
# end
|
|
33
|
+
#
|
|
34
|
+
# class User < ApplicationRecord
|
|
35
|
+
# self.ignored_columns += %w[settings]
|
|
36
|
+
# end
|
|
37
|
+
#
|
|
38
|
+
# class RemoveUsersSettings < ActiveRecord::Migration[7.0]
|
|
39
|
+
# def change
|
|
40
|
+
# remove_column :users, :settings
|
|
41
|
+
# end
|
|
42
|
+
# end
|
|
43
|
+
class RenameColumn < RuboCop::Cop::Base
|
|
44
|
+
MSG = "Do not rename columns that are in use. It will cause down time in your application " \
|
|
45
|
+
"and is unsafe for pt-online-schema-change."
|
|
46
|
+
|
|
47
|
+
def on_send(node)
|
|
48
|
+
return unless rename_column?(node)
|
|
49
|
+
|
|
50
|
+
add_offense(node)
|
|
51
|
+
end
|
|
52
|
+
alias on_csend on_send
|
|
53
|
+
|
|
54
|
+
def on_block(node)
|
|
55
|
+
return unless change_table_block?(node)
|
|
56
|
+
|
|
57
|
+
block_arg = node.arguments.first
|
|
58
|
+
return unless block_arg
|
|
59
|
+
|
|
60
|
+
rename_calls(node, block_arg.name) do |rename_node|
|
|
61
|
+
add_offense(rename_node)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def_node_matcher :change_table_block?, <<~PATTERN
|
|
66
|
+
(block
|
|
67
|
+
(send nil? :change_table ...)
|
|
68
|
+
(args (arg _))
|
|
69
|
+
_
|
|
70
|
+
)
|
|
71
|
+
PATTERN
|
|
72
|
+
|
|
73
|
+
def_node_search :rename_calls, <<~PATTERN
|
|
74
|
+
(send
|
|
75
|
+
(lvar %1)
|
|
76
|
+
:rename
|
|
77
|
+
...
|
|
78
|
+
)
|
|
79
|
+
PATTERN
|
|
80
|
+
|
|
81
|
+
def_node_matcher :rename_column?, <<~PATTERN
|
|
82
|
+
(send
|
|
83
|
+
nil?
|
|
84
|
+
:rename_column
|
|
85
|
+
...
|
|
86
|
+
)
|
|
87
|
+
PATTERN
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Migration
|
|
6
|
+
# Do not rename tables. It will cause down time in your application and is unsafe for pt-online-schema-change.
|
|
7
|
+
# Instead:
|
|
8
|
+
#
|
|
9
|
+
# 1. Create a new table
|
|
10
|
+
# 2. Backfill and write to the new table
|
|
11
|
+
# 3. Drop the old table
|
|
12
|
+
#
|
|
13
|
+
# @example
|
|
14
|
+
# # bad
|
|
15
|
+
# class RenameUsersToAccouts < ActiveRecord::Migration[7.0]
|
|
16
|
+
# def change
|
|
17
|
+
# rename_table :users, :accounts
|
|
18
|
+
# end
|
|
19
|
+
# end
|
|
20
|
+
#
|
|
21
|
+
# # good
|
|
22
|
+
# class AddAccounts < ActiveRecord::Migration[7.0]
|
|
23
|
+
# def change
|
|
24
|
+
# create_table :accounts do |t|
|
|
25
|
+
# t.string :name, null: false
|
|
26
|
+
# end
|
|
27
|
+
# end
|
|
28
|
+
# end
|
|
29
|
+
#
|
|
30
|
+
# class RemoveUsers < ActiveRecord::Migration[7.0]
|
|
31
|
+
# def change
|
|
32
|
+
# remove_table :users, if_exists: true
|
|
33
|
+
# end
|
|
34
|
+
# end
|
|
35
|
+
class RenameTable < RuboCop::Cop::Base
|
|
36
|
+
MSG = "Do not rename tables. It will cause down time in your application " \
|
|
37
|
+
"and is unsafe for pt-online-schema-change."
|
|
38
|
+
|
|
39
|
+
def on_send(node)
|
|
40
|
+
return unless rename_table?(node)
|
|
41
|
+
|
|
42
|
+
add_offense(node)
|
|
43
|
+
end
|
|
44
|
+
alias on_csend on_send
|
|
45
|
+
|
|
46
|
+
def_node_matcher :rename_table?, <<~PATTERN
|
|
47
|
+
(send
|
|
48
|
+
nil?
|
|
49
|
+
:rename_table
|
|
50
|
+
...
|
|
51
|
+
)
|
|
52
|
+
PATTERN
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
data/lib/rubocop/powerhome.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
module Powerhome
|
|
5
5
|
class Error < StandardError; end
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
|
8
8
|
CONFIG_DEFAULT = PROJECT_ROOT.join("config", "default.yml").freeze
|
|
9
9
|
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
data/lib/rubocop-powerhome.rb
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/rubocop/powerhome/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "rubocop-powerhome"
|
|
7
|
+
spec.version = RuboCop::Powerhome::VERSION
|
|
8
|
+
spec.authors = ["Carlos Palhares", "Garett Arrowood"]
|
|
9
|
+
spec.email = ["chjunior@gmail.com", "garettarrowood@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Powerhome Rubocop standard rules"
|
|
12
|
+
spec.description = "Powerhome Rubocop standard rules"
|
|
13
|
+
spec.homepage = "https://github.com/powerhome/power-tools/blob/main/packages/rubocop-powerhome/"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 3.0"
|
|
16
|
+
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
19
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
|
|
20
|
+
|
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
25
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
spec.bindir = "exe"
|
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
|
+
spec.require_paths = ["lib"]
|
|
31
|
+
|
|
32
|
+
# Uncomment to register a new dependency of your gem
|
|
33
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
|
34
|
+
|
|
35
|
+
# For more information and examples about making a new gem, check out our
|
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
37
|
+
|
|
38
|
+
spec.add_dependency "rubocop", "1.82.1"
|
|
39
|
+
spec.add_dependency "rubocop-performance"
|
|
40
|
+
spec.add_dependency "rubocop-rails"
|
|
41
|
+
spec.add_dependency "rubocop-rake"
|
|
42
|
+
spec.add_dependency "rubocop-rspec"
|
|
43
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
44
|
+
|
|
45
|
+
spec.add_development_dependency "appraisal", "~> 2.5.0"
|
|
46
|
+
spec.add_development_dependency "license_finder", "~> 7.0"
|
|
47
|
+
spec.add_development_dependency "pry", ">= 0.14.2"
|
|
48
|
+
spec.add_development_dependency "pry-byebug", "3.10.1"
|
|
49
|
+
spec.add_development_dependency "rails", ">= 6.0.6.1", "< 8"
|
|
50
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
51
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
52
|
+
end
|
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-powerhome
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Carlos Palhares
|
|
8
8
|
- Garett Arrowood
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: exe
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: rubocop
|
|
@@ -17,14 +16,14 @@ dependencies:
|
|
|
17
16
|
requirements:
|
|
18
17
|
- - '='
|
|
19
18
|
- !ruby/object:Gem::Version
|
|
20
|
-
version: 1.
|
|
19
|
+
version: 1.82.1
|
|
21
20
|
type: :runtime
|
|
22
21
|
prerelease: false
|
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
23
|
requirements:
|
|
25
24
|
- - '='
|
|
26
25
|
- !ruby/object:Gem::Version
|
|
27
|
-
version: 1.
|
|
26
|
+
version: 1.82.1
|
|
28
27
|
- !ruby/object:Gem::Dependency
|
|
29
28
|
name: rubocop-performance
|
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -214,6 +213,10 @@ files:
|
|
|
214
213
|
- gemfiles/rails_7_2.gemfile
|
|
215
214
|
- gemfiles/rails_7_2.gemfile.lock
|
|
216
215
|
- lib/rubocop-powerhome.rb
|
|
216
|
+
- lib/rubocop/cop/migration/acknowledge_ignored_column.rb
|
|
217
|
+
- lib/rubocop/cop/migration/rename_column.rb
|
|
218
|
+
- lib/rubocop/cop/migration/rename_table.rb
|
|
219
|
+
- lib/rubocop/cop/migration_cops.rb
|
|
217
220
|
- lib/rubocop/cop/naming/view_component.rb
|
|
218
221
|
- lib/rubocop/cop/naming_cops.rb
|
|
219
222
|
- lib/rubocop/cop/style/no_helpers.rb
|
|
@@ -222,6 +225,7 @@ files:
|
|
|
222
225
|
- lib/rubocop/powerhome/inject.rb
|
|
223
226
|
- lib/rubocop/powerhome/version.rb
|
|
224
227
|
- mkdocs.yml
|
|
228
|
+
- rubocop-powerhome.gemspec
|
|
225
229
|
- sig/rubocop/powerhome.rbs
|
|
226
230
|
homepage: https://github.com/powerhome/power-tools/blob/main/packages/rubocop-powerhome/
|
|
227
231
|
licenses:
|
|
@@ -231,7 +235,6 @@ metadata:
|
|
|
231
235
|
source_code_uri: https://github.com/powerhome/power-tools/blob/main/packages/rubocop-powerhome/
|
|
232
236
|
changelog_uri: https://github.com/powerhome/power-tools/blob/main/packages/rubocop-powerhome//CHANGELOG.md
|
|
233
237
|
rubygems_mfa_required: 'true'
|
|
234
|
-
post_install_message:
|
|
235
238
|
rdoc_options: []
|
|
236
239
|
require_paths:
|
|
237
240
|
- lib
|
|
@@ -246,8 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
246
249
|
- !ruby/object:Gem::Version
|
|
247
250
|
version: '0'
|
|
248
251
|
requirements: []
|
|
249
|
-
rubygems_version: 3.
|
|
250
|
-
signing_key:
|
|
252
|
+
rubygems_version: 3.6.9
|
|
251
253
|
specification_version: 4
|
|
252
254
|
summary: Powerhome Rubocop standard rules
|
|
253
255
|
test_files: []
|