Skip to content
Merged
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
10 changes: 7 additions & 3 deletions lib/overcommit/hook/shared/pronto.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# frozen_string_literal: true

module Overcommit::Hook::Shared
# Shared code used by all Pronto hooks. Runs pronto linter.
# Shared code used by all Pronto hooks. Runs pronto linters.

# @see https://github.com/prontolabs/pronto
module Pronto
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
type.include?('E') ? :error : :warning
end

MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+) (?<type>[^ ]+)/.freeze

def run
result = execute(command)
return :pass if result.success?

extract_messages(
result.stdout.split("\n"),
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+) (?<type>[^ ]+)/,
result.stdout.split("\n").select { |line| line.match?(MESSAGE_REGEX) },
MESSAGE_REGEX,
MESSAGE_TYPE_CATEGORIZER,
)
end
Expand Down
13 changes: 9 additions & 4 deletions spec/overcommit/hook/pre_commit/pronto_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@

context 'and it reports a warning' do
before do
result.stub(:stdout).and_return([
'file1.rb:12 W: Line is too long. [107/80]',
'file2.rb:14 I: Prefer single-quoted strings'
].join("\n"))
result.stub(:stdout).and_return <<~MESSAGE
Running Pronto::Rubocop
file1.rb:12 W: Line is too long. [107/80]
file2.rb:14 I: Prefer single-quoted strings

```suggestion
x = 'x'
```
MESSAGE
end

it { should warn }
Expand Down
13 changes: 9 additions & 4 deletions spec/overcommit/hook/pre_push/pronto_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@

context 'and it reports a warning' do
before do
result.stub(:stdout).and_return([
'file1.rb:12 W: Line is too long. [107/80]',
'file2.rb:14 I: Prefer single-quoted strings'
].join("\n"))
result.stub(:stdout).and_return <<~MESSAGE
Running Pronto::Rubocop
file1.rb:12 W: Line is too long. [107/80]
file2.rb:14 I: Prefer single-quoted strings

```suggestion
x = 'x'
```
MESSAGE
end

it { should warn }
Expand Down