rubocop-sequel 0.3.7 → 0.3.8
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43689260646cb1428cd6629924d01648a005939d8f1094a6fcbb88ecc1a7fc68
|
4
|
+
data.tar.gz: b95f6400f9d2857ac7ce9d32c8931a71db14ba6e8cd86e128289fe1ef836d95b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a78387c550cc09564f2fffee05a5dda77c370130dd41f9c8b8a0f8bb26683813b97c1c2540250574c95ae7a192743d1873f59b82cdf02de501ff1d679a029bb5
|
7
|
+
data.tar.gz: 2e91b8df57f918c221d2d2319037264d347b84eaa082ed6f378d85f5023f9b6bcf19a5b2854553cc56707e986551c9bf5dd2ff1f17aaa1e04a3e5bd7c94221a9
|
data/config/default.yml
CHANGED
@@ -17,7 +17,7 @@ Sequel/IrreversibleMigration:
|
|
17
17
|
Reference: https://www.rubydoc.info/gems/rubocop-sequel/RuboCop/Cop/Sequel/IrreversibleMigration
|
18
18
|
Enabled: true
|
19
19
|
VersionAdded: 0.3.5
|
20
|
-
VersionChanged: 0.3.
|
20
|
+
VersionChanged: 0.3.8
|
21
21
|
|
22
22
|
Sequel/JSONColumn:
|
23
23
|
Description: >-
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
set_column_allow_null
|
29
29
|
].freeze
|
30
30
|
|
31
|
-
MSG = '
|
31
|
+
MSG = 'Using "%<name>s" inside a "change" block may cause an irreversible migration. Use "up" & "down" instead.'
|
32
32
|
PRIMARY_KEY_MSG = 'Avoid using "add_primary_key" with an array argument inside a "change" block.'
|
33
33
|
|
34
34
|
def on_block(node)
|
@@ -46,6 +46,8 @@ module RuboCop
|
|
46
46
|
def validate_node(node)
|
47
47
|
return if within_create_table_block?(node)
|
48
48
|
|
49
|
+
return if part_of_method_call?(node)
|
50
|
+
|
49
51
|
add_offense(node.loc.selector, message: format(MSG, name: node.method_name)) unless valid_change_method?(node)
|
50
52
|
|
51
53
|
add_offense(node.loc.selector, message: PRIMARY_KEY_MSG) if invalid_primary_key_method?(node)
|
@@ -68,6 +70,10 @@ module RuboCop
|
|
68
70
|
ancestor.method_name == :create_table
|
69
71
|
end
|
70
72
|
end
|
73
|
+
|
74
|
+
def part_of_method_call?(node)
|
75
|
+
node.each_ancestor(:send).count.positive?
|
76
|
+
end
|
71
77
|
end
|
72
78
|
end
|
73
79
|
end
|
data/rubocop-sequel.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
13
13
|
gem.name = 'rubocop-sequel'
|
14
14
|
gem.require_paths = ['lib']
|
15
|
-
gem.version = '0.3.
|
15
|
+
gem.version = '0.3.8'
|
16
16
|
gem.metadata['rubygems_mfa_required'] = 'true'
|
17
17
|
|
18
18
|
gem.required_ruby_version = '>= 2.5'
|
@@ -103,6 +103,52 @@ RSpec.describe RuboCop::Cop::Sequel::IrreversibleMigration do
|
|
103
103
|
expect(offenses.size).to eq(1)
|
104
104
|
end
|
105
105
|
end
|
106
|
+
|
107
|
+
describe 'and a method is used within an argument' do
|
108
|
+
let(:source) do
|
109
|
+
<<~SOURCE
|
110
|
+
change do
|
111
|
+
alter_table(:stores) do
|
112
|
+
add_column(:products, JSON, null: false, default: Sequel.pg_json({}))
|
113
|
+
add_constraint(
|
114
|
+
:only_one_user,
|
115
|
+
(
|
116
|
+
Sequel.cast(Sequel.~(user_id: nil), Integer) +
|
117
|
+
Sequel.cast(Sequel.~(owner_id: nil), Integer)
|
118
|
+
) => 1,
|
119
|
+
)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
SOURCE
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'does not register an offense with valid methods' do
|
126
|
+
offenses = inspect_source_within_migration(source)
|
127
|
+
expect(offenses).to be_empty
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe 'and an invalid change method contains another invalid change method as an argument' do
|
132
|
+
let(:source) do
|
133
|
+
<<~SOURCE
|
134
|
+
change do
|
135
|
+
alter_table(:stores) do
|
136
|
+
drop_column(:products, JSON, null: false, default: Sequel.pg_json({}))
|
137
|
+
end
|
138
|
+
end
|
139
|
+
SOURCE
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'only registers 1 offense' do
|
143
|
+
offenses = inspect_source_within_migration(source)
|
144
|
+
expect(offenses.size).to eq(1)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'only registers an offense for the parent method' do
|
148
|
+
offenses = inspect_source_within_migration(source)
|
149
|
+
expect(offenses.first.message).to include('drop_column')
|
150
|
+
end
|
151
|
+
end
|
106
152
|
end
|
107
153
|
|
108
154
|
context 'when inside an up block' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timothée Peignier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|