rubocop_runner 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rubocop.yml +5 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +72 -0
- data/Rakefile +15 -0
- data/bin/console +14 -0
- data/bin/setup +9 -0
- data/lib/rubocop_runner/version.rb +3 -0
- data/lib/rubocop_runner.rb +94 -0
- data/lib/template/pre-commit +11 -0
- data/rubocop_runner.gemspec +30 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4b279ef953a3b18c17aa0119e92144523ba81467
|
4
|
+
data.tar.gz: 6db9d7df701314ee10cb230916fe0443823cdb6f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 186968b18e3bcf626ddc6db422de13f98cbad01d70eaa799a1e3b69888c6e6ed4a3ea8235a81a392958c76bd80c36cec7970c4a04c33b4ee70da07e046077683
|
7
|
+
data.tar.gz: ac2d7150badd6b2bbc2c9a80592eb4feccbb9242266d46d94564032b734b95cb891e8340ec9c0d6b6fa3b83d4c7fdcd4c5da9e2cf16c238e3d5028933bc895b7
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Runtastic
|
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,72 @@
|
|
1
|
+
# RubocopRunner
|
2
|
+
|
3
|
+
This gem provides means of running rubocop including auto-correct on all files
|
4
|
+
which are currently staged in git. This can be easily used as pre-commit hook
|
5
|
+
with the included template.
|
6
|
+
|
7
|
+
If rubocop can fix all detected issues itself via autocorrect it will will do
|
8
|
+
so. The commit will abort in this situation.
|
9
|
+
In case rubocop accepts all code changes the commit continues.
|
10
|
+
|
11
|
+
_Although this gem has no tests it's pretty battle tested and is in use internally since years._
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add these lines to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
group :development do
|
19
|
+
gem 'rubocop_runner', '~> 2.0', require: false
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
To create a rubocop runner pre-commit hook once just run
|
30
|
+
|
31
|
+
```sh
|
32
|
+
ruby -rrubocop_runner -e "RubocopRunner.install"
|
33
|
+
```
|
34
|
+
|
35
|
+
To make it easy for every developer on the project you can also add the following rake task
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
begin
|
39
|
+
require 'rubocop/rake_task'
|
40
|
+
RuboCop::RakeTask.new
|
41
|
+
namespace :rubocop do
|
42
|
+
desc 'Install Rubocop as pre-commit hook'
|
43
|
+
task :install do
|
44
|
+
require 'rubocop_runner'
|
45
|
+
RubocopRunner.install
|
46
|
+
end
|
47
|
+
end
|
48
|
+
rescue LoadError
|
49
|
+
p 'rubocop not installed'
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
## ToDo
|
54
|
+
|
55
|
+
- add the install rake task itself to the gem
|
56
|
+
- add tests
|
57
|
+
- improve gem structure
|
58
|
+
|
59
|
+
## Development
|
60
|
+
|
61
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
62
|
+
|
63
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/runtastic/rubocop_runner.
|
68
|
+
|
69
|
+
## License
|
70
|
+
|
71
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
72
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubocop/rake_task'
|
5
|
+
RuboCop::RakeTask.new
|
6
|
+
namespace :rubocop do
|
7
|
+
desc 'Install Rubocop as pre-commit hook'
|
8
|
+
task :install do
|
9
|
+
require 'rubocop_runner'
|
10
|
+
RubocopRunner.install
|
11
|
+
end
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
p 'rubocop not installed'
|
15
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rubocop_runner'
|
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,94 @@
|
|
1
|
+
require 'rubocop_runner/version'
|
2
|
+
require 'rubocop'
|
3
|
+
|
4
|
+
module RubocopRunner
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# from https://github.com/djberg96/ptools/blob/master/lib/ptools.rb#L90
|
8
|
+
def binary?(file)
|
9
|
+
return true if File.ftype(file) != 'file'
|
10
|
+
s = (File.read(file, File.stat(file).blksize) || '').split(//)
|
11
|
+
((s.size - s.grep(' '..'~').size) / s.size.to_f) > 0.30
|
12
|
+
end
|
13
|
+
|
14
|
+
def staged_files
|
15
|
+
files = `git diff --cached --name-only --diff-filter=ACM`.split
|
16
|
+
files.reject do |f|
|
17
|
+
if File.ftype(f) != 'file'
|
18
|
+
true
|
19
|
+
else
|
20
|
+
size = File.size(f)
|
21
|
+
size > 1_000_000 || (size > 20 && binary?(f))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def merge?
|
27
|
+
File.exist?('.git/MERGE_MSG') && File.exist?('.git/MERGE_HEAD')
|
28
|
+
end
|
29
|
+
|
30
|
+
def conflict_files
|
31
|
+
IO.read('.git/MERGE_MSG')
|
32
|
+
.each_line
|
33
|
+
.select { |e| e.start_with?("\t") }
|
34
|
+
.map(&:strip)
|
35
|
+
end
|
36
|
+
|
37
|
+
def files
|
38
|
+
if merge?
|
39
|
+
conflict_files
|
40
|
+
else
|
41
|
+
staged_files
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
RUBY_PATTERN = /\.(rb|gemspec)$/
|
46
|
+
RUBY_NAMES = %w(Guardfile Gemfile Rakefile config.ru).freeze
|
47
|
+
|
48
|
+
def ruby_file?(filename)
|
49
|
+
RUBY_NAMES.include?(filename) || !(filename =~ RUBY_PATTERN).nil?
|
50
|
+
end
|
51
|
+
|
52
|
+
def staged_ruby_files
|
53
|
+
@ruby_files ||= files.select do |file|
|
54
|
+
!File.directory?(file) && File.exist?(file) && ruby_file?(file)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
DEFAULT_ARGS = %w(--auto-correct
|
59
|
+
--format fuubar
|
60
|
+
--force-exclusion
|
61
|
+
--fail-level autocorrect).freeze
|
62
|
+
def run
|
63
|
+
return 0 if staged_ruby_files.empty?
|
64
|
+
::RuboCop::CLI.new.run(DEFAULT_ARGS + staged_ruby_files)
|
65
|
+
end
|
66
|
+
|
67
|
+
RUBOCOP_RUNNER_HOME =
|
68
|
+
Pathname.new(File.join(File.dirname(__FILE__), '..')).realpath
|
69
|
+
|
70
|
+
def root
|
71
|
+
RUBOCOP_RUNNER_HOME
|
72
|
+
end
|
73
|
+
|
74
|
+
def create_backup(pre_commit_path)
|
75
|
+
return unless File.exist?(pre_commit_path)
|
76
|
+
FileUtils.mv(pre_commit_path,
|
77
|
+
pre_commit_path.join('.bkp'),
|
78
|
+
force: true)
|
79
|
+
end
|
80
|
+
|
81
|
+
def install(root = '.')
|
82
|
+
require 'fileutils'
|
83
|
+
git_root = Pathname.new "#{root}/.git"
|
84
|
+
return false unless File.exist?(git_root)
|
85
|
+
pre_commit_path = git_root.join('hooks', 'pre-commit')
|
86
|
+
create_backup(pre_commit_path)
|
87
|
+
|
88
|
+
pre_commit_template_path = RubocopRunner.root.join('lib',
|
89
|
+
'template',
|
90
|
+
'pre-commit')
|
91
|
+
FileUtils.cp(pre_commit_template_path, pre_commit_path)
|
92
|
+
FileUtils.chmod('+x', pre_commit_path)
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rubocop_runner/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rubocop_runner'
|
8
|
+
spec.version = RubocopRunner::VERSION
|
9
|
+
spec.authors = ['Andreas Eger']
|
10
|
+
spec.email = ['andreas.eger@runtastic.com']
|
11
|
+
spec.summary = 'runs rubocop for all changed files'
|
12
|
+
spec.description = <<-DESC
|
13
|
+
This gem provides means of running rubocop including auto-correct on all
|
14
|
+
files which are currently staged in git. This can be easily used as pre-commit
|
15
|
+
hook with the included template.
|
16
|
+
DESC
|
17
|
+
spec.homepage = 'https://github.com/runtastic/rubocop_runner'
|
18
|
+
spec.license = 'MIT'
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0")
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'rubocop'
|
29
|
+
spec.add_development_dependency 'pry'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop_runner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andreas Eger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: |2
|
70
|
+
This gem provides means of running rubocop including auto-correct on all
|
71
|
+
files which are currently staged in git. This can be easily used as pre-commit
|
72
|
+
hook with the included template.
|
73
|
+
email:
|
74
|
+
- andreas.eger@runtastic.com
|
75
|
+
executables:
|
76
|
+
- console
|
77
|
+
- setup
|
78
|
+
extensions: []
|
79
|
+
extra_rdoc_files: []
|
80
|
+
files:
|
81
|
+
- ".gitignore"
|
82
|
+
- ".rubocop.yml"
|
83
|
+
- Gemfile
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- bin/console
|
88
|
+
- bin/setup
|
89
|
+
- lib/rubocop_runner.rb
|
90
|
+
- lib/rubocop_runner/version.rb
|
91
|
+
- lib/template/pre-commit
|
92
|
+
- rubocop_runner.gemspec
|
93
|
+
homepage: https://github.com/runtastic/rubocop_runner
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.5.2
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: runs rubocop for all changed files
|
117
|
+
test_files: []
|