File tree 6 files changed +73
-27
lines changed
lib/overcommit/hook/pre_commit
spec/overcommit/hook/pre_commit
6 files changed +73
-27
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,9 @@ PreCommit:
58
58
description : ' Analyzing with haml-lint'
59
59
include : ' **/*.haml'
60
60
61
+ HardTabs :
62
+ description : ' Checking for hard tabs'
63
+
61
64
ImageOptim :
62
65
description : ' Checking for optimizable images'
63
66
include :
@@ -87,8 +90,8 @@ PreCommit:
87
90
description : ' Analyzing with scss-lint'
88
91
include : ' **/*.scss'
89
92
90
- Whitespace :
91
- description : ' Checking for invalid whitespace'
93
+ TrailingWhitespace :
94
+ description : ' Checking for trailing whitespace'
92
95
93
96
YamlSyntax :
94
97
description : ' Checking YAML syntax'
Original file line number Diff line number Diff line change
1
+ module Overcommit ::Hook ::PreCommit
2
+ # Checks for hard tabs in files.
3
+ class HardTabs < Base
4
+ def run
5
+ paths = applicable_files . join ( ' ' )
6
+
7
+ # Catches hard tabs
8
+ result = command ( "grep -IHn \" \\ t\" #{ paths } " )
9
+ unless result . stdout . empty?
10
+ return :bad , "Hard tabs detected:\n #{ result . stdout } "
11
+ end
12
+
13
+ :good
14
+ end
15
+ end
16
+ end
Original file line number Diff line number Diff line change
1
+ module Overcommit ::Hook ::PreCommit
2
+ # Checks for trailing whitespace in files.
3
+ class TrailingWhitespace < Base
4
+ def run
5
+ paths = applicable_files . join ( ' ' )
6
+
7
+ result = command ( "grep -IHn \" \\ s$\" #{ paths } " )
8
+ unless result . stdout . empty?
9
+ return :bad , "Trailing whitespace detected:\n #{ result . stdout } "
10
+ end
11
+
12
+ :good
13
+ end
14
+ end
15
+ end
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe Overcommit ::Hook ::PreCommit ::HardTabs do
4
+ let ( :config ) { Overcommit ::ConfigurationLoader . default_configuration }
5
+ let ( :context ) { double ( 'context' ) }
6
+ subject { described_class . new ( config , context ) }
7
+ let ( :staged_file ) { 'filename.txt' }
8
+
9
+ before do
10
+ subject . stub ( :applicable_files ) . and_return ( [ staged_file ] )
11
+ end
12
+
13
+ around do |example |
14
+ repo do
15
+ File . open ( staged_file , 'w' ) { |f | f . write ( contents ) }
16
+ `git add #{ staged_file } `
17
+ example . run
18
+ end
19
+ end
20
+
21
+ context 'when file contains hard tabs' do
22
+ let ( :contents ) { "Some\t hard\t tabs" }
23
+
24
+ it { should fail_check }
25
+ end
26
+
27
+ context 'when file has no hard tabs' do
28
+ let ( :contents ) { 'Just some text' }
29
+
30
+ it { should pass }
31
+ end
32
+ end
Original file line number Diff line number Diff line change 1
1
require 'spec_helper'
2
2
3
- describe Overcommit ::Hook ::PreCommit ::Whitespace do
3
+ describe Overcommit ::Hook ::PreCommit ::TrailingWhitespace do
4
4
let ( :config ) { Overcommit ::ConfigurationLoader . default_configuration }
5
5
let ( :context ) { double ( 'context' ) }
6
6
subject { described_class . new ( config , context ) }
18
18
end
19
19
end
20
20
21
- context 'when file contains hard tabs ' do
22
- let ( :contents ) { " Some\t hard \t tabs" }
21
+ context 'when file contains trailing whitespace ' do
22
+ let ( :contents ) { ' Some trailing whitespace ' }
23
23
24
24
it { should fail_check }
25
25
end
26
26
27
- context 'when file contains trailing whitespace ' do
28
- let ( :contents ) { ' Some trailing whitespace ' }
27
+ context 'when file contains trailing tabs ' do
28
+ let ( :contents ) { " Some trailing tabs \t \t " }
29
29
30
30
it { should fail_check }
31
31
end
You can’t perform that action at this time.
0 commit comments