Skip to content

Commit 339e13e

Browse files
committedJun 26, 2015
Fix and update (semi)standard hooks
* Use stdout instead of stderr * Update regexp to account for space before file path in output * Update tests to mimic latest tool output See sds#231
1 parent f1699ce commit 339e13e

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed
 

‎lib/overcommit/hook/pre_commit/semi_standard.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ module Overcommit::Hook::PreCommit
55
class SemiStandard < Base
66
def run
77
result = execute(command + applicable_files)
8-
output = result.stderr.chomp
8+
output = result.stdout.chomp
99
return :pass if result.success? && output.empty?
1010

1111
# example message:
1212
# path/to/file.js:1:1: Error message (ruleName)
1313
extract_messages(
1414
output.split("\n")[1..-1], # ignore header line
15-
/^(?<file>[^:]+):(?<line>\d+)/
15+
/^\s*(?<file>[^:]+):(?<line>\d+)/
1616
)
1717
end
1818
end

‎lib/overcommit/hook/pre_commit/standard.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ module Overcommit::Hook::PreCommit
55
class Standard < Base
66
def run
77
result = execute(command + applicable_files)
8-
output = result.stderr.chomp
8+
output = result.stdout.chomp
99
return :pass if result.success? && output.empty?
1010

1111
# example message:
1212
# path/to/file.js:1:1: Error message (ruleName)
1313
extract_messages(
1414
output.split("\n")[1..-1], # ignore header line
15-
/^(?<file>[^:]+):(?<line>\d+)/
15+
/^\s*(?<file>[^:]+):(?<line>\d+)/
1616
)
1717
end
1818
end

‎spec/overcommit/hook/pre_commit/semi_standard_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
context 'when semistandard exits successfully' do
1313
before do
1414
result = double('result')
15-
result.stub(success?: true, stderr: '')
15+
result.stub(success?: true, stdout: '')
1616
subject.stub(:execute).and_return(result)
1717
end
1818

@@ -29,9 +29,9 @@
2929

3030
context 'and it reports an error' do
3131
before do
32-
result.stub(:stderr).and_return([
33-
'Error: Code style check failed:',
34-
'file1.js:1:1: Extra semicolon. (eslint/semi)'
32+
result.stub(:stdout).and_return([
33+
'semistandard: Use Semicolons For All! (https://github.com/Flet/semistandard)',
34+
' file1.js:1:1: Extra semicolon. (eslint/semi)'
3535
].join("\n"))
3636
end
3737

‎spec/overcommit/hook/pre_commit/standard_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
context 'when standard exits successfully' do
1313
before do
1414
result = double('result')
15-
result.stub(success?: true, stderr: '')
15+
result.stub(success?: true, stdout: '')
1616
subject.stub(:execute).and_return(result)
1717
end
1818

@@ -29,9 +29,9 @@
2929

3030
context 'and it reports an error' do
3131
before do
32-
result.stub(:stderr).and_return([
33-
'Error: Use JavaScript Standard Style (https://github.com/feross/standard)',
34-
'file1.js:1:1: Extra semicolon. (eslint/semi)'
32+
result.stub(:stdout).and_return([
33+
'standard: Use JavaScript Standard Style (https://github.com/feross/standard)',
34+
' file1.js:1:1: Extra semicolon. (eslint/semi)'
3535
].join("\n"))
3636
end
3737

0 commit comments

Comments
 (0)