Skip to content

Commit e26f2bd

Browse files
committed
scalastyle: capture messages with no line
1 parent fd22a5a commit e26f2bd

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

lib/overcommit/hook/pre_commit/scalastyle.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class Scalastyle < Base
66
MESSAGE_REGEX = /
77
^(?<type>error|warning)\s
88
file=(?<file>(?:\w:)?.+)\s
9-
message=.+\s
10-
line=(?<line>\d+)
9+
message=.+\s*
10+
(line=(?<line>\d+))?
1111
/x
1212

1313
def run

spec/overcommit/hook/pre_commit/scalastyle_spec.rb

+32-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,21 @@
4141
OUT
4242
end
4343

44-
it { should warn }
44+
it { should warn(/Use : Unit = for procedures/) }
45+
end
46+
47+
context 'and it reports a warning with no line' do
48+
before do
49+
result.stub(stderr: '', stdout: normalize_indent(<<-OUT))
50+
warning file=file1.scala message=File must end with newline character
51+
Processed 1 file(s)
52+
Found 0 errors
53+
Found 1 warnings
54+
Finished in 490 ms
55+
OUT
56+
end
57+
58+
it { should warn(/File must end with newline character/) }
4559
end
4660
end
4761

@@ -64,7 +78,21 @@
6478
OUT
6579
end
6680

67-
it { should fail_hook }
81+
it { should fail_hook(/Use : Unit = for procedures/) }
82+
end
83+
84+
context 'and it reports an error with no line' do
85+
before do
86+
result.stub(stderr: '', stdout: normalize_indent(<<-OUT))
87+
error file=file1.scala message=File must end with newline character
88+
Processed 1 file(s)
89+
Found 1 errors
90+
Found 0 warnings
91+
Finished in 490 ms
92+
OUT
93+
end
94+
95+
it { should fail_hook(/File must end with newline character/) }
6896
end
6997

7098
context 'with a usage message' do
@@ -83,7 +111,7 @@
83111
OUT
84112
end
85113

86-
it { should fail_hook }
114+
it { should fail_hook(/Usage/) }
87115
end
88116

89117
context 'with a runtime error' do
@@ -104,7 +132,7 @@
104132
ERR
105133
end
106134

107-
it { should fail_hook }
135+
it { should fail_hook(/Exception/) }
108136
end
109137
end
110138
end

0 commit comments

Comments
 (0)