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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bfe96d66708b6d85a47d781db1c5d08918e3a08
4
- data.tar.gz: 15c09b2c1ee51c81b70b7a55d985fc859dad3b4b
3
+ metadata.gz: 6e42d709c96e2e27bceb516a8be42a2ec3924f7b
4
+ data.tar.gz: c070a92dc2457cd8563a6e874a798ff9b43b0250
5
5
  SHA512:
6
- metadata.gz: b591962b8e5a02ba565f2c6a9b04a3afffa114e929fef420c671f813f1bfc993038b69a0f0b4f6c7d4175a84a8ab6663aa7ca226964608af2d053b826146bf7e
7
- data.tar.gz: bc0257ff86116bd52e2c6c200ed876d1ef950d3a538b4da64310430877a35affa10e03e1c0d7079a59db4935c34ae07dea5ac623f469308bae8f2f583d28c931
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
@@ -1,2 +1,3 @@
1
1
  require 'bundler/gem_tasks'
2
+ load 'tasks/osm_rubocop.rake'
2
3
  task default: :spec
@@ -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
@@ -0,0 +1,7 @@
1
+ module Osm
2
+ module Rubocop
3
+ class Railtie < Rails::Railtie
4
+ rake_tasks { load 'tasks/osm_rubocop.rake' }
5
+ end
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  module Osm
2
2
  module Rubocop
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.1.2'.freeze
4
4
  end
5
5
  end
data/lib/osm/rubocop.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'osm/rubocop/version'
2
+ require 'osm/rubocop/railtie' if defined?(::Rails::Railtie)
2
3
  require 'rubocop'
3
4
 
4
5
  module Osm
@@ -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.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: