Skip to content

Commit 3d5c5db

Browse files
author
adam
authored
dont capture false positives (sds#744)
1 parent 6b25f5d commit 3d5c5db

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/overcommit/hook/pre_commit/es_lint.rb

+3-6
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,17 @@ module Overcommit::Hook::PreCommit
1919
# @see http://eslint.org/
2020
class EsLint < Base
2121
def run
22+
eslint_regex = /^(?<file>[^\s](?:\w:)?[^:]+):[^\d]+(?<line>\d+).*?(?<type>Error|Warning)/
2223
result = execute(command, args: applicable_files)
2324
output = result.stdout.chomp
24-
messages = output.split("\n").grep(/Warning|Error/)
25+
messages = output.split("\n").grep(eslint_regex)
2526

2627
return [:fail, result.stderr] if messages.empty? && !result.success?
2728
return :pass if result.success? && output.empty?
2829

2930
# example message:
3031
# path/to/file.js: line 1, col 0, Error - Error message (ruleName)
31-
extract_messages(
32-
messages,
33-
/^(?<file>(?:\w:)?[^:]+):[^\d]+(?<line>\d+).*?(?<type>Error|Warning)/,
34-
lambda { |type| type.downcase.to_sym }
35-
)
32+
extract_messages(messages, eslint_regex, lambda { |type| type.downcase.to_sym })
3633
end
3734
end
3835
end

spec/overcommit/hook/pre_commit/es_lint_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@
5252

5353
it { should warn }
5454
end
55+
56+
context 'and it doesnt count false positives error messages' do
57+
before do
58+
result.stub(:stdout).and_return([
59+
'$ yarn eslint --quiet --format=compact /app/project/Error.ts',
60+
'$ /app/project/node_modules/.bin/eslint --quiet --format=compact /app/project/Error.ts',
61+
'',
62+
].join("\n"))
63+
end
64+
65+
it { should pass }
66+
end
5567
end
5668

5769
context 'when eslint exits unsucessfully' do

0 commit comments

Comments
 (0)