Skip to content

Commit 30c337c

Browse files
mmozurassds
authored andcommitted
Add Pronto pre-commit hook
1 parent 3ed4333 commit 30c337c

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## master
44

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

config/default.yml

+7
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,13 @@ PreCommit:
430430
install_command: 'pip install pep8'
431431
include: '**/*.py'
432432

433+
Pronto:
434+
enabled: false
435+
description: 'Analyzing with pronto'
436+
required_executable: 'pronto'
437+
install_command: 'gem install pronto'
438+
flags: ['run', '--staged --exit-code']
439+
433440
PuppetLint:
434441
enabled: false
435442
description: 'Analyze with puppet-lint'
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Overcommit::Hook::PreCommit
2+
# Runs `pronto`
3+
#
4+
# @see https://github.com/mmozuras/pronto
5+
class Pronto < Base
6+
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
7+
type.include?('E') ? :error : :warning
8+
end
9+
10+
def run
11+
result = execute(command)
12+
return :pass if result.success?
13+
14+
extract_messages(
15+
result.stdout.split("\n"),
16+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+) (?<type>[^ ]+)/,
17+
MESSAGE_TYPE_CATEGORIZER,
18+
)
19+
end
20+
end
21+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PreCommit::Pronto do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
before do
9+
subject.stub(:applicable_files).and_return(%w[file1.rb file2.rb])
10+
end
11+
12+
context 'when pronto exits successfully' do
13+
before do
14+
result = double('result')
15+
result.stub(:success?).and_return(true)
16+
subject.stub(:execute).and_return(result)
17+
end
18+
19+
it { should pass }
20+
end
21+
22+
context 'when pronto exits unsucessfully' do
23+
let(:result) { double('result') }
24+
25+
before do
26+
result.stub(:success?).and_return(false)
27+
subject.stub(:execute).and_return(result)
28+
end
29+
30+
context 'and it reports an error' do
31+
before do
32+
result.stub(:stdout).and_return([
33+
'file2.rb:10 E: IDENTICAL code found in :iter.',
34+
].join("\n"))
35+
end
36+
37+
it { should fail_hook }
38+
end
39+
40+
context 'and it reports a warning' do
41+
before do
42+
result.stub(:stdout).and_return([
43+
'file1.rb:12 W: Line is too long. [107/80]',
44+
'file2.rb:14 I: Prefer single-quoted strings'
45+
].join("\n"))
46+
end
47+
48+
it { should warn }
49+
end
50+
end
51+
end

0 commit comments

Comments
 (0)