rubocop-sequel 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7060c587b01d22b660cfabc0ead46e03524b0f51
4
+ data.tar.gz: 59617e179cec66a67b2d051f0dde3170164b4026
5
+ SHA512:
6
+ metadata.gz: acdd32c982d42943d8b0dc806668699b024f56deeafc3c9bb38a3c300d650234209a61721396466c82f989482420c29b6618f0a99733c274882eee7153067773
7
+ data.tar.gz: 39473108b08740593758b370b41848b831d12aea8b44434a433f121ce0315dc035b19b2e6facf6fe52ca15cab15ab73fc3230c96b7e32e800ae0d9e5b038f30b
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .tags
2
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,13 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-12-16 21:46:22 -0800 using RuboCop version 0.46.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
11
+ # URISchemes: http, https
12
+ Metrics/LineLength:
13
+ Max: 88
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubocop-sequel (0.0.1)
5
+ rubocop (~> 0.46, >= 0.46)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.3.0)
11
+ diff-lcs (1.2.5)
12
+ docile (1.1.5)
13
+ json (2.0.2)
14
+ parser (2.3.3.1)
15
+ ast (~> 2.2)
16
+ powerpack (0.1.1)
17
+ rainbow (2.1.0)
18
+ rspec (3.5.0)
19
+ rspec-core (~> 3.5.0)
20
+ rspec-expectations (~> 3.5.0)
21
+ rspec-mocks (~> 3.5.0)
22
+ rspec-core (3.5.4)
23
+ rspec-support (~> 3.5.0)
24
+ rspec-expectations (3.5.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.5.0)
27
+ rspec-mocks (3.5.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.5.0)
30
+ rspec-support (3.5.0)
31
+ rubocop (0.46.0)
32
+ parser (>= 2.3.1.1, < 3.0)
33
+ powerpack (~> 0.1)
34
+ rainbow (>= 1.99.1, < 3.0)
35
+ ruby-progressbar (~> 1.7)
36
+ unicode-display_width (~> 1.0, >= 1.0.1)
37
+ ruby-progressbar (1.8.1)
38
+ sequel (4.41.0)
39
+ simplecov (0.12.0)
40
+ docile (~> 1.1.0)
41
+ json (>= 1.8, < 3)
42
+ simplecov-html (~> 0.10.0)
43
+ simplecov-html (0.10.0)
44
+ sqlite3 (1.3.12)
45
+ unicode-display_width (1.1.2)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ rspec (~> 3.5, >= 3.5.0)
52
+ rubocop-sequel!
53
+ sequel (~> 4.41, >= 4.41.0)
54
+ simplecov (~> 0.12)
55
+ sqlite3 (~> 1.3, >= 1.3.12)
56
+
57
+ BUNDLED WITH
58
+ 1.13.6
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Timothée Peignier <timothee.peignier@tryphon.org>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # RuboCop Sequel
2
+
3
+ Code style checking for Sequel.
4
+
5
+ ## Installation
6
+
7
+ Using the `rubocop-rspec` gem
8
+
9
+ ```bash
10
+ gem install rubocop-sequel
11
+ ```
12
+
13
+ or using bundler by adding in your `Gemfile`
14
+
15
+ ```
16
+ gem 'rubocop-sequel'
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### RuboCop configuration file
22
+
23
+ Add to your `.rubocop.yml`.
24
+
25
+ ```
26
+ require: rubocop-sequel
27
+ ```
28
+
29
+ `rubocop` will now automatically load RuboCop Sequel
30
+ cops alongside with the standard cops.
31
+
32
+ ### Command line
33
+
34
+ ```bash
35
+ rubocop --require rubocop-sequel
36
+ ```
37
+
38
+ ### Rake task
39
+
40
+ ```ruby
41
+ RuboCop::RakeTask.new do |task|
42
+ task.requires << 'rubocop-sequel'
43
+ end
44
+ ```
@@ -0,0 +1,6 @@
1
+ require 'rubocop'
2
+
3
+ require 'rubocop/cop/sequel/column_default'
4
+ require 'rubocop/cop/sequel/concurrent_index'
5
+ require 'rubocop/cop/sequel/migration_name'
6
+ require 'rubocop/cop/sequel/save_changes'
@@ -0,0 +1,18 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Sequel
4
+ # ColumnDefault looks for column creation with a default value.
5
+ class ColumnDefault < Cop
6
+ MSG = "Don't create new column with default values".freeze
7
+
8
+ def_node_matcher :add_column_default, <<-END
9
+ (send _ :add_column ... (hash (pair (sym :default) _)))
10
+ END
11
+
12
+ def on_send(node)
13
+ add_offense(node, :selector, MSG) if add_column_default(node)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Sequel
4
+ # ConcurrentIndex looks for non-concurrent index creation.
5
+ class ConcurrentIndex < Cop
6
+ MSG = 'Prefer creating new index concurrently'.freeze
7
+
8
+ def_node_matcher :add_index, <<-END
9
+ (send _ :add_index $...)
10
+ END
11
+
12
+ def on_send(node)
13
+ add_index(node) do |args|
14
+ add_offense(node, :selector, MSG) if offensive?(args)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def offensive?(args)
21
+ !args.last.hash_type? || !args.last.each_descendant.any? do |n|
22
+ next unless n.sym_type?
23
+ n.children.any? { |s| s == :concurrently }
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Sequel
4
+ # MigrationName looks for migration files named with a default name.
5
+ class MigrationName < Cop
6
+ MSG = 'Migration files should not use default name.'.freeze
7
+
8
+ def investigate(processed_source)
9
+ file_path = processed_source.buffer.name
10
+ return if config.file_to_include?(file_path)
11
+
12
+ return unless filename_bad?(file_path)
13
+
14
+ add_offense(nil, source_range(processed_source.buffer, 1, 0), nil)
15
+ end
16
+
17
+ private
18
+
19
+ def filename_bad?(path)
20
+ basename = File.basename(path)
21
+ basename =~ /#{cop_config.fetch('DefaultName', 'new_migration')}/
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Sequel
4
+ # SaveChanges promotes the use of save_changes.
5
+ class SaveChanges < Cop
6
+ MSG = 'Use `Sequel::Model#save_changes` instead of `Sequel::Model#save`.'.freeze
7
+
8
+ def_node_matcher :model_save, <<-END
9
+ (send _ :save)
10
+ END
11
+
12
+ def on_send(node)
13
+ add_offense(node, :selector, MSG) if model_save(node)
14
+ end
15
+
16
+ def autocorrect(node)
17
+ ->(corrector) { corrector.replace(node.loc.selector, 'save_changes') }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ module RuboCop
2
+ # RuboCop Sequel project namespace
3
+ module Sequel
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ['Timothée Peignier']
5
+ gem.email = ['timothee.peignier@tryphon.org']
6
+ gem.description = 'Code style checking for Sequel'
7
+ gem.summary = 'A plugin for the RuboCop code style & linting tool.'
8
+ gem.homepage = 'http://rubygems.org/gems/rubocop-sequel'
9
+ gem.license = 'MIT'
10
+
11
+ gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = 'rubocop-sequel'
15
+ gem.require_paths = ['lib']
16
+ gem.version = '0.0.1'
17
+
18
+ gem.add_runtime_dependency 'rubocop', '~> 0.46', '>= 0.46'
19
+
20
+ gem.add_development_dependency 'sequel', '~> 4.41', '>= 4.41.0'
21
+ gem.add_development_dependency 'rspec', '~> 3.5', '>= 3.5.0'
22
+ gem.add_development_dependency 'simplecov', '~> 0.12'
23
+ gem.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.12'
24
+ end
data/rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ inherit_from: .rubocop_todo.yml
2
+ AllCops:
3
+ TargetRubyVersion: 2.3
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe RuboCop::Cop::Sequel::ColumnDefault do
4
+ subject(:cop) { described_class.new }
5
+
6
+ it 'registers an offense when setting a default' do
7
+ inspect_source(cop, 'add_column(:products, :type, :text, default: "cop")')
8
+ expect(cop.offenses.size).to eq(1)
9
+ end
10
+
11
+ it 'does not register an offense when not setting a default' do
12
+ inspect_source(cop, 'add_column(:products, :type, :text)')
13
+ expect(cop.offenses).to be_empty
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe RuboCop::Cop::Sequel::ConcurrentIndex do
4
+ subject(:cop) { described_class.new }
5
+
6
+ context 'without the concurrent option' do
7
+ it 'registers an offense without options' do
8
+ inspect_source(cop, 'add_index(:products, :name)')
9
+ expect(cop.offenses.size).to eq(1)
10
+ end
11
+
12
+ it 'registers an offense with other options' do
13
+ inspect_source(cop, 'add_index(:products, :name, unique: true)')
14
+ expect(cop.offenses.size).to eq(1)
15
+ end
16
+
17
+ it 'registers an offense with composite index' do
18
+ inspect_source(cop, 'add_index(:products, :name, unique: true)')
19
+ expect(cop.offenses.size).to eq(1)
20
+ end
21
+ end
22
+
23
+ it 'does not register an offense when using concurrent option' do
24
+ inspect_source(cop, 'add_index(:products, :name, unique: true, concurrently: true)')
25
+ expect(cop.offenses).to be_empty
26
+ end
27
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe RuboCop::Cop::Sequel::MigrationName, :config do
4
+ subject(:cop) { described_class.new(config) }
5
+
6
+ let(:config) do
7
+ RuboCop::Config.new(
8
+ { 'AllCops' => { 'Include' => [] },
9
+ 'Sequel/MigrationName' => cop_config },
10
+ '/some/.rubocop.yml'
11
+ )
12
+ end
13
+
14
+ context 'default configuration' do
15
+ let(:cop_config) { {} }
16
+
17
+ it 'registers an offense when using the default name' do
18
+ inspect_source(cop, '', 'new_migration.rb')
19
+ expect(cop.offenses.size).to eq(1)
20
+ end
21
+
22
+ it 'does not register an offense when using a specific name' do
23
+ inspect_source(cop, '', 'add_index.rb')
24
+ expect(cop.offenses).to be_empty
25
+ end
26
+ end
27
+
28
+ context 'with custom configuration' do
29
+ let(:cop_config) { { 'DefaultName' => 'add_migration' } }
30
+
31
+ it 'registers an offense when using the default name' do
32
+ inspect_source(cop, '', 'add_migration.rb')
33
+ expect(cop.offenses.size).to eq(1)
34
+ end
35
+
36
+ it 'does not register an offense when using a specific name' do
37
+ inspect_source(cop, '', 'add_index.rb')
38
+ expect(cop.offenses).to be_empty
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe RuboCop::Cop::Sequel::SaveChanges do
4
+ subject(:cop) { described_class.new }
5
+
6
+ it 'registers an offense when using save' do
7
+ inspect_source(cop, 'favorite.save')
8
+ expect(cop.offenses.size).to eq(1)
9
+ end
10
+
11
+ it 'does not register an offense when using save_changes' do
12
+ inspect_source(cop, 'favorite.save_changes')
13
+ expect(cop.offenses).to be_empty
14
+ end
15
+
16
+ it 'auto-corrects by using save_changes' do
17
+ new_source = autocorrect_source(cop, 'favorite.save')
18
+ expect(new_source).to eq('favorite.save_changes')
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ require 'rubocop'
2
+ require 'rubocop/rspec/support'
3
+ require 'rubocop-sequel'
4
+
5
+ RSpec.configure do |config|
6
+ # rspec-expectations config goes here. You can use an alternate
7
+ # assertion/expectation library such as wrong or the stdlib/minitest
8
+ # assertions if you prefer.
9
+ config.expect_with :rspec do |expectations|
10
+ # This option will default to `true` in RSpec 4. It makes the `description`
11
+ # and `failure_message` of custom matchers include text for helper methods
12
+ # defined using `chain`, e.g.:
13
+ # be_bigger_than(2).and_smaller_than(4).description
14
+ # # => "be bigger than 2 and smaller than 4"
15
+ # ...rather than:
16
+ # # => "be bigger than 2"
17
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
18
+ end
19
+
20
+ # rspec-mocks config goes here. You can use an alternate test double
21
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
22
+ config.mock_with :rspec do |mocks|
23
+ # Prevents you from mocking or stubbing a method that does not exist on
24
+ # a real object. This is generally recommended, and will default to
25
+ # `true` in RSpec 4.
26
+ mocks.verify_partial_doubles = true
27
+ end
28
+
29
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
30
+ # have no way to turn it off -- the option exists only for backwards
31
+ # compatibility in RSpec 3). It causes shared context metadata to be
32
+ # inherited by the metadata hash of host groups and examples, rather than
33
+ # triggering implicit auto-inclusion in groups with matching metadata.
34
+ config.shared_context_metadata_behavior = :apply_to_host_groups
35
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-sequel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Timothée Peignier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.46'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '0.46'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.46'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0.46'
33
+ - !ruby/object:Gem::Dependency
34
+ name: sequel
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '4.41'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 4.41.0
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '4.41'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 4.41.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.5'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.5.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.5'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.5.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: simplecov
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.12'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '0.12'
87
+ - !ruby/object:Gem::Dependency
88
+ name: sqlite3
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '1.3'
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.12
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 1.3.12
107
+ description: Code style checking for Sequel
108
+ email:
109
+ - timothee.peignier@tryphon.org
110
+ executables: []
111
+ extensions: []
112
+ extra_rdoc_files: []
113
+ files:
114
+ - ".gitignore"
115
+ - ".rspec"
116
+ - ".rubocop_todo.yml"
117
+ - Gemfile
118
+ - Gemfile.lock
119
+ - LICENSE
120
+ - README.md
121
+ - lib/rubocop-sequel.rb
122
+ - lib/rubocop/cop/sequel/column_default.rb
123
+ - lib/rubocop/cop/sequel/concurrent_index.rb
124
+ - lib/rubocop/cop/sequel/migration_name.rb
125
+ - lib/rubocop/cop/sequel/save_changes.rb
126
+ - lib/rubocop/sequel.rb
127
+ - rubocop-sequel.gemspec
128
+ - rubocop.yml
129
+ - spec/rubocop/cop/sequel/column_default_spec.rb
130
+ - spec/rubocop/cop/sequel/concurrent_index_spec.rb
131
+ - spec/rubocop/cop/sequel/migration_name_spec.rb
132
+ - spec/rubocop/cop/sequel/save_changes_spec.rb
133
+ - spec/spec_helper.rb
134
+ homepage: http://rubygems.org/gems/rubocop-sequel
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.5.2
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: A plugin for the RuboCop code style & linting tool.
158
+ test_files:
159
+ - spec/rubocop/cop/sequel/column_default_spec.rb
160
+ - spec/rubocop/cop/sequel/concurrent_index_spec.rb
161
+ - spec/rubocop/cop/sequel/migration_name_spec.rb
162
+ - spec/rubocop/cop/sequel/save_changes_spec.rb
163
+ - spec/spec_helper.rb