pre-commit 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@ require 'pre-commit/checks/debugger_check'
7
7
  require 'pre-commit/checks/jslint_check'
8
8
  require 'pre-commit/checks/jshint_check'
9
9
  require 'pre-commit/checks/migration_check'
10
+ require 'pre-commit/checks/ci_check'
10
11
 
11
12
  class PreCommit
12
13
 
@@ -34,7 +35,8 @@ class PreCommit
34
35
  :tabs => Tabs,
35
36
  :closure_syntax_check => ClosureSyntaxCheck,
36
37
  :merge_conflict => MergeConflict,
37
- :migrations => MigrationCheck.new
38
+ :migrations => MigrationCheck.new,
39
+ :ci => CiCheck.new
38
40
  }
39
41
 
40
42
  # Can not delete this method with out a deprecation strategy.
@@ -0,0 +1,47 @@
1
+ class CiCheck
2
+
3
+ CI_TASK_NAME = 'pre_commit:ci'
4
+
5
+ def call
6
+ if rakefile_present? && has_ci_task?
7
+ run
8
+ else
9
+ $stderr.puts "pre-commit: skipping ci check. The `#{CI_TASK_NAME}` task is not defined."
10
+
11
+ # pretend the check passed and move on
12
+ true
13
+ end
14
+ end
15
+
16
+ def run
17
+ if tests_passed?
18
+ true
19
+ else
20
+ $stderr.puts 'pre-commit: your test suite has failed'
21
+ $stderr.puts "for the full output run `#{CI_TASK_NAME}`"
22
+ $stderr.puts
23
+
24
+ false
25
+ end
26
+ end
27
+
28
+ def tests_passed?
29
+ system("rake #{CI_TASK_NAME} --silent")
30
+ end
31
+
32
+ def rakefile_present?
33
+ ['rakefile', 'Rakefile', 'rakefile.rb', 'Rakefile.rb'].any? do |file|
34
+ File.exist?(file)
35
+ end
36
+ end
37
+
38
+ def has_ci_task?
39
+ require 'rake'
40
+ Rake.application.init
41
+ Rake.application.load_rakefile
42
+ Rake::Task.task_defined?(CI_TASK_NAME)
43
+ rescue LoadError
44
+ $stderr.puts 'pre-commit: rake not found, skipping ci check'
45
+ end
46
+
47
+ end
@@ -11,9 +11,20 @@ class PreCommit
11
11
  Utils.staged_files('.').split(" ")
12
12
  end
13
13
 
14
+ def config
15
+ config_file = ENV['JSHINT_CONFIG']
16
+ config_file ||= File.exists?(".jshintrc") ? ".jshintrc" : nil
17
+
18
+ if config_file
19
+ ExecJS.exec("return (#{File.read(config_file)});")
20
+ else
21
+ {}
22
+ end
23
+ end
24
+
14
25
  def run_check(file)
15
26
  context = ExecJS.compile(File.read(linter_src))
16
- if !(context.call('JSHINT', File.read(file)))
27
+ if !(context.call('JSHINT', File.read(file), config))
17
28
  context.exec('return JSHINT.errors;')
18
29
  else
19
30
  []
@@ -9,7 +9,24 @@ class MergeConflict
9
9
  end
10
10
 
11
11
  def run
12
- !system("grep '<<<<<<<' #{staged_files}")
12
+ if detected_bad_code?
13
+ $stderr.puts 'pre-commit: detected a merge conflict'
14
+ $stderr.puts errors
15
+ $stderr.puts
16
+ $stderr.puts 'pre-commit: You can bypass this check using `git commit -n`'
17
+ $stderr.puts
18
+ false
19
+ else
20
+ true
21
+ end
22
+ end
23
+
24
+ def detected_bad_code?
25
+ system("grep '<<<<<<<' #{staged_files} --quiet")
26
+ end
27
+
28
+ def errors
29
+ `grep -nH '<<<<<<<' #{staged_files}`
13
30
  end
14
31
 
15
32
  end
@@ -9,7 +9,16 @@ class Tabs
9
9
  def self.call
10
10
  check = new
11
11
  check.staged_files = Utils.staged_files('*')
12
- check.run
12
+ result = check.run
13
+
14
+ if !result
15
+ $stderr.puts check.error_message
16
+ $stderr.puts
17
+ $stderr.puts 'pre-commit: You can bypass this check using `git commit -n`'
18
+ $stderr.puts
19
+ end
20
+
21
+ result
13
22
  end
14
23
 
15
24
  def run
@@ -22,9 +31,6 @@ class Tabs
22
31
  @error_message = "pre-commit: detected tab before initial space:\n"
23
32
  @error_message += violations
24
33
 
25
- $stderr.puts @error_message
26
- $stderr.puts
27
-
28
34
  @passed = false
29
35
  else
30
36
  @passed = true
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pre-commit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 12
10
- version: 0.1.12
5
+ version: 0.1.13
11
6
  platform: ruby
12
7
  authors:
13
8
  - Shajith Chacko, Josh Lubaway
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-06-03 00:00:00 -07:00
13
+ date: 2011-06-29 00:00:00 -07:00
19
14
  default_executable: pre-commit
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,9 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
24
  version: "0"
33
25
  type: :runtime
34
26
  version_requirements: *id001
@@ -42,6 +34,7 @@ extra_rdoc_files:
42
34
  - README.md
43
35
  files:
44
36
  - lib/pre-commit/base.rb
37
+ - lib/pre-commit/checks/ci_check.rb
45
38
  - lib/pre-commit/checks/console_log.rb
46
39
  - lib/pre-commit/checks/debugger_check.rb
47
40
  - lib/pre-commit/checks/js_check.rb
@@ -78,18 +71,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
71
  requirements:
79
72
  - - ">="
80
73
  - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
83
- - 0
84
74
  version: "0"
85
75
  required_rubygems_version: !ruby/object:Gem::Requirement
86
76
  none: false
87
77
  requirements:
88
78
  - - ">="
89
79
  - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
80
  version: "0"
94
81
  requirements: []
95
82