rubocop-custom 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -5
- data/lib/rubocop/custom/inject.rb +26 -3
- data/lib/rubocop/custom/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b54804e76ca9710b351f4c146c64f0cbb71aa9d
|
4
|
+
data.tar.gz: 52f8a15356b3b335cd843e5d4862c0fdee41ff02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a495724cb521e2e33d057dd445a551e3079f95bbc658a9d185b537e6f3381bea3609faf18f16f50c930808d328c3891dea518a4a798cf4fe730d7072c907e69
|
7
|
+
data.tar.gz: c581fa00d1a6f3122f87bd58a078b587e3932c1bb8ebd7e870c09374de891f40f0c8847fc6f290c3affb079c4d00ae7005d5c90a31a8d2855ddc60501c3617d5
|
data/README.md
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
# RuboCop Custom
|
2
2
|
|
3
|
-
|
3
|
+
Let's say you work on a few projects and they all have different style preferences. What do you do if those particulars fall outside of those covered by the excellent RuboCop gem?
|
4
4
|
|
5
|
-
|
5
|
+
Extend it, per project, with custom cops.
|
6
6
|
|
7
|
+
## Installation
|
7
8
|
|
8
|
-
In your `Gemfile` (
|
9
|
+
In your `Gemfile` (perhaps in a custom group)
|
9
10
|
|
10
11
|
```
|
11
|
-
gem 'rubocop-custom'
|
12
|
+
gem 'rubocop-custom', require: false
|
12
13
|
```
|
13
14
|
|
14
15
|
And modify your `.rubocop.yml`.
|
@@ -19,4 +20,10 @@ require: rubocop-custom
|
|
19
20
|
|
20
21
|
## Custom Cops
|
21
22
|
|
22
|
-
Make new cops and put them into `spec/cops` and they'll be loaded automatically.
|
23
|
+
Make new cops and put them into `spec/cops`, `app/cops`, or `cops` and they'll be loaded automatically.
|
24
|
+
|
25
|
+
For inspiration, check out [RuboCop's cops](https://github.com/bbatsov/rubocop/tree/master/lib/rubocop/cop) and [RuboCop-rspec's cops](https://github.com/nevir/rubocop-rspec/tree/master/lib/rubocop/cop/rspec).
|
26
|
+
|
27
|
+
## Acknowledgments
|
28
|
+
|
29
|
+
This is entirely derivative of [rubocop-rspec](https://github.com/nevir/rubocop-rspec).
|
@@ -1,10 +1,33 @@
|
|
1
1
|
module Rubocop
|
2
2
|
module Custom
|
3
3
|
def self.inject!
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
root = Rubocop::Custom.project_root
|
5
|
+
return if root.nil?
|
6
|
+
['spec/cops', 'cops', 'app/cops'].each do |subpath|
|
7
|
+
Dir.glob(File.join(root, subpath, '*.rb')).each do |file|
|
8
|
+
require file
|
9
|
+
end
|
7
10
|
end
|
8
11
|
end
|
12
|
+
|
13
|
+
def self.project_root
|
14
|
+
cwd = Dir.pwd
|
15
|
+
depth = 10
|
16
|
+
while depth > 0
|
17
|
+
if Rubocop::Custom.cwd_is_root?(cwd)
|
18
|
+
return cwd
|
19
|
+
else
|
20
|
+
depth -= 1
|
21
|
+
cwd = File.expand_path('..', cwd)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.cwd_is_root?(cwd)
|
28
|
+
%w(Gemfile app).collect do |match|
|
29
|
+
File.exist?(File.join(cwd, match))
|
30
|
+
end.all?
|
31
|
+
end
|
9
32
|
end
|
10
33
|
end
|