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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## master

* Add [`Pronto`](https://github.com/mmozuras/pronto) pre-commit hook
* Add [`hadolint`](https://github.com/lukasmartinelli/hadolint) pre-commit hook
* Use the `core.hooksPath` Git configuration option when installing hooks

Expand Down
7 changes: 7 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,13 @@ PreCommit:
install_command: 'pip install pep8'
include: '**/*.py'

Pronto:
enabled: false
description: 'Analyzing with pronto'
required_executable: 'pronto'
install_command: 'gem install pronto'
flags: ['run', '--staged --exit-code']

PuppetLint:
enabled: false
description: 'Analyze with puppet-lint'
Expand Down
21 changes: 21 additions & 0 deletions lib/overcommit/hook/pre_commit/pronto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Overcommit::Hook::PreCommit
# Runs `pronto`
#
# @see https://github.com/mmozuras/pronto
class Pronto < Base
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
type.include?('E') ? :error : :warning
end

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

extract_messages(
result.stdout.split("\n"),
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+) (?<type>[^ ]+)/,
MESSAGE_TYPE_CATEGORIZER,
)
end
end
end
51 changes: 51 additions & 0 deletions spec/overcommit/hook/pre_commit/pronto_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'spec_helper'

describe Overcommit::Hook::PreCommit::Pronto do
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
let(:context) { double('context') }
subject { described_class.new(config, context) }

before do
subject.stub(:applicable_files).and_return(%w[file1.rb file2.rb])
end

context 'when pronto exits successfully' do
before do
result = double('result')
result.stub(:success?).and_return(true)
subject.stub(:execute).and_return(result)
end

it { should pass }
end

context 'when pronto exits unsucessfully' do
let(:result) { double('result') }

before do
result.stub(:success?).and_return(false)
subject.stub(:execute).and_return(result)
end

context 'and it reports an error' do
before do
result.stub(:stdout).and_return([
'file2.rb:10 E: IDENTICAL code found in :iter.',
].join("\n"))
end

it { should fail_hook }
end

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"))
end

it { should warn }
end
end
end