-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc50788
commit 16eded3
Showing
8 changed files
with
104 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ coverage/ | |
pkg/ | ||
.bundle | ||
.idea | ||
.history/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'overcommit/hook/shared/pronto' | ||
|
||
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 | ||
include Overcommit::Hook::Shared::Pronto | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'overcommit/hook/shared/pronto' | ||
|
||
module Overcommit::Hook::PrePush | ||
# Runs `pronto` | ||
# | ||
# @see https://github.com/mmozuras/pronto | ||
class Pronto < Base | ||
include Overcommit::Hook::Shared::Pronto | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Overcommit::Hook::Shared | ||
# Shared code used by all Pronto hooks. Runs pronto linter. | ||
module Pronto | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe Overcommit::Hook::PrePush::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 |