pre-commit 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pre-commit/checks/jslint_check.rb +45 -0
- data/lib/pre-commit/checks.rb +18 -3
- data/lib/support/jslint/jslint_checker.rb +0 -8
- metadata +5 -12
@@ -0,0 +1,45 @@
|
|
1
|
+
# This (PreCommit) should be a module
|
2
|
+
# ... it should also have a cooler name :P
|
3
|
+
class PreCommit
|
4
|
+
class JslintCheck
|
5
|
+
|
6
|
+
attr_accessor :therubyracer_installed, :type
|
7
|
+
|
8
|
+
def initialize(type = :all)
|
9
|
+
@type = type
|
10
|
+
@therubyracer_installed = check_for_therubyracer_install
|
11
|
+
end
|
12
|
+
|
13
|
+
def should_run?
|
14
|
+
@therubyracer_installed
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
if should_run?
|
19
|
+
run
|
20
|
+
else
|
21
|
+
$stderr.puts 'pre-commit: Skipping JSLint check (to run it: `gem install therubyracer`)'
|
22
|
+
# pretent the check passed and move on
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def run
|
28
|
+
errors = check_to_run.call
|
29
|
+
end
|
30
|
+
|
31
|
+
def check_to_run
|
32
|
+
@type == :all ? JSLintAll : JSLintNew
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def check_for_therubyracer_install
|
38
|
+
require 'v8'
|
39
|
+
@therubyracer_installed = true
|
40
|
+
rescue LoadError
|
41
|
+
@therubyracer_installed = false
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
data/lib/pre-commit/checks.rb
CHANGED
@@ -4,6 +4,7 @@ require 'pre-commit/checks/merge_conflict'
|
|
4
4
|
require 'pre-commit/checks/tabs'
|
5
5
|
require 'pre-commit/checks/console_log'
|
6
6
|
require 'pre-commit/checks/debugger_check'
|
7
|
+
require 'pre-commit/checks/jslint_check'
|
7
8
|
|
8
9
|
class PreCommit
|
9
10
|
|
@@ -27,10 +28,18 @@ class PreCommit
|
|
27
28
|
errors << JSLint.lint_file(file)
|
28
29
|
end
|
29
30
|
|
31
|
+
# JSLint.lint_file returns an array.
|
32
|
+
# Therefore no errors looks like this: [[]]
|
33
|
+
# And errors.empty? returns false
|
34
|
+
errors.flatten!
|
35
|
+
|
30
36
|
if errors.empty?
|
31
37
|
true
|
32
38
|
else
|
33
|
-
puts errors.join("\n")
|
39
|
+
$stderr.puts errors.join("\n")
|
40
|
+
$stderr.puts
|
41
|
+
$stderr.puts 'pre-commit: You can bypass this check using `git commit -n`'
|
42
|
+
$stderr.puts
|
34
43
|
false
|
35
44
|
end
|
36
45
|
}
|
@@ -48,8 +57,8 @@ class PreCommit
|
|
48
57
|
Checks = {
|
49
58
|
:white_space => WhiteSpace,
|
50
59
|
:console_log => ConsoleLog,
|
51
|
-
:js_lint_all =>
|
52
|
-
:js_lint_new =>
|
60
|
+
:js_lint_all => JslintCheck.new(:all),
|
61
|
+
:js_lint_new => JslintCheck.new(:new),
|
53
62
|
:debugger => DebuggerCheck,
|
54
63
|
:tabs => Tabs,
|
55
64
|
:closure_syntax_check => ClosureSyntaxCheck,
|
@@ -61,6 +70,12 @@ class PreCommit
|
|
61
70
|
#
|
62
71
|
# NOTE: The deprecation strategy *may* be just delete it since, we're still
|
63
72
|
# pre 1.0.
|
73
|
+
|
74
|
+
#
|
75
|
+
# Actually, on the deprecation note. This method isn't really the problem.
|
76
|
+
# The problem is the default generated pre-commit hook. It shouldn't have
|
77
|
+
# logic in it. The we have freedom to change the gem implementation however
|
78
|
+
# we want, and nobody is forced to update their pre-commit binary.
|
64
79
|
def self.checks_to_run
|
65
80
|
checks_to_run = `git config pre-commit.checks`.chomp.split(/,\s*/).map(&:to_sym)
|
66
81
|
|
@@ -10,14 +10,6 @@ class JSLint
|
|
10
10
|
LINT_PATH = File.join(File.dirname(__FILE__), "lint.js")
|
11
11
|
|
12
12
|
def self.lint_file(file)
|
13
|
-
begin
|
14
|
-
require 'rubygems'
|
15
|
-
require 'v8'
|
16
|
-
rescue LoadError
|
17
|
-
puts "ERROR: Couldn't load therubyracer, which is needed to run JSLint checks. Install via \"gem install therubyracer\", or disable the JS lint checks."
|
18
|
-
return []
|
19
|
-
end
|
20
|
-
|
21
13
|
errors = []
|
22
14
|
V8::Context.new do |context|
|
23
15
|
context.load(LINT_PATH)
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pre-commit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 5
|
9
|
-
version: 0.1.5
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.6
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Shajith Chacko, Josh Lubaway
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-04-06 00:00:00 -07:00
|
18
14
|
default_executable: pre-commit
|
19
15
|
dependencies: []
|
20
16
|
|
@@ -29,6 +25,7 @@ extra_rdoc_files:
|
|
29
25
|
files:
|
30
26
|
- lib/pre-commit/checks/console_log.rb
|
31
27
|
- lib/pre-commit/checks/debugger_check.rb
|
28
|
+
- lib/pre-commit/checks/jslint_check.rb
|
32
29
|
- lib/pre-commit/checks/merge_conflict.rb
|
33
30
|
- lib/pre-commit/checks/tabs.rb
|
34
31
|
- lib/pre-commit/checks.rb
|
@@ -59,21 +56,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
56
|
requirements:
|
60
57
|
- - ">="
|
61
58
|
- !ruby/object:Gem::Version
|
62
|
-
segments:
|
63
|
-
- 0
|
64
59
|
version: "0"
|
65
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
61
|
none: false
|
67
62
|
requirements:
|
68
63
|
- - ">="
|
69
64
|
- !ruby/object:Gem::Version
|
70
|
-
segments:
|
71
|
-
- 0
|
72
65
|
version: "0"
|
73
66
|
requirements: []
|
74
67
|
|
75
68
|
rubyforge_project:
|
76
|
-
rubygems_version: 1.
|
69
|
+
rubygems_version: 1.5.2
|
77
70
|
signing_key:
|
78
71
|
specification_version: 3
|
79
72
|
summary: What this thing does
|