Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/solargraph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module PreCommit
#
# @see https://github.com/castwide/solargraph
class Solargraph < Base
MESSAGE_REGEX = /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+) - /.freeze
MESSAGE_REGEX = /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+)( -|:) /.freeze

def run
result = execute(command, args: applicable_files)
Expand Down
45 changes: 41 additions & 4 deletions spec/overcommit/hook/pre_commit/solargraph_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,20 @@
end
end

# Old Solargraph version
context 'when Solargraph exits unsucessfully' do
before do
result.stub(:success?).and_return(false)
subject.stub(:execute).and_return(result)
end

# New Solargraph version (see: https://github.com/castwide/solargraph/pull/1072)
context 'and it reports typechecking issues' do
let(:stdout) do
normalize_indent(<<-MSG)
/home/username/src/solargraph-rails/file1.rb:36 - Unresolved constant Solargraph::Parser::Legacy::NodeChainer
/home/username/src/solargraph-rails/file2.rb:44 - Unresolved call to []
/home/username/src/solargraph-rails/file2.rb:99 - Unresolved call to []
/home/username/src/solargraph-rails/file1.rb:36: Unresolved constant Solargraph::Parser::Legacy::NodeChainer
/home/username/src/solargraph-rails/file2.rb:44: Unresolved call to []
/home/username/src/solargraph-rails/file2.rb:99: Unresolved call to []
Typecheck finished in 8.921023999806494 seconds.
189 problems found in 14 of 16 files.
MSG
Expand All @@ -77,13 +79,48 @@
expect(messages.first.line).to eq 36
end
it 'parses and returns error message content' do
msg = '/home/username/src/solargraph-rails/file1.rb:36 - Unresolved constant Solargraph::Parser::Legacy::NodeChainer'
msg = '/home/username/src/solargraph-rails/file1.rb:36: Unresolved constant Solargraph::Parser::Legacy::NodeChainer'
expect(messages.first.content).to eq msg
end
end
end
end

context 'with old solargraph output format' do
context 'and it reports typechecking issues' do
let(:stdout) do
normalize_indent(<<-MSG)
/home/username/src/solargraph-rails/file1.rb:36 - Unresolved constant Solargraph::Parser::Legacy::NodeChainer
/home/username/src/solargraph-rails/file2.rb:44 - Unresolved call to []
/home/username/src/solargraph-rails/file2.rb:99 - Unresolved call to []
Typecheck finished in 8.921023999806494 seconds.
189 problems found in 14 of 16 files.
MSG
end

['', 'unexpected output'].each do |stderr_string|
context "with stderr output of #{stderr_string.inspect}" do
let(:stderr) { stderr_string }

it { should fail_hook }
it 'reports only three errors and assumes stderr is harmless' do
expect(messages.size).to eq 3
end
it 'parses filename' do
expect(messages.first.file).to eq '/home/username/src/solargraph-rails/file1.rb'
end
it 'parses line number of messages' do
expect(messages.first.line).to eq 36
end
it 'parses and returns error message content' do
msg = '/home/username/src/solargraph-rails/file1.rb:36 - Unresolved constant Solargraph::Parser::Legacy::NodeChainer'
expect(messages.first.content).to eq msg
end
end
end
end
end

context 'but it reports no typechecking issues' do
let(:stdout) do
normalize_indent(<<-MSG)
Expand Down