rubocop-sequel 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/actions.yml +2 -1
- data/lib/rubocop/cop/sequel/column_default.rb +2 -2
- data/lib/rubocop/cop/sequel/concurrent_index.rb +2 -2
- data/lib/rubocop/cop/sequel/json_column.rb +3 -3
- data/lib/rubocop/cop/sequel/migration_name.rb +3 -3
- data/lib/rubocop/cop/sequel/save_changes.rb +7 -5
- data/rubocop-sequel.gemspec +2 -2
- data/spec/rubocop/cop/sequel/column_default_spec.rb +4 -4
- data/spec/rubocop/cop/sequel/concurrent_index_spec.rb +8 -8
- data/spec/rubocop/cop/sequel/json_column_spec.rb +16 -16
- data/spec/rubocop/cop/sequel/migration_name_spec.rb +8 -8
- data/spec/rubocop/cop/sequel/save_changes_spec.rb +4 -4
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8b48c970ba23412aca37456e02bc2e3cd27856338494132bfe0ef2e43fe2bf0b
|
4
|
+
data.tar.gz: 55f74cf994978072f005b0c23603e12d2eb79a9cb680f49496aaf430500ee2fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '069b933d71802921ffdbf4e763686c00f69104ec6b181c1854f259e4bb9a13352ed39ccc76197341bc39487908eed2eecfd3d9e1ea1bd3453441de3a45f4f774'
|
7
|
+
data.tar.gz: c6273c16039bf43725eaa6218881fcd84c64835fcae46dc18393d15e32bb944a69252800d312f2a0f23b5d29aeb81c8ac28468ed3f5620cbfa1aa605731532c0
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Sequel
|
6
6
|
# ColumnDefault looks for column creation with a default value.
|
7
|
-
class ColumnDefault <
|
7
|
+
class ColumnDefault < Base
|
8
8
|
MSG = "Don't create new column with default values"
|
9
9
|
|
10
10
|
def_node_matcher :add_column_default?, <<-MATCHER
|
@@ -14,7 +14,7 @@ module RuboCop
|
|
14
14
|
def on_send(node)
|
15
15
|
return unless add_column_default?(node)
|
16
16
|
|
17
|
-
add_offense(node
|
17
|
+
add_offense(node.loc.selector, message: MSG)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Sequel
|
6
6
|
# ConcurrentIndex looks for non-concurrent index creation.
|
7
|
-
class ConcurrentIndex <
|
7
|
+
class ConcurrentIndex < Base
|
8
8
|
MSG = 'Prefer creating or dropping new index concurrently'
|
9
9
|
|
10
10
|
def_node_matcher :indexes?, <<-MATCHER
|
@@ -13,7 +13,7 @@ module RuboCop
|
|
13
13
|
|
14
14
|
def on_send(node)
|
15
15
|
indexes?(node) do |args|
|
16
|
-
add_offense(node
|
16
|
+
add_offense(node.loc.selector, message: MSG) if offensive?(args)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Sequel
|
6
6
|
# JSONColumn looks for non-JSONB columns.
|
7
|
-
class JSONColumn <
|
7
|
+
class JSONColumn < Base
|
8
8
|
MSG = 'Use JSONB rather than JSON or hstore'
|
9
9
|
|
10
10
|
def_node_matcher :json_or_hstore?, <<-MATCHER
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
22
22
|
def on_send(node)
|
23
23
|
return unless json_or_hstore?(node)
|
24
24
|
|
25
|
-
add_offense(node
|
25
|
+
add_offense(node.loc.selector, message: MSG)
|
26
26
|
end
|
27
27
|
|
28
28
|
def on_block(node)
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
node.each_node(:send) do |method|
|
32
32
|
next unless column_method?(method) || column_type?(method)
|
33
33
|
|
34
|
-
add_offense(method
|
34
|
+
add_offense(method.loc.selector, message: MSG)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -4,19 +4,19 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Sequel
|
6
6
|
# MigrationName looks for migration files named with a default name.
|
7
|
-
class MigrationName <
|
7
|
+
class MigrationName < Base
|
8
8
|
include RangeHelp
|
9
9
|
|
10
10
|
MSG = 'Migration files should not use default name.'
|
11
11
|
|
12
|
-
def
|
12
|
+
def on_new_investigation
|
13
13
|
file_path = processed_source.buffer.name
|
14
14
|
return if config.file_to_include?(file_path)
|
15
15
|
|
16
16
|
return unless filename_bad?(file_path)
|
17
17
|
|
18
18
|
location = source_range(processed_source.buffer, 1, 0)
|
19
|
-
add_offense(
|
19
|
+
add_offense(location)
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
@@ -4,7 +4,9 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Sequel
|
6
6
|
# SaveChanges promotes the use of save_changes.
|
7
|
-
class SaveChanges <
|
7
|
+
class SaveChanges < Base
|
8
|
+
extend AutoCorrector
|
9
|
+
|
8
10
|
MSG = 'Use `Sequel::Model#save_changes` instead of '\
|
9
11
|
'`Sequel::Model#save`.'
|
10
12
|
|
@@ -15,11 +17,11 @@ module RuboCop
|
|
15
17
|
def on_send(node)
|
16
18
|
return unless model_save?(node)
|
17
19
|
|
18
|
-
|
19
|
-
end
|
20
|
+
range = node.loc.selector
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
add_offense(range, message: MSG) do |corrector|
|
23
|
+
corrector.replace(range, 'save_changes')
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
data/rubocop-sequel.gemspec
CHANGED
@@ -13,9 +13,9 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
14
|
gem.name = 'rubocop-sequel'
|
15
15
|
gem.require_paths = ['lib']
|
16
|
-
gem.version = '0.
|
16
|
+
gem.version = '0.2.0'
|
17
17
|
|
18
|
-
gem.required_ruby_version = '
|
18
|
+
gem.required_ruby_version = '>= 2.4'
|
19
19
|
|
20
20
|
gem.add_runtime_dependency 'rubocop', '~> 1.0'
|
21
21
|
|
@@ -6,12 +6,12 @@ describe RuboCop::Cop::Sequel::ColumnDefault do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'registers an offense when setting a default' do
|
9
|
-
inspect_source('add_column(:products, :type, :text, default: "cop")')
|
10
|
-
expect(
|
9
|
+
offenses = inspect_source('add_column(:products, :type, :text, default: "cop")')
|
10
|
+
expect(offenses.size).to eq(1)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'does not register an offense when not setting a default' do
|
14
|
-
inspect_source('add_column(:products, :type, :text)')
|
15
|
-
expect(
|
14
|
+
offenses = inspect_source('add_column(:products, :type, :text)')
|
15
|
+
expect(offenses).to be_empty
|
16
16
|
end
|
17
17
|
end
|
@@ -7,35 +7,35 @@ describe RuboCop::Cop::Sequel::ConcurrentIndex do
|
|
7
7
|
|
8
8
|
context 'without the concurrent option' do
|
9
9
|
it 'registers an offense without options' do
|
10
|
-
inspect_source(<<~SOURCE)
|
10
|
+
offenses = inspect_source(<<~SOURCE)
|
11
11
|
add_index(:products, :name)
|
12
12
|
drop_index(:products, :name)
|
13
13
|
SOURCE
|
14
|
-
expect(
|
14
|
+
expect(offenses.size).to eq(2)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'registers an offense with other options' do
|
18
|
-
inspect_source(<<~SOURCE)
|
18
|
+
offenses = inspect_source(<<~SOURCE)
|
19
19
|
add_index(:products, :name, unique: true)
|
20
20
|
drop_index(:products, :name, unique: true)
|
21
21
|
SOURCE
|
22
|
-
expect(
|
22
|
+
expect(offenses.size).to eq(2)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'registers an offense with composite index' do
|
26
|
-
inspect_source(<<~SOURCE)
|
26
|
+
offenses = inspect_source(<<~SOURCE)
|
27
27
|
add_index(:products, [:name, :price], unique: true)
|
28
28
|
drop_index(:products, [:name, :price])
|
29
29
|
SOURCE
|
30
|
-
expect(
|
30
|
+
expect(offenses.size).to eq(2)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'does not register an offense when using concurrent option' do
|
35
|
-
inspect_source(<<~SOURCE)
|
35
|
+
offenses = inspect_source(<<~SOURCE)
|
36
36
|
add_index(:products, :name, unique: true, concurrently: true)
|
37
37
|
drop_index(:products, :name, concurrently: true)
|
38
38
|
SOURCE
|
39
|
-
expect(
|
39
|
+
expect(offenses).to be_empty
|
40
40
|
end
|
41
41
|
end
|
@@ -7,45 +7,45 @@ describe RuboCop::Cop::Sequel::JSONColumn do
|
|
7
7
|
|
8
8
|
context 'with add_column' do
|
9
9
|
it 'registers an offense when using json type' do
|
10
|
-
inspect_source('add_column(:products, :type, :json)')
|
11
|
-
expect(
|
10
|
+
offenses = inspect_source('add_column(:products, :type, :json)')
|
11
|
+
expect(offenses.size).to eq(1)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'registers an offense when using hstore type' do
|
15
|
-
inspect_source('add_column(:products, :type, :hstore)')
|
16
|
-
expect(
|
15
|
+
offenses = inspect_source('add_column(:products, :type, :hstore)')
|
16
|
+
expect(offenses.size).to eq(1)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'does not register an offense when using jsonb' do
|
20
|
-
inspect_source('add_column(:products, :type, :jsonb)')
|
21
|
-
expect(
|
20
|
+
offenses = inspect_source('add_column(:products, :type, :jsonb)')
|
21
|
+
expect(offenses).to be_empty
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'with create_table' do
|
26
26
|
it 'registers an offense when using json as a method' do
|
27
|
-
inspect_source('create_table(:products) { json :type, default: {} }')
|
28
|
-
expect(
|
27
|
+
offenses = inspect_source('create_table(:products) { json :type, default: {} }')
|
28
|
+
expect(offenses.size).to eq(1)
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'registers an offense when using the column method with hstore' do
|
32
|
-
inspect_source('create_table(:products) { column :type, :hstore }')
|
33
|
-
expect(
|
32
|
+
offenses = inspect_source('create_table(:products) { column :type, :hstore }')
|
33
|
+
expect(offenses.size).to eq(1)
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'does not register an offense when using jsonb as column type`' do
|
37
|
-
inspect_source('create_table(:products) { column :type, :jsonb }')
|
38
|
-
expect(
|
37
|
+
offenses = inspect_source('create_table(:products) { column :type, :jsonb }')
|
38
|
+
expect(offenses).to be_empty
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'does not register an offense when using jsonb' do
|
42
|
-
inspect_source('create_table(:products) { jsonb :type }')
|
43
|
-
expect(
|
42
|
+
offenses = inspect_source('create_table(:products) { jsonb :type }')
|
43
|
+
expect(offenses).to be_empty
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'does not register an offense when using a simple type' do
|
47
|
-
inspect_source('create_table(:products) { integer :type, default: 0 }')
|
48
|
-
expect(
|
47
|
+
offenses = inspect_source('create_table(:products) { integer :type, default: 0 }')
|
48
|
+
expect(offenses).to be_empty
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -17,13 +17,13 @@ describe RuboCop::Cop::Sequel::MigrationName, :config do
|
|
17
17
|
let(:cop_config) { {} }
|
18
18
|
|
19
19
|
it 'registers an offense when using the default name' do
|
20
|
-
inspect_source('', 'new_migration.rb')
|
21
|
-
expect(
|
20
|
+
offenses = inspect_source('', 'new_migration.rb')
|
21
|
+
expect(offenses.size).to eq(1)
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'does not register an offense when using a specific name' do
|
25
|
-
inspect_source('', 'add_index.rb')
|
26
|
-
expect(
|
25
|
+
offenses = inspect_source('', 'add_index.rb')
|
26
|
+
expect(offenses).to be_empty
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -31,13 +31,13 @@ describe RuboCop::Cop::Sequel::MigrationName, :config do
|
|
31
31
|
let(:cop_config) { { 'DefaultName' => 'add_migration' } }
|
32
32
|
|
33
33
|
it 'registers an offense when using the default name' do
|
34
|
-
inspect_source('', 'add_migration.rb')
|
35
|
-
expect(
|
34
|
+
offenses = inspect_source('', 'add_migration.rb')
|
35
|
+
expect(offenses.size).to eq(1)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'does not register an offense when using a specific name' do
|
39
|
-
inspect_source('', 'add_index.rb')
|
40
|
-
expect(
|
39
|
+
offenses = inspect_source('', 'add_index.rb')
|
40
|
+
expect(offenses).to be_empty
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -6,13 +6,13 @@ describe RuboCop::Cop::Sequel::SaveChanges do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'registers an offense when using save' do
|
9
|
-
inspect_source('favorite.save')
|
10
|
-
expect(
|
9
|
+
offenses = inspect_source('favorite.save')
|
10
|
+
expect(offenses.size).to eq(1)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'does not register an offense when using save_changes' do
|
14
|
-
inspect_source('favorite.save_changes')
|
15
|
-
expect(
|
14
|
+
offenses = inspect_source('favorite.save_changes')
|
15
|
+
expect(offenses).to be_empty
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'auto-corrects by using save_changes' 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.
|
4
|
+
version: 0.2.0
|
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:
|
11
|
+
date: 2021-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -152,7 +152,7 @@ require_paths:
|
|
152
152
|
- lib
|
153
153
|
required_ruby_version: !ruby/object:Gem::Requirement
|
154
154
|
requirements:
|
155
|
-
- - "
|
155
|
+
- - ">="
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '2.4'
|
158
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -161,8 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
161
|
- !ruby/object:Gem::Version
|
162
162
|
version: '0'
|
163
163
|
requirements: []
|
164
|
-
|
165
|
-
rubygems_version: 2.6.11
|
164
|
+
rubygems_version: 3.1.4
|
166
165
|
signing_key:
|
167
166
|
specification_version: 4
|
168
167
|
summary: A Sequel plugin for RuboCop
|