rubocop-migrations 0.1.0

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: 7d3ac1850fba3f2b655f9a83fa59a2b6829f8784
4
+ data.tar.gz: 27977387b8ae9ad1ff2935097064ea2185e89053
5
+ SHA512:
6
+ metadata.gz: 5339bb07962042774e073b4221941d0ca7e0dbb0bd7251d95ce78a6ff07c472b5b80bc78b13b1e206f786bc100df800362a9d13e552c77031b87130d1db71e0c
7
+ data.tar.gz: 64567f026d05c20083c86b0efaa26a33f52b3cf3b1f8c46d17538ce960de73d6f89ebb322c7f83527f0c64c5e017aae09ab58365c153fbe86e781ca534e52be7
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *~
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubocop-migrations.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 enricostano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # RuboCop Migrations
2
+
3
+ Rails migrations analysis as a extension of [RuboCop](https://github.com/bbatsov/rubocop). Heavily inspired by [`rubocop-cask`](https://github.com/caskroom/rubocop-cask) which in turn is inspired by [`rubocop-rspec`](https://github.com/nevir/rubocop-rspec).
4
+
5
+ ## Installation
6
+
7
+ Just install the `rubocop-migrations` gem
8
+
9
+ ```bash
10
+ gem install rubocop-migrations
11
+ ```
12
+
13
+ or if you use bundler put this in your `Gemfile`
14
+
15
+ ```ruby
16
+ gem 'rubocop-migrations'
17
+ ```
18
+
19
+
20
+ ## Usage
21
+
22
+ You need to tell RuboCop to load the Migrations extension. There are three ways to do this:
23
+
24
+ ### RuboCop configuration file
25
+
26
+ Put this into your `.rubocop.yml`:
27
+
28
+ ```yaml
29
+ require: rubocop/migrations
30
+ ```
31
+
32
+ Now you can run `rubocop` and it will automatically load the RuboCop Migrations cops together with the standard cops.
33
+
34
+ ### Command line
35
+
36
+ ```bash
37
+ rubocop --require rubocop/migrations
38
+ ```
39
+
40
+ ## The Cop
41
+
42
+ All cops are located under [`lib/rubocop/cop/migrations`](lib/rubocop/cop/migrations), and contain examples/documentation.
43
+
44
+ In your `.rubocop.yml`, you may treat the Cask cops just like any other cop. For example:
45
+
46
+ ```yaml
47
+ Migrations/RemoveIndex:
48
+ Enabled: false
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
58
+
59
+ For running the spec files, this project depends on RuboCop's spec helpers. This means that in order to run the specs locally, you need a (shallow) clone of the RuboCop repository:
60
+
61
+ ```bash
62
+ git submodule update --init --depth 1 vendor/rubocop
63
+ ```
64
+
65
+ ## License
66
+
67
+ `rubocop-migrations` is MIT licensed. [See the accompanying file](MIT-LICENSE.md) for
68
+ the full text.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rubocop/migrations"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Migrations
4
+ # Removing indexes is dangerous by nature, if the index you remove
5
+ # is used extensively, you could end up with database degradation.
6
+ #
7
+ # This disallow the use of remove_index at all. It is only allowed
8
+ # inside a down method definition. If you actually know what you are doing
9
+ # (usually when the index is not being used) you should explicitly disable
10
+ # the check by adding a ``rubocop:disable Migrations/RemoveIndex`` comment
11
+ # in the offending line
12
+ class RemoveIndex < Cop
13
+ MSG = 'remove_index is disallowed'.freeze
14
+
15
+ def_node_matcher :remove_index_found, '(:send _ :remove_index ...)'
16
+
17
+ def on_send(node)
18
+ remove_index_found(node) do
19
+ node.each_ancestor do |a|
20
+ next unless a.def_type?
21
+ if a.to_s =~ /def :up/ || a.to_s =~ /def :change/
22
+ add_offense(node, :selector, MSG)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubocop'
2
+
3
+ # cops
4
+ require 'rubocop/cop/migrations/remove_index'
@@ -0,0 +1,5 @@
1
+ module Rubocop
2
+ module Migrations
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubocop/migrations/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rubocop-migrations'
8
+ spec.version = Rubocop::Migrations::VERSION
9
+
10
+ spec.authors = %w(enricostano magec)
11
+ spec.email = %w(ocirne.onats@gmail.com joseferper@gmail.com)
12
+
13
+ spec.summary = 'Rails migrations rubocop checks'
14
+ spec.description = 'Performs some checks for migration sanity'
15
+ spec.homepage = 'https://github.com/redbooth/rubocop-migrations'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } # rubocop:disable Metrics/LineLength
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_runtime_dependency 'rubocop', '>= 0.42.0'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.11'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '3.5.0'
28
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-migrations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - enricostano
8
+ - magec
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-09-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rubocop
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 0.42.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 0.42.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.11'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.11'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
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.0
70
+ description: Performs some checks for migration sanity
71
+ email:
72
+ - ocirne.onats@gmail.com
73
+ - joseferper@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/rubocop/cop/migrations/remove_index.rb
88
+ - lib/rubocop/migrations.rb
89
+ - lib/rubocop/migrations/version.rb
90
+ - rubocop-migrations.gemspec
91
+ homepage: https://github.com/redbooth/rubocop-migrations
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.5.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Rails migrations rubocop checks
115
+ test_files: []