rubocop-powerhome 0.5.5 → 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/Appraisals +8 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +20 -13
- data/gemfiles/rails_6_0.gemfile +3 -1
- data/gemfiles/rails_6_1.gemfile +6 -1
- data/gemfiles/rails_6_1.gemfile.lock +66 -47
- data/gemfiles/rails_7_0.gemfile +6 -1
- data/gemfiles/rails_7_0.gemfile.lock +63 -46
- data/gemfiles/rails_7_1.gemfile +14 -0
- data/gemfiles/rails_7_1.gemfile.lock +321 -0
- data/gemfiles/rails_7_2.gemfile +14 -0
- data/gemfiles/rails_7_2.gemfile.lock +315 -0
- 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 +2 -2
- metadata +14 -6
|
@@ -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
data/rubocop-powerhome.gemspec
CHANGED
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
|
|
|
35
35
|
# For more information and examples about making a new gem, check out our
|
|
36
36
|
# guide at: https://bundler.io/guides/creating_gem.html
|
|
37
37
|
|
|
38
|
-
spec.add_dependency "rubocop", "1.
|
|
38
|
+
spec.add_dependency "rubocop", "1.82.1"
|
|
39
39
|
spec.add_dependency "rubocop-performance"
|
|
40
40
|
spec.add_dependency "rubocop-rails"
|
|
41
41
|
spec.add_dependency "rubocop-rake"
|
|
@@ -46,7 +46,7 @@ Gem::Specification.new do |spec|
|
|
|
46
46
|
spec.add_development_dependency "license_finder", "~> 7.0"
|
|
47
47
|
spec.add_development_dependency "pry", ">= 0.14.2"
|
|
48
48
|
spec.add_development_dependency "pry-byebug", "3.10.1"
|
|
49
|
-
spec.add_development_dependency "rails", ">= 6.0.6.1", "<
|
|
49
|
+
spec.add_development_dependency "rails", ">= 6.0.6.1", "< 8"
|
|
50
50
|
spec.add_development_dependency "rake", "~> 13.0"
|
|
51
51
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
52
52
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - '='
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.
|
|
19
|
+
version: 1.82.1
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - '='
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.
|
|
26
|
+
version: 1.82.1
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rubocop-performance
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -145,7 +145,7 @@ dependencies:
|
|
|
145
145
|
version: 6.0.6.1
|
|
146
146
|
- - "<"
|
|
147
147
|
- !ruby/object:Gem::Version
|
|
148
|
-
version: '
|
|
148
|
+
version: '8'
|
|
149
149
|
type: :development
|
|
150
150
|
prerelease: false
|
|
151
151
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -155,7 +155,7 @@ dependencies:
|
|
|
155
155
|
version: 6.0.6.1
|
|
156
156
|
- - "<"
|
|
157
157
|
- !ruby/object:Gem::Version
|
|
158
|
-
version: '
|
|
158
|
+
version: '8'
|
|
159
159
|
- !ruby/object:Gem::Dependency
|
|
160
160
|
name: rake
|
|
161
161
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -208,7 +208,15 @@ files:
|
|
|
208
208
|
- gemfiles/rails_6_1.gemfile.lock
|
|
209
209
|
- gemfiles/rails_7_0.gemfile
|
|
210
210
|
- gemfiles/rails_7_0.gemfile.lock
|
|
211
|
+
- gemfiles/rails_7_1.gemfile
|
|
212
|
+
- gemfiles/rails_7_1.gemfile.lock
|
|
213
|
+
- gemfiles/rails_7_2.gemfile
|
|
214
|
+
- gemfiles/rails_7_2.gemfile.lock
|
|
211
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
|
|
212
220
|
- lib/rubocop/cop/naming/view_component.rb
|
|
213
221
|
- lib/rubocop/cop/naming_cops.rb
|
|
214
222
|
- lib/rubocop/cop/style/no_helpers.rb
|
|
@@ -241,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
241
249
|
- !ruby/object:Gem::Version
|
|
242
250
|
version: '0'
|
|
243
251
|
requirements: []
|
|
244
|
-
rubygems_version: 3.6.
|
|
252
|
+
rubygems_version: 3.6.9
|
|
245
253
|
specification_version: 4
|
|
246
254
|
summary: Powerhome Rubocop standard rules
|
|
247
255
|
test_files: []
|