File tree 2 files changed +14
-18
lines changed
lib/overcommit/hook/pre_commit
spec/overcommit/hook/pre_commit
2 files changed +14
-18
lines changed Original file line number Diff line number Diff line change 1
1
module Overcommit ::Hook ::PreCommit
2
2
# Runs `haml-lint` against any modified HAML files.
3
3
class HamlLint < Base
4
+ MESSAGE_TYPE_CATEGORIZER = lambda do |type |
5
+ type . include? ( 'W' ) ? :warning : :error
6
+ end
7
+
4
8
def run
5
9
result = execute ( [ executable ] + applicable_files )
6
10
return :pass if result . success?
7
11
8
- # Keep lines from the output for files that we actually modified
9
- error_lines , warning_lines = result . stdout . split ( "\n " ) . partition do |output_line |
10
- if match = output_line . match ( /^([^:]+):(\d +)/ )
11
- file = match [ 1 ]
12
- line = match [ 2 ]
13
- end
14
- modified_lines ( file ) . include? ( line . to_i )
15
- end
16
-
17
- return :fail , error_lines . join ( "\n " ) unless error_lines . empty?
18
-
19
- [ :warn , "Modified files have lints (on lines you didn't modify)\n " <<
20
- warning_lines . join ( "\n " ) ]
12
+ extract_messages (
13
+ result . stdout . split ( "\n " ) ,
14
+ /^(?<file>[^:]+):(?<line>\d +)[^ ]* (?<type>[^ ]+)/ ,
15
+ MESSAGE_TYPE_CATEGORIZER ,
16
+ )
21
17
end
22
18
end
23
19
end
Original file line number Diff line number Diff line change 27
27
subject . stub ( :execute ) . and_return ( result )
28
28
end
29
29
30
- context 'and it reports lines that were not modified by the commit ' do
30
+ context 'and it reports a warning ' do
31
31
before do
32
32
result . stub ( :stdout ) . and_return ( [
33
33
'file1.haml:1 [W] Prefer single quoted strings' ,
34
34
] . join ( "\n " ) )
35
35
36
- subject . stub ( :modified_lines ) . and_return ( [ 2 , 3 ] )
36
+ subject . stub ( :modified_lines_in_file ) . and_return ( [ 2 , 3 ] )
37
37
end
38
38
39
39
it { should warn }
40
40
end
41
41
42
- context 'and it reports lines that were modified by the commit ' do
42
+ context 'and it reports an error ' do
43
43
before do
44
44
result . stub ( :stdout ) . and_return ( [
45
- 'file1.haml:1 [W] Prefer single quoted strings ' ,
45
+ 'file1.haml:1 [E] Unbalanced brackets. ' ,
46
46
] . join ( "\n " ) )
47
47
48
- subject . stub ( :modified_lines ) . and_return ( [ 1 , 2 ] )
48
+ subject . stub ( :modified_lines_in_file ) . and_return ( [ 1 , 2 ] )
49
49
end
50
50
51
51
it { should fail_hook }
You can’t perform that action at this time.
0 commit comments