osm-rubocop 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -0
- data/Rakefile +1 -0
- data/lib/osm/rubocop/pre-commit.bash +22 -0
- data/lib/osm/rubocop/railtie.rb +7 -0
- data/lib/osm/rubocop/version.rb +1 -1
- data/lib/osm/rubocop.rb +1 -0
- data/lib/tasks/osm_rubocop.rake +30 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e42d709c96e2e27bceb516a8be42a2ec3924f7b
|
4
|
+
data.tar.gz: c070a92dc2457cd8563a6e874a798ff9b43b0250
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 050809daaf6d306943c8da25c62d7cda5dee9faf34a1c0c13edacdfe91b96a313753bd806274ad0c482a82ec5f905679dd662c6d161c3cd09a81313de7f4761d
|
7
|
+
data.tar.gz: 3d3af002fe4b3fc6f1a9377038cdde574bc59536007bd271d619e0e4f95422380ecb81481b16ce0a3a3aaf9d46bf3fbc876ab94de2eb72a84cd1db4563c017b6
|
data/README.md
CHANGED
@@ -20,12 +20,39 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
#### Using osm-rubocop's rubocop configuration
|
24
|
+
|
23
25
|
Add this line to the top of your project's .rubocop.yml:
|
24
26
|
|
25
27
|
```ruby
|
26
28
|
require: osm-rubocop
|
27
29
|
```
|
28
30
|
|
31
|
+
It will make osm-rubocop's configuration the default configuration for running rubocop.
|
32
|
+
|
33
|
+
#### Adding a pre-commit hook
|
34
|
+
|
35
|
+
If your project is a Rails application, add this to your Rakefile (above the call to `load_tasks`):
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require 'osm-rubocop'
|
39
|
+
```
|
40
|
+
|
41
|
+
If your project is not a Rails application, add this to your Rakefile:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
require 'osm-rubocop'
|
45
|
+
load File.join Gem.loaded_specs['osm-rubocop'].full_gem_path, 'lib', 'tasks', 'osm_rubocop.rake'
|
46
|
+
```
|
47
|
+
|
48
|
+
Now you can create a pre-commit hook by running:
|
49
|
+
|
50
|
+
```bash
|
51
|
+
$ rake osm_rubocop:install_precommit_hook
|
52
|
+
```
|
53
|
+
|
54
|
+
This will install a pre-commit hook that will remind you to make sure there are no rubocop violations before each commit.
|
55
|
+
|
29
56
|
## Development
|
30
57
|
|
31
58
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
RED="\\e[31m"
|
3
|
+
NO_COLOR="\\e[0m"
|
4
|
+
# Pre commit messages don't take STDIN from the terminal by default.
|
5
|
+
# (See http://stackoverflow.com/a/10015707/1633753)
|
6
|
+
# The following line overrides that:
|
7
|
+
exec < /dev/tty
|
8
|
+
|
9
|
+
if !(bundle exec rubocop --parallel); then
|
10
|
+
echo -e "$RED"
|
11
|
+
echo -e "Rubocop offenses were found."
|
12
|
+
echo -ne "Do you want to commit anyway? [Y/n] "
|
13
|
+
echo -ne "$NO_COLOR"
|
14
|
+
read input
|
15
|
+
case $input in
|
16
|
+
[Yy] ) exit
|
17
|
+
esac
|
18
|
+
echo -ne "$RED"
|
19
|
+
echo -e "Commit was cancelled due to rubocop offenses."
|
20
|
+
echo -ne "$NO_COLOR"
|
21
|
+
exit 1
|
22
|
+
fi
|
data/lib/osm/rubocop/version.rb
CHANGED
data/lib/osm/rubocop.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
namespace :osm_rubocop do
|
2
|
+
desc 'Install a pre-commit hook that ensures the code adheres to the OSM Rubocop configuration'
|
3
|
+
task :install_precommit_hook do
|
4
|
+
source = File.join(
|
5
|
+
Gem.loaded_specs['osm-rubocop'].full_gem_path,
|
6
|
+
'lib',
|
7
|
+
'osm',
|
8
|
+
'rubocop',
|
9
|
+
'pre-commit.bash'
|
10
|
+
)
|
11
|
+
root = defined?(::Rails.root) ? ::Rails.root : Dir.pwd
|
12
|
+
target = File.join(root, '.git', 'hooks', 'pre-commit')
|
13
|
+
|
14
|
+
# rubocop:disable Rails/SkipsModelValidations
|
15
|
+
# There's a false positive rubocop violation here. See bug at:
|
16
|
+
# https://github.com/bbatsov/rubocop/issues/4260
|
17
|
+
FileUtils.touch target
|
18
|
+
# rubocop:enable Rails/SkipsModelValidations
|
19
|
+
FileUtils.chmod '+x', target
|
20
|
+
|
21
|
+
source_content = File.read source
|
22
|
+
target_content = File.read target
|
23
|
+
|
24
|
+
unless target_content.include? source_content
|
25
|
+
File.open(target, 'a') do |f|
|
26
|
+
f.puts source_content
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osm-rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Betesh
|
@@ -84,7 +84,10 @@ files:
|
|
84
84
|
- config/default.yml
|
85
85
|
- lib/osm-rubocop.rb
|
86
86
|
- lib/osm/rubocop.rb
|
87
|
+
- lib/osm/rubocop/pre-commit.bash
|
88
|
+
- lib/osm/rubocop/railtie.rb
|
87
89
|
- lib/osm/rubocop/version.rb
|
90
|
+
- lib/tasks/osm_rubocop.rake
|
88
91
|
- osm-rubocop.gemspec
|
89
92
|
homepage: https://github.com/on-site/osm-rubocop
|
90
93
|
licenses:
|