Skip to content

Commit a54ee73

Browse files
committed
Prepare for the new solargraph typecheck format
See castwide/solargraph#1072
1 parent 11838c6 commit a54ee73

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

lib/overcommit/hook/pre_commit/solargraph.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module PreCommit
1010
#
1111
# @see https://github.com/castwide/solargraph
1212
class Solargraph < Base
13-
MESSAGE_REGEX = /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+) - /.freeze
13+
MESSAGE_REGEX = /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+)( -|:) /.freeze
1414

1515
def run
1616
result = execute(command, args: applicable_files)

spec/overcommit/hook/pre_commit/solargraph_spec.rb

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,20 @@
4545
end
4646
end
4747

48+
# Old Solargraph version
4849
context 'when Solargraph exits unsucessfully' do
4950
before do
5051
result.stub(:success?).and_return(false)
5152
subject.stub(:execute).and_return(result)
5253
end
5354

55+
# New Solargraph version (see: https://github.com/castwide/solargraph/pull/1072)
5456
context 'and it reports typechecking issues' do
5557
let(:stdout) do
5658
normalize_indent(<<-MSG)
57-
/home/username/src/solargraph-rails/file1.rb:36 - Unresolved constant Solargraph::Parser::Legacy::NodeChainer
58-
/home/username/src/solargraph-rails/file2.rb:44 - Unresolved call to []
59-
/home/username/src/solargraph-rails/file2.rb:99 - Unresolved call to []
59+
/home/username/src/solargraph-rails/file1.rb:36: Unresolved constant Solargraph::Parser::Legacy::NodeChainer
60+
/home/username/src/solargraph-rails/file2.rb:44: Unresolved call to []
61+
/home/username/src/solargraph-rails/file2.rb:99: Unresolved call to []
6062
Typecheck finished in 8.921023999806494 seconds.
6163
189 problems found in 14 of 16 files.
6264
MSG
@@ -77,13 +79,48 @@
7779
expect(messages.first.line).to eq 36
7880
end
7981
it 'parses and returns error message content' do
80-
msg = '/home/username/src/solargraph-rails/file1.rb:36 - Unresolved constant Solargraph::Parser::Legacy::NodeChainer'
82+
msg = '/home/username/src/solargraph-rails/file1.rb:36: Unresolved constant Solargraph::Parser::Legacy::NodeChainer'
8183
expect(messages.first.content).to eq msg
8284
end
8385
end
8486
end
8587
end
8688

89+
context 'with old solargraph output format' do
90+
context 'and it reports typechecking issues' do
91+
let(:stdout) do
92+
normalize_indent(<<-MSG)
93+
/home/username/src/solargraph-rails/file1.rb:36 - Unresolved constant Solargraph::Parser::Legacy::NodeChainer
94+
/home/username/src/solargraph-rails/file2.rb:44 - Unresolved call to []
95+
/home/username/src/solargraph-rails/file2.rb:99 - Unresolved call to []
96+
Typecheck finished in 8.921023999806494 seconds.
97+
189 problems found in 14 of 16 files.
98+
MSG
99+
end
100+
101+
['', 'unexpected output'].each do |stderr_string|
102+
context "with stderr output of #{stderr_string.inspect}" do
103+
let(:stderr) { stderr_string }
104+
105+
it { should fail_hook }
106+
it 'reports only three errors and assumes stderr is harmless' do
107+
expect(messages.size).to eq 3
108+
end
109+
it 'parses filename' do
110+
expect(messages.first.file).to eq '/home/username/src/solargraph-rails/file1.rb'
111+
end
112+
it 'parses line number of messages' do
113+
expect(messages.first.line).to eq 36
114+
end
115+
it 'parses and returns error message content' do
116+
msg = '/home/username/src/solargraph-rails/file1.rb:36 - Unresolved constant Solargraph::Parser::Legacy::NodeChainer'
117+
expect(messages.first.content).to eq msg
118+
end
119+
end
120+
end
121+
end
122+
end
123+
87124
context 'but it reports no typechecking issues' do
88125
let(:stdout) do
89126
normalize_indent(<<-MSG)

0 commit comments

Comments
 (0)