File tree 2 files changed +15
-6
lines changed
lib/overcommit/hook/pre_commit
spec/overcommit/hook/pre_commit
2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -19,20 +19,17 @@ module Overcommit::Hook::PreCommit
19
19
# @see http://eslint.org/
20
20
class EsLint < Base
21
21
def run
22
+ eslint_regex = /^(?<file>[^\s ](?:\w :)?[^:]+):[^\d ]+(?<line>\d +).*?(?<type>Error|Warning)/
22
23
result = execute ( command , args : applicable_files )
23
24
output = result . stdout . chomp
24
- messages = output . split ( "\n " ) . grep ( /Warning|Error/ )
25
+ messages = output . split ( "\n " ) . grep ( eslint_regex )
25
26
26
27
return [ :fail , result . stderr ] if messages . empty? && !result . success?
27
28
return :pass if result . success? && output . empty?
28
29
29
30
# example message:
30
31
# 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 } )
36
33
end
37
34
end
38
35
end
Original file line number Diff line number Diff line change 52
52
53
53
it { should warn }
54
54
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
55
67
end
56
68
57
69
context 'when eslint exits unsucessfully' do
You can’t perform that action at this time.
0 commit comments