rubocop-sequel 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -1
- data/lib/rubocop-sequel.rb +1 -0
- 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 +37 -0
- data/lib/rubocop/cop/sequel/save_changes.rb +2 -2
- data/rubocop-sequel.gemspec +6 -6
- data/spec/rubocop/cop/sequel/json_column_spec.rb +51 -0
- metadata +21 -19
- data/rubocop.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8a199639fb0c16e569564f9648764d8fb8aaf33bbee5def7a66d210cc85d649
|
4
|
+
data.tar.gz: 593503731a786d54e7fafbde51fd1972ce2d20713549c9d440d62a899c2e7ee0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b55fa4dd717d9f52c7df265cff1e69971fc383dd2ee5851badeab905824910735e5f911061dbec719f66a44cf4f2b3a4774e5d068e3bd305e05261c051886b78
|
7
|
+
data.tar.gz: eb87589c3d20befa8af7bdff1c9c46143b351d7a38e43c32b3b3ce195bdb538e8fefc7b9f97635aad7d9511dd3e276c382349792c8519aa3d6e9e462d6ee3791
|
data/.rubocop.yml
CHANGED
@@ -7,7 +7,8 @@ AllCops:
|
|
7
7
|
# Offense count: 1
|
8
8
|
# Configuration parameters: CountComments, ExcludedMethods.
|
9
9
|
Metrics/BlockLength:
|
10
|
-
|
10
|
+
Exclude:
|
11
|
+
- spec/**/*
|
11
12
|
|
12
13
|
# Offense count: 1
|
13
14
|
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
data/lib/rubocop-sequel.rb
CHANGED
@@ -7,12 +7,12 @@ module RuboCop
|
|
7
7
|
class ColumnDefault < Cop
|
8
8
|
MSG = "Don't create new column with default values"
|
9
9
|
|
10
|
-
def_node_matcher :add_column_default
|
10
|
+
def_node_matcher :add_column_default?, <<-MATCHER
|
11
11
|
(send _ :add_column ... (hash (pair (sym :default) _)))
|
12
12
|
MATCHER
|
13
13
|
|
14
14
|
def on_send(node)
|
15
|
-
return unless add_column_default(node)
|
15
|
+
return unless add_column_default?(node)
|
16
16
|
add_offense(node, location: :selector, message: MSG)
|
17
17
|
end
|
18
18
|
end
|
@@ -7,12 +7,12 @@ module RuboCop
|
|
7
7
|
class ConcurrentIndex < Cop
|
8
8
|
MSG = 'Prefer creating or dropping new index concurrently'
|
9
9
|
|
10
|
-
def_node_matcher :indexes
|
10
|
+
def_node_matcher :indexes?, <<-MATCHER
|
11
11
|
(send _ {:add_index :drop_index} $...)
|
12
12
|
MATCHER
|
13
13
|
|
14
14
|
def on_send(node)
|
15
|
-
indexes(node) do |args|
|
15
|
+
indexes?(node) do |args|
|
16
16
|
if offensive?(args)
|
17
17
|
add_offense(node, location: :selector, message: MSG)
|
18
18
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Sequel
|
6
|
+
# JSONColumn looks for non-JSONB columns.
|
7
|
+
class JSONColumn < Cop
|
8
|
+
MSG = 'Use JSONB rather than JSON or hstore'
|
9
|
+
|
10
|
+
def_node_matcher :json_or_hstore?, <<-MATCHER
|
11
|
+
(send _ :add_column ... (sym {:json :hstore}))
|
12
|
+
MATCHER
|
13
|
+
|
14
|
+
def_node_matcher :column_type?, <<-MATCHER
|
15
|
+
(send _ {:json :hstore} ...)
|
16
|
+
MATCHER
|
17
|
+
|
18
|
+
def_node_matcher :column_method?, <<-MATCHER
|
19
|
+
(send _ :column ... (sym {:json :hstore}))
|
20
|
+
MATCHER
|
21
|
+
|
22
|
+
def on_send(node)
|
23
|
+
return unless json_or_hstore?(node)
|
24
|
+
add_offense(node, location: :selector, message: MSG)
|
25
|
+
end
|
26
|
+
|
27
|
+
def on_block(node)
|
28
|
+
return unless node.send_node.method_name == :create_table
|
29
|
+
node.each_node(:send) do |method|
|
30
|
+
next unless column_method?(method) || column_type?(method)
|
31
|
+
add_offense(method, location: :selector, message: MSG)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -8,12 +8,12 @@ module RuboCop
|
|
8
8
|
MSG = 'Use `Sequel::Model#save_changes` instead of '\
|
9
9
|
'`Sequel::Model#save`.'
|
10
10
|
|
11
|
-
def_node_matcher :model_save
|
11
|
+
def_node_matcher :model_save?, <<-MATCHER
|
12
12
|
(send _ :save)
|
13
13
|
MATCHER
|
14
14
|
|
15
15
|
def on_send(node)
|
16
|
-
return unless model_save(node)
|
16
|
+
return unless model_save?(node)
|
17
17
|
add_offense(node, location: :selector, message: MSG)
|
18
18
|
end
|
19
19
|
|
data/rubocop-sequel.gemspec
CHANGED
@@ -13,14 +13,14 @@ 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.0.
|
16
|
+
gem.version = '0.0.6'
|
17
17
|
|
18
|
-
gem.add_runtime_dependency 'rubocop', '~> 0.
|
18
|
+
gem.add_runtime_dependency 'rubocop', '~> 0.55', '>= 0.55'
|
19
19
|
|
20
|
-
gem.add_development_dependency 'rake', '~> 12.
|
21
|
-
gem.add_development_dependency 'rspec', '~> 3.
|
22
|
-
gem.add_development_dependency 'rubocop-rspec', '~> 1.
|
20
|
+
gem.add_development_dependency 'rake', '~> 12.3.0', '>= 12.0.0'
|
21
|
+
gem.add_development_dependency 'rspec', '~> 3.7', '>= 3.7.0'
|
22
|
+
gem.add_development_dependency 'rubocop-rspec', '~> 1.25.0', '>= 1.25.0'
|
23
23
|
gem.add_development_dependency 'sequel', '~> 4.49', '>= 4.49.0'
|
24
|
-
gem.add_development_dependency 'simplecov', '~> 0.
|
24
|
+
gem.add_development_dependency 'simplecov', '~> 0.16'
|
25
25
|
gem.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.12'
|
26
26
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RuboCop::Cop::Sequel::JSONColumn do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
context 'with add_column' do
|
9
|
+
it 'registers an offense when using json type' do
|
10
|
+
inspect_source('add_column(:products, :type, :json)')
|
11
|
+
expect(cop.offenses.size).to eq(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'registers an offense when using hstore type' do
|
15
|
+
inspect_source('add_column(:products, :type, :hstore)')
|
16
|
+
expect(cop.offenses.size).to eq(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'does not register an offense when using jsonb' do
|
20
|
+
inspect_source('add_column(:products, :type, :jsonb)')
|
21
|
+
expect(cop.offenses).to be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with create_table' do
|
26
|
+
it 'registers an offense when using json as a method' do
|
27
|
+
inspect_source('create_table(:products) { json :type, default: {} }')
|
28
|
+
expect(cop.offenses.size).to eq(1)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'registers an offense when using the column method with hstore' do
|
32
|
+
inspect_source('create_table(:products) { column :type, :hstore }')
|
33
|
+
expect(cop.offenses.size).to eq(1)
|
34
|
+
end
|
35
|
+
|
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(cop.offenses).to be_empty
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'does not register an offense when using jsonb' do
|
42
|
+
inspect_source('create_table(:products) { jsonb :type }')
|
43
|
+
expect(cop.offenses).to be_empty
|
44
|
+
end
|
45
|
+
|
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(cop.offenses).to be_empty
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
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.0.
|
4
|
+
version: 0.0.6
|
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: 2018-
|
11
|
+
date: 2018-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -16,27 +16,27 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.55'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '0.
|
22
|
+
version: '0.55'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0.
|
29
|
+
version: '0.55'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '0.
|
32
|
+
version: '0.55'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rake
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 12.
|
39
|
+
version: 12.3.0
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 12.0.0
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 12.
|
49
|
+
version: 12.3.0
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: 12.0.0
|
@@ -56,40 +56,40 @@ dependencies:
|
|
56
56
|
requirements:
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: '3.
|
59
|
+
version: '3.7'
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 3.
|
62
|
+
version: 3.7.0
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '3.
|
69
|
+
version: '3.7'
|
70
70
|
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: 3.
|
72
|
+
version: 3.7.0
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: rubocop-rspec
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
77
|
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: 1.
|
79
|
+
version: 1.25.0
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.
|
82
|
+
version: 1.25.0
|
83
83
|
type: :development
|
84
84
|
prerelease: false
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 1.
|
89
|
+
version: 1.25.0
|
90
90
|
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
|
-
version: 1.
|
92
|
+
version: 1.25.0
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: sequel
|
95
95
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,14 +116,14 @@ dependencies:
|
|
116
116
|
requirements:
|
117
117
|
- - "~>"
|
118
118
|
- !ruby/object:Gem::Version
|
119
|
-
version: '0.
|
119
|
+
version: '0.16'
|
120
120
|
type: :development
|
121
121
|
prerelease: false
|
122
122
|
version_requirements: !ruby/object:Gem::Requirement
|
123
123
|
requirements:
|
124
124
|
- - "~>"
|
125
125
|
- !ruby/object:Gem::Version
|
126
|
-
version: '0.
|
126
|
+
version: '0.16'
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
128
|
name: sqlite3
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
@@ -161,13 +161,14 @@ files:
|
|
161
161
|
- lib/rubocop-sequel.rb
|
162
162
|
- lib/rubocop/cop/sequel/column_default.rb
|
163
163
|
- lib/rubocop/cop/sequel/concurrent_index.rb
|
164
|
+
- lib/rubocop/cop/sequel/json_column.rb
|
164
165
|
- lib/rubocop/cop/sequel/migration_name.rb
|
165
166
|
- lib/rubocop/cop/sequel/save_changes.rb
|
166
167
|
- lib/rubocop/sequel.rb
|
167
168
|
- rubocop-sequel.gemspec
|
168
|
-
- rubocop.yml
|
169
169
|
- spec/rubocop/cop/sequel/column_default_spec.rb
|
170
170
|
- spec/rubocop/cop/sequel/concurrent_index_spec.rb
|
171
|
+
- spec/rubocop/cop/sequel/json_column_spec.rb
|
171
172
|
- spec/rubocop/cop/sequel/migration_name_spec.rb
|
172
173
|
- spec/rubocop/cop/sequel/save_changes_spec.rb
|
173
174
|
- spec/spec_helper.rb
|
@@ -198,6 +199,7 @@ summary: A plugin for the RuboCop code style & linting tool.
|
|
198
199
|
test_files:
|
199
200
|
- spec/rubocop/cop/sequel/column_default_spec.rb
|
200
201
|
- spec/rubocop/cop/sequel/concurrent_index_spec.rb
|
202
|
+
- spec/rubocop/cop/sequel/json_column_spec.rb
|
201
203
|
- spec/rubocop/cop/sequel/migration_name_spec.rb
|
202
204
|
- spec/rubocop/cop/sequel/save_changes_spec.rb
|
203
205
|
- spec/spec_helper.rb
|
data/rubocop.yml
DELETED