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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69aee17571a54c11ff77280b89e8406a81254482
4
- data.tar.gz: 949fe6bfe3a0300b8fdf642cbfb5a46f466019d3
3
+ metadata.gz: 5dab0f8dfe39ff4db5209debc8a2e5daee7ecdf7
4
+ data.tar.gz: 5e3da2c1c5bce760ef1ecaa55399707362557484
5
5
  SHA512:
6
- metadata.gz: 027c4f5c35d091e8fb644aa1b4e03b0176205f21fadaeedd1386e859668b35e89b4cbe6f9c6b8d26c6084b50d5bddfab3c78496d9d60a1965fa146a2c3d462de
7
- data.tar.gz: f45d73029cb1e62e62f76793dc799cca48afe49a203b1658aff24d7d72fb1f34ae633ec0b34f4c66d3a0cf21e91b0ee3ce84d1a767d64002e4c91ee1f553480b
6
+ metadata.gz: 3049903809914697e748d797e5de6a07f9cecd202d8517abddb1a2e31aa68b2b2842d4ec550efb631bedc0092b0379f0805d20e8a284bf0f96c24b59fd56a3dd
7
+ data.tar.gz: 4edfd9436aeba99c84d627cb39ba5e2b797fa4aee9f1d5fdd0ff0963020fb4b90c4ea7bcbace0d495c6a3e88128fc45cab9ddac459310fd27f6835f9234a0560
@@ -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
- errors = []
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
- errors << filename.background(:red)
20
- errors << @fashion_police.errors.collect {|element| element.to_s.foreground(:red) }
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 errors.empty?
44
+ if everything_copasetic
25
45
  exit(0)
26
46
  else
27
- puts "JavaScript style errors!".foreground(:red)
28
- errors.each do |error|
29
- puts error
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
@@ -1,6 +1,5 @@
1
1
  class FashionPolice
2
- attr_reader :errors
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
 
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fashion-police
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giles Bowkett