File tree Expand file tree Collapse file tree
lib/overcommit/hook/pre_commit
spec/overcommit/hook/pre_commit Expand file tree Collapse file tree Original file line number Diff line number Diff 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
3835end
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments