fashion-police 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/fashion-police +28 -7
- data/lib/fashion-police.rb +2 -2
- data/spec/fashion_police_spec.rb +1 -0
- 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: 5dab0f8dfe39ff4db5209debc8a2e5daee7ecdf7
|
4
|
+
data.tar.gz: 5e3da2c1c5bce760ef1ecaa55399707362557484
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3049903809914697e748d797e5de6a07f9cecd202d8517abddb1a2e31aa68b2b2842d4ec550efb631bedc0092b0379f0805d20e8a284bf0f96c24b59fd56a3dd
|
7
|
+
data.tar.gz: 4edfd9436aeba99c84d627cb39ba5e2b797fa4aee9f1d5fdd0ff0963020fb4b90c4ea7bcbace0d495c6a3e88128fc45cab9ddac459310fd27f6835f9234a0560
|
data/bin/fashion-police
CHANGED
@@ -4,8 +4,11 @@ require 'rubygems'
|
|
4
4
|
require 'rainbow'
|
5
5
|
require 'fashion-police'
|
6
6
|
|
7
|
+
no_color = ARGV[0] == '--no-color' ? true : false
|
8
|
+
|
7
9
|
@fashion_police = FashionPolice.new
|
8
|
-
|
10
|
+
|
11
|
+
everything_copasetic = true
|
9
12
|
|
10
13
|
unstaged = `git diff --name-only`.split("\n")
|
11
14
|
staged = `git diff --name-only --cached`.split("\n")
|
@@ -13,20 +16,38 @@ staged = `git diff --name-only --cached`.split("\n")
|
|
13
16
|
files = unstaged + staged
|
14
17
|
|
15
18
|
files.each do |filename|
|
19
|
+
next unless filename.match(/\.js$/)
|
16
20
|
begin
|
17
21
|
@fashion_police.investigate(File.read(filename))
|
18
22
|
rescue FashionPolice::BadCode
|
19
|
-
|
20
|
-
|
23
|
+
# FIXME: it's fairly obvious the clunkiness of this block
|
24
|
+
# means I should clean up the design
|
25
|
+
if no_color
|
26
|
+
puts filename
|
27
|
+
else
|
28
|
+
puts filename.color("ff7400")
|
29
|
+
end
|
30
|
+
@fashion_police.errors.each do |element|
|
31
|
+
element.each do |key, value|
|
32
|
+
if no_color
|
33
|
+
puts key.to_s + " " + value
|
34
|
+
else
|
35
|
+
puts key.to_s.color("bf3030") + " " + value.color("ff0000")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
@fashion_police.errors = []
|
40
|
+
everything_copasetic = false
|
21
41
|
end
|
22
42
|
end
|
23
43
|
|
24
|
-
if
|
44
|
+
if everything_copasetic
|
25
45
|
exit(0)
|
26
46
|
else
|
27
|
-
|
28
|
-
|
29
|
-
|
47
|
+
if no_color
|
48
|
+
puts "Commit aborted due to JavaScript style errors."
|
49
|
+
else
|
50
|
+
puts "Commit aborted due to JavaScript style errors.".color("ff9640")
|
30
51
|
end
|
31
52
|
exit(1)
|
32
53
|
end
|
data/lib/fashion-police.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
class FashionPolice
|
2
|
-
|
3
|
-
attr_accessor :rules
|
2
|
+
attr_accessor :errors, :rules
|
4
3
|
|
5
4
|
class SpacesNotTabs
|
6
5
|
def test(string)
|
@@ -69,6 +68,7 @@ class FashionPolice
|
|
69
68
|
class SpacesAroundArgumentsInForLoops
|
70
69
|
def test(string)
|
71
70
|
return false if string.match(/for\(\S+\s+[^\)]+\)/)
|
71
|
+
return false if string.match(/for \(\S+\s+/)
|
72
72
|
return true
|
73
73
|
end
|
74
74
|
|
data/spec/fashion_police_spec.rb
CHANGED
@@ -266,6 +266,7 @@ describe FashionPolice do
|
|
266
266
|
it "(negative case)" do
|
267
267
|
@rule = FashionPolice::SpacesAroundArgumentsInForLoops.new
|
268
268
|
@rule.test("for(var i=0;i<100;i++) {").should be_false
|
269
|
+
@rule.test("for (i = 0; i < 100; i++) {").should be_false
|
269
270
|
end
|
270
271
|
|
271
272
|
end
|