overcommit 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/scripts/gerrit-change-id +1 -1
- data/lib/overcommit.rb +1 -0
- data/lib/overcommit/plugins/pre_commit/css_linter.rb +3 -2
- data/lib/overcommit/plugins/pre_commit/erb_syntax.rb +2 -1
- data/lib/overcommit/plugins/pre_commit/haml_syntax.rb +3 -2
- data/lib/overcommit/plugins/pre_commit/js_console_log.rb +2 -1
- data/lib/overcommit/plugins/pre_commit/js_syntax.rb +4 -1
- data/lib/overcommit/plugins/pre_commit/ruby_syntax.rb +2 -2
- data/lib/overcommit/plugins/pre_commit/scss_lint.rb +2 -1
- data/lib/overcommit/plugins/pre_commit/whitespace.rb +4 -1
- data/lib/overcommit/plugins/pre_commit/yaml_syntax.rb +3 -3
- data/lib/overcommit/staged_file.rb +39 -0
- data/lib/overcommit/version.rb +1 -1
- metadata +3 -2
data/lib/overcommit.rb
CHANGED
@@ -8,9 +8,10 @@ module Overcommit::GitHook
|
|
8
8
|
def run_check
|
9
9
|
return :warn, "Rhino is not installed" unless in_path? 'rhino'
|
10
10
|
|
11
|
-
paths = staged.join(' ')
|
12
|
-
output = `rhino #{CSS_LINTER_PATH} --quiet --format=compact #{paths} | grep 'Error - '`
|
11
|
+
paths = staged.map { |s| s.path }.join(' ')
|
13
12
|
|
13
|
+
output = `rhino #{CSS_LINTER_PATH} --quiet --format=compact #{paths} | grep 'Error - '`
|
14
|
+
staged.each { |s| output = s.filter_string(output) }
|
14
15
|
return (output !~ /Error - (?!Unknown @ rule)/ ? :good : :bad), output
|
15
16
|
end
|
16
17
|
end
|
@@ -14,7 +14,8 @@ module Overcommit::GitHook
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def run_check
|
17
|
-
output = `bundle exec #{ERB_CHECKER} #{staged.join(' ')}`
|
17
|
+
output = `bundle exec #{ERB_CHECKER} #{staged.map{ |file| file.path }.join(' ')}`
|
18
|
+
staged.each { |s| output = s.filter_string(output) }
|
18
19
|
return (output !~ /: compile error$/ ? :good : :bad), output
|
19
20
|
end
|
20
21
|
end
|
@@ -10,14 +10,15 @@ module Overcommit::GitHook
|
|
10
10
|
return :warn, "'haml' gem not installed -- run `gem install haml`"
|
11
11
|
end
|
12
12
|
|
13
|
-
staged.each do |path|
|
13
|
+
staged.map { |s| s.path }.each do |path|
|
14
14
|
begin
|
15
15
|
Haml::Engine.new(File.read(path), :check_syntax => true)
|
16
16
|
rescue Haml::Error => e
|
17
17
|
return :bad, e.message
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
|
+
:good
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -5,11 +5,12 @@ module Overcommit::GitHook
|
|
5
5
|
|
6
6
|
# https://www.pivotaltracker.com/story/show/18119495
|
7
7
|
def run_check
|
8
|
-
paths = staged.join(' ')
|
8
|
+
paths = staged.map { |s| s.path }.join(' ')
|
9
9
|
output = `grep -n -e 'console\\.log' #{paths}`.split("\n").reject do |line|
|
10
10
|
/^\d+:\s*\/\// =~ line || # Skip comments
|
11
11
|
/ALLOW_CONSOLE_LOG/ =~ line # and lines with ALLOW_CONSOLE_LOG
|
12
12
|
end.join("\n")
|
13
|
+
staged.each { |s| output = s.filter_string(output) }
|
13
14
|
return (output.empty? ? :good : :bad), output
|
14
15
|
end
|
15
16
|
end
|
@@ -6,7 +6,10 @@ module Overcommit::GitHook
|
|
6
6
|
def run_check
|
7
7
|
return :warn, 'Need either `jshint` or `rhino` in path' unless runner
|
8
8
|
|
9
|
-
|
9
|
+
paths = staged.map { |s| s.path }.join(' ')
|
10
|
+
output = runner.call(paths).split("\n")
|
11
|
+
staged.each { |s| output = s.filter_string(output) }
|
12
|
+
|
10
13
|
return (output.none? ? :good : :bad), output
|
11
14
|
end
|
12
15
|
|
@@ -7,9 +7,9 @@ module Overcommit::GitHook
|
|
7
7
|
clean = true
|
8
8
|
output = []
|
9
9
|
staged.each do |staged|
|
10
|
-
syntax = `ruby -c #{staged} 2>&1`
|
10
|
+
syntax = `ruby -c #{staged.path} 2>&1`
|
11
11
|
unless $?.success?
|
12
|
-
output += syntax.lines.to_a
|
12
|
+
output += staged.filter_string(syntax).lines.to_a
|
13
13
|
clean = false
|
14
14
|
end
|
15
15
|
end
|
@@ -10,10 +10,11 @@ module Overcommit::GitHook
|
|
10
10
|
return :warn, 'scss-lint not installed -- run `gem install scss-lint`'
|
11
11
|
end
|
12
12
|
|
13
|
-
paths = staged.join(' ')
|
13
|
+
paths = staged.map { |s| s.path }.join(' ')
|
14
14
|
|
15
15
|
output = `scss-lint #{paths} 2>&1`
|
16
16
|
|
17
|
+
staged.each { |s| output = s.filter_string(output) }
|
17
18
|
return (output.empty? ? :good : :bad), output
|
18
19
|
end
|
19
20
|
end
|
@@ -3,8 +3,11 @@ module Overcommit::GitHook
|
|
3
3
|
include HookRegistry
|
4
4
|
|
5
5
|
def run_check
|
6
|
+
paths = staged.map { |s| s.path }.join(' ')
|
7
|
+
|
6
8
|
# Catches hard tabs
|
7
|
-
output = `grep -Inl "\t" #{
|
9
|
+
output = `grep -Inl "\t" #{paths}`
|
10
|
+
staged.each { |s| output = s.filter_string(output) }
|
8
11
|
unless output.empty?
|
9
12
|
return :stop, "Don't use hard tabs:\n#{output}"
|
10
13
|
end
|
@@ -8,11 +8,11 @@ module Overcommit::GitHook
|
|
8
8
|
def run_check
|
9
9
|
clean = true
|
10
10
|
output = []
|
11
|
-
staged.each do |
|
11
|
+
staged.each do |staged_file|
|
12
12
|
begin
|
13
|
-
YAML.load_file(path)
|
13
|
+
YAML.load_file(staged_file.path)
|
14
14
|
rescue ArgumentError => e
|
15
|
-
output << "#{e.message} parsing #{path}"
|
15
|
+
output << "#{e.message} parsing #{staged_file.path}"
|
16
16
|
clean = false
|
17
17
|
end
|
18
18
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
# We run syntax checks against the version of the file that is staged in
|
3
|
+
# the index, not the one in the work tree. This class is a simple wrapper
|
4
|
+
# to make working with staged files easier.
|
5
|
+
|
6
|
+
module Overcommit
|
7
|
+
class StagedFile
|
8
|
+
attr_reader :contents
|
9
|
+
|
10
|
+
def initialize path
|
11
|
+
@original_path = path
|
12
|
+
@tempfile = Tempfile.new([path.gsub('/', '_'), File.extname(path)])
|
13
|
+
self.contents = `git show :#{@original_path}`
|
14
|
+
end
|
15
|
+
|
16
|
+
# Given error output from a syntax checker, replace references to the
|
17
|
+
# temporary file path with the original path.
|
18
|
+
def filter_string string
|
19
|
+
string.gsub(path, @original_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
# The path of the temporary file on disk, suitable for feeding in to a
|
23
|
+
# syntax checker.
|
24
|
+
def path
|
25
|
+
@tempfile.path
|
26
|
+
end
|
27
|
+
|
28
|
+
# Set or overwrite the temporary file's contents.
|
29
|
+
#
|
30
|
+
# This is used by the ERB syntax checker, for example, to compile
|
31
|
+
# the template before checking.
|
32
|
+
def contents=(contents)
|
33
|
+
@contents = contents
|
34
|
+
@tempfile.seek 0
|
35
|
+
@tempfile.write @contents
|
36
|
+
@tempfile.flush
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/overcommit/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: overcommit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- lib/overcommit/installer.rb
|
39
39
|
- lib/overcommit/hook_specific_check.rb
|
40
40
|
- lib/overcommit/reporter.rb
|
41
|
+
- lib/overcommit/staged_file.rb
|
41
42
|
- lib/overcommit/plugins/commit_msg/hard_tabs.rb
|
42
43
|
- lib/overcommit/plugins/commit_msg/russian_novel.rb
|
43
44
|
- lib/overcommit/plugins/commit_msg/release_note.rb
|