Skip to content

Commit f8cd206

Browse files
Dom Corvascetrotzig
Dom Corvasce
authored andcommitted
ESLint pre-commit hook fails if there are problems (#475)
* Fix #458: Overcommit fails if ESLint fails for whatever reason * Add check for bindly_pass option * Delete extra empty line * Return the stderr output along with exit status * Remove bindly_pass option
1 parent 9cbffeb commit f8cd206

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/overcommit/hook/pre_commit/es_lint.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ class EsLint < Base
1919
def run
2020
result = execute(command, args: applicable_files)
2121
output = result.stdout.chomp
22+
messages = output.split("\n").grep(/Warning|Error/)
23+
24+
return [:fail, result.stderr] if messages.empty? && !result.success?
2225
return :pass if result.success? && output.empty?
2326

2427
# example message:
2528
# path/to/file.js: line 1, col 0, Error - Error message (ruleName)
2629
extract_messages(
27-
output.split("\n").grep(/Warning|Error/),
30+
messages,
2831
/^(?<file>(?:\w:)?[^:]+):[^\d]+(?<line>\d+).*?(?<type>Error|Warning)/,
2932
lambda { |type| type.downcase.to_sym }
3033
)

spec/overcommit/hook/pre_commit/es_lint_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@
99
subject.stub(:applicable_files).and_return(%w[file1.js file2.js])
1010
end
1111

12+
context 'when eslint is unable to run' do
13+
let(:result) { double('result') }
14+
15+
before do
16+
result.stub(:stderr).and_return('SyntaxError: Use of const in strict mode.')
17+
result.stub(:stdout).and_return('')
18+
19+
result.stub(:success?).and_return(false)
20+
subject.stub(:execute).and_return(result)
21+
end
22+
23+
it { should fail_hook }
24+
end
25+
1226
context 'when eslint exits successfully' do
1327
let(:result) { double('result') }
1428

0 commit comments

Comments
 (0)