git-hooks-helper 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +9 -3
- data/Gemfile.lock +54 -18
- data/README.md +18 -5
- data/TODO +5 -1
- data/git-hooks-helper.gemspec +1 -3
- data/lib/git-hooks-helper/git.rb +3 -3
- data/lib/git-hooks-helper/hook.rb +43 -15
- data/lib/git-hooks-helper/version.rb +1 -1
- data/spec/git_files/no_best_practices.rb +1 -1
- data/spec/git_files/ok.html.slim +4 -0
- data/spec/git_files/ok_best_practices.rb +1 -1
- data/spec/git_files/syntax_error.html.slim +4 -0
- data/spec/git_hooks_helper_spec.rb +29 -1
- metadata +7 -5
data/Gemfile
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
source :rubygems
|
2
2
|
gemspec
|
3
|
-
gem 'rspec'
|
4
|
-
gem 'pry'
|
5
|
-
gem 'rails_best_practices'
|
3
|
+
gem 'rspec', '2.6.0'
|
4
|
+
gem 'pry', '0.9.7.4'
|
5
|
+
gem 'rails_best_practices', '1.7.2'
|
6
|
+
gem 'sexp_processor', '3.0.9'
|
7
|
+
|
8
|
+
group :test do
|
9
|
+
gem 'rails-erb-check', '0.1.0'
|
10
|
+
gem 'slim', '1.1.0'
|
11
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -6,47 +6,83 @@ PATH
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
9
|
+
actionpack (3.2.8)
|
10
|
+
activemodel (= 3.2.8)
|
11
|
+
activesupport (= 3.2.8)
|
12
|
+
builder (~> 3.0.0)
|
13
|
+
erubis (~> 2.7.0)
|
14
|
+
journey (~> 1.0.4)
|
15
|
+
rack (~> 1.4.0)
|
16
|
+
rack-cache (~> 1.2)
|
17
|
+
rack-test (~> 0.6.1)
|
18
|
+
sprockets (~> 2.1.3)
|
19
|
+
activemodel (3.2.8)
|
20
|
+
activesupport (= 3.2.8)
|
21
|
+
builder (~> 3.0.0)
|
22
|
+
activesupport (3.2.8)
|
23
|
+
i18n (~> 0.6)
|
24
|
+
multi_json (~> 1.0)
|
25
|
+
builder (3.0.0)
|
11
26
|
coderay (0.9.8)
|
12
27
|
colored (1.2)
|
13
28
|
diff-lcs (1.1.3)
|
14
|
-
erubis (2.
|
15
|
-
|
16
|
-
i18n (0.
|
29
|
+
erubis (2.7.0)
|
30
|
+
hike (1.2.1)
|
31
|
+
i18n (0.6.0)
|
32
|
+
journey (1.0.4)
|
17
33
|
method_source (0.6.7)
|
18
34
|
ruby_parser (>= 2.3.1)
|
19
|
-
|
35
|
+
multi_json (1.3.6)
|
36
|
+
progressbar (0.9.2)
|
20
37
|
pry (0.9.7.4)
|
21
38
|
coderay (~> 0.9.8)
|
22
39
|
method_source (~> 0.6.7)
|
23
40
|
ruby_parser (>= 2.3.1)
|
24
41
|
slop (~> 2.1.0)
|
25
|
-
|
42
|
+
rack (1.4.1)
|
43
|
+
rack-cache (1.2)
|
44
|
+
rack (>= 0.4)
|
45
|
+
rack-test (0.6.1)
|
46
|
+
rack (>= 1.0)
|
47
|
+
rails-erb-check (0.1.0)
|
48
|
+
actionpack (~> 3.0)
|
49
|
+
rails_best_practices (1.7.2)
|
26
50
|
activesupport
|
27
51
|
colored
|
28
52
|
erubis
|
29
53
|
i18n
|
30
54
|
progressbar
|
31
55
|
sexp_processor
|
32
|
-
rspec (2.
|
33
|
-
rspec-core (~> 2.
|
34
|
-
rspec-expectations (~> 2.
|
35
|
-
rspec-mocks (~> 2.
|
36
|
-
rspec-core (2.
|
37
|
-
rspec-expectations (2.
|
56
|
+
rspec (2.6.0)
|
57
|
+
rspec-core (~> 2.6.0)
|
58
|
+
rspec-expectations (~> 2.6.0)
|
59
|
+
rspec-mocks (~> 2.6.0)
|
60
|
+
rspec-core (2.6.4)
|
61
|
+
rspec-expectations (2.6.0)
|
38
62
|
diff-lcs (~> 1.1.2)
|
39
|
-
rspec-mocks (2.
|
63
|
+
rspec-mocks (2.6.0)
|
40
64
|
ruby_parser (2.3.1)
|
41
65
|
sexp_processor (~> 3.0)
|
42
|
-
sexp_processor (3.0.
|
66
|
+
sexp_processor (3.0.9)
|
67
|
+
slim (1.1.0)
|
68
|
+
temple (~> 0.3.5)
|
69
|
+
tilt (~> 1.3.2)
|
43
70
|
slop (2.1.0)
|
71
|
+
sprockets (2.1.3)
|
72
|
+
hike (~> 1.2)
|
73
|
+
rack (~> 1.0)
|
74
|
+
tilt (~> 1.1, != 1.3.0)
|
75
|
+
temple (0.3.5)
|
76
|
+
tilt (1.3.3)
|
44
77
|
|
45
78
|
PLATFORMS
|
46
79
|
ruby
|
47
80
|
|
48
81
|
DEPENDENCIES
|
49
82
|
git-hooks-helper!
|
50
|
-
pry
|
51
|
-
|
52
|
-
|
83
|
+
pry (= 0.9.7.4)
|
84
|
+
rails-erb-check (= 0.1.0)
|
85
|
+
rails_best_practices (= 1.7.2)
|
86
|
+
rspec (= 2.6.0)
|
87
|
+
sexp_processor (= 3.0.9)
|
88
|
+
slim (= 1.1.0)
|
data/README.md
CHANGED
@@ -2,15 +2,26 @@ Instalation
|
|
2
2
|
-----------
|
3
3
|
gem install git-hooks-helper
|
4
4
|
|
5
|
+
Dependencies
|
6
|
+
------------
|
7
|
+
This gem has will have no dependencies and it will be up to you to provide required and possible dependencies.
|
8
|
+
Possible dependencies are tied to checks you want to use:
|
9
|
+
* check_erb - rails-erb-check
|
10
|
+
* check_slim - slim
|
11
|
+
* check_haml - haml
|
12
|
+
* check_best_practices - rails_best_practices
|
13
|
+
|
14
|
+
|
5
15
|
File clasification
|
6
16
|
------------------
|
7
17
|
|
8
18
|
Most commands use file classes internally or accept type class as a param.
|
9
19
|
File type classes and associated file extensions:
|
10
20
|
|
11
|
-
1. :rb -
|
12
|
-
2. :js -
|
13
|
-
3. :erb -
|
21
|
+
1. :rb - .rb .rake .task .prawn
|
22
|
+
2. :js - .js
|
23
|
+
3. :erb - .erb
|
24
|
+
3. :slim - .slim
|
14
25
|
|
15
26
|
Usage
|
16
27
|
-----
|
@@ -39,8 +50,10 @@ and paste following code:
|
|
39
50
|
# list_files # shows list of all changed files
|
40
51
|
|
41
52
|
# checks
|
42
|
-
check_ruby_syntax # errors when ruby syntax
|
43
|
-
check_erb # errors when ERB syntax
|
53
|
+
check_ruby_syntax # errors when ruby syntax is invalid
|
54
|
+
check_erb # errors when ERB syntax is invalid
|
55
|
+
check_slim # errors when SLIM syntax is invalid
|
56
|
+
check_haml # errors when HAML syntax is invalid
|
44
57
|
check_best_practices # warnings when ruby best practices are violated
|
45
58
|
warning_on "WTF?", "binding.pry", "<<<<<<<" # warnings when any of these texts are present in any commited files
|
46
59
|
warning_on "console.log", "debugger", {:in => [:js]} # warning when any of these texts are present in JS files
|
data/TODO
CHANGED
data/git-hooks-helper.gemspec
CHANGED
@@ -9,9 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ["no@email.com"]
|
10
10
|
s.homepage = "https://github.com/BuGo/git-hooks-helper"
|
11
11
|
s.summary = %q{Small gem to help write simple git hooks}
|
12
|
-
s.description = %q{Gem for creating simple git hooks in ruby.}
|
13
|
-
|
14
|
-
s.rubyforge_project = "git-hooks-helper"
|
12
|
+
s.description = %q{Gem for creating simple pre-commit git hooks in ruby.}
|
15
13
|
|
16
14
|
s.files = `git ls-files`.split("\n")
|
17
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/git-hooks-helper/git.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module GitHooksHelper
|
2
2
|
class Git
|
3
3
|
class << self
|
4
|
-
FILES_TO_WATCH = /(.+\.(e?rb|
|
4
|
+
FILES_TO_WATCH = /(.+\.(e?rb|rake|prawn|haml|coffee|slim|task)|[Rr]akefile)/
|
5
5
|
|
6
6
|
def in_index
|
7
|
-
|
8
|
-
|
7
|
+
all_files = `git diff --cached --name-only --diff-filter=AM HEAD`.split("\n").map(&:chomp)
|
8
|
+
all_files.select{|file| file =~ FILES_TO_WATCH}
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -1,29 +1,33 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require 'git-hooks-helper/result'
|
2
|
+
require 'git-hooks-helper/git'
|
3
|
+
require 'git-hooks-helper/ruby'
|
4
|
+
require 'git-hooks-helper/extensions/string'
|
5
|
+
require 'open3'
|
6
|
+
require 'pry'
|
6
7
|
|
7
8
|
module GitHooksHelper
|
8
9
|
class Hook
|
9
10
|
|
10
|
-
RB_REGEXP
|
11
|
-
ERB_REGEXP
|
12
|
-
JS_REGEXP
|
13
|
-
HAML_REGEXP
|
14
|
-
COFFEE_REGEXP
|
11
|
+
RB_REGEXP = /\.(rb|rake|task|prawn|[Rr]akefile|task)\z/
|
12
|
+
ERB_REGEXP = /\.erb\z/
|
13
|
+
JS_REGEXP = /\.js\z/
|
14
|
+
HAML_REGEXP = /\.haml\z/
|
15
|
+
COFFEE_REGEXP = /\.coffee\z/
|
16
|
+
SLIM_REGEXP = /\.slim\z/
|
15
17
|
|
16
18
|
FILETYPES = {
|
17
19
|
rb: RB_REGEXP,
|
18
20
|
erb: ERB_REGEXP,
|
19
21
|
js: JS_REGEXP,
|
20
22
|
haml: HAML_REGEXP,
|
21
|
-
coffee: COFFEE_REGEXP
|
23
|
+
coffee: COFFEE_REGEXP,
|
24
|
+
slim: SLIM_REGEXP
|
22
25
|
}
|
23
26
|
|
24
27
|
RB_WARNING_REGEXP = /[0-9]+:\s+warning:/
|
25
28
|
HAML_INVALID_REGEXP = /error/
|
26
29
|
ERB_INVALID_REGEXP = /invalid\z/
|
30
|
+
SLIM_INVALID_REGEXP = /invalid1\z/
|
27
31
|
COLOR_REGEXP = /\e\[(\d+)m/
|
28
32
|
|
29
33
|
# Set this to true if you want warnings to stop your commit
|
@@ -35,7 +39,6 @@ module GitHooksHelper
|
|
35
39
|
@changed_files = GitHooksHelper::Git.in_index
|
36
40
|
debug("changed files")
|
37
41
|
debug @changed_files
|
38
|
-
|
39
42
|
instance_eval(&block) if block
|
40
43
|
|
41
44
|
if @result.errors?
|
@@ -131,15 +134,40 @@ module GitHooksHelper
|
|
131
134
|
def check_erb
|
132
135
|
each_changed_file([:erb]) do |file|
|
133
136
|
Open3.popen3("rails-erb-check #{file}") do |stdin, stdout, stderr|
|
134
|
-
|
137
|
+
lines = stdout.read.split("\n")
|
138
|
+
errors = lines.map do |line|
|
139
|
+
if line.gsub(COLOR_REGEXP, '') =~ ERB_INVALID_REGEXP
|
140
|
+
"#{file} => invalid ERB syntax"
|
141
|
+
end
|
142
|
+
end.compact
|
143
|
+
@result.errors.concat errors
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
def check_slim
|
150
|
+
each_changed_file([:slim]) do |file|
|
151
|
+
Open3.popen3("slimrb -c #{file}") do |stdin, stdout, stderr|
|
152
|
+
lines = stderr.read.split("\n")
|
153
|
+
errors = if lines.size > 0
|
154
|
+
# skip last 2 lines from output. There is only trace info.
|
155
|
+
@result.errors << "#{file} => invalid SLIM syntax\n " + lines[0..-3].join("\n ")
|
156
|
+
end
|
135
157
|
end
|
136
158
|
end
|
137
159
|
end
|
138
160
|
|
139
161
|
def check_haml
|
140
162
|
each_changed_file([:haml]) do |file|
|
141
|
-
popen3("haml --check #{file}") do |stdin, stdout, stderr|
|
142
|
-
|
163
|
+
Open3.popen3("haml --check #{file}") do |stdin, stdout, stderr|
|
164
|
+
lines = stderr.read.split("\n")
|
165
|
+
errors = lines.map do |line|
|
166
|
+
if line.gsub(COLOR_REGEXP, '') =~ HAML_INVALID_REGEXP
|
167
|
+
"#{file} => invalid HAML syntax\n #{line}"
|
168
|
+
end
|
169
|
+
end.compact
|
170
|
+
@result.errors.concat errors
|
143
171
|
end
|
144
172
|
end
|
145
173
|
end
|
@@ -85,7 +85,7 @@ describe GitHooksHelper do
|
|
85
85
|
end
|
86
86
|
|
87
87
|
describe "check_erb" do
|
88
|
-
it "should stop
|
88
|
+
it "should stop on syntax error in ERB" do
|
89
89
|
GitHooksHelper::Git.should_receive(:in_index).and_return(["spec/git_files/syntax_error.html.erb"])
|
90
90
|
begin
|
91
91
|
GitHooksHelper.results do
|
@@ -110,6 +110,34 @@ describe GitHooksHelper do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
+
describe 'check_slim' do
|
114
|
+
|
115
|
+
it 'should stop on error in SLIM template' do
|
116
|
+
GitHooksHelper::Git.should_receive(:in_index).and_return(["spec/git_files/syntax_error.html.slim"])
|
117
|
+
begin
|
118
|
+
GitHooksHelper.results do
|
119
|
+
stop_on_warnings
|
120
|
+
check_slim
|
121
|
+
end
|
122
|
+
rescue SystemExit => e
|
123
|
+
$!.status.should eql 1
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should show to error in correct SLIM template' do
|
128
|
+
GitHooksHelper::Git.should_receive(:in_index).and_return(["spec/git_files/ok.html.slim"])
|
129
|
+
begin
|
130
|
+
GitHooksHelper.results do
|
131
|
+
stop_on_warnings
|
132
|
+
check_slim
|
133
|
+
end
|
134
|
+
rescue SystemExit => e
|
135
|
+
$!.status.should eql 0
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
113
141
|
describe "warning_on" do
|
114
142
|
it "should show error when file contains specific text" do
|
115
143
|
GitHooksHelper::Git.should_receive(:in_index).and_return(["spec/git_files/ok.html.erb"])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-hooks-helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-30 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
|
-
description: Gem for creating simple git hooks in ruby.
|
14
|
+
description: Gem for creating simple pre-commit git hooks in ruby.
|
15
15
|
email:
|
16
16
|
- no@email.com
|
17
17
|
executables: []
|
@@ -38,8 +38,10 @@ files:
|
|
38
38
|
- spec/git_files/good_syntax.rb
|
39
39
|
- spec/git_files/no_best_practices.rb
|
40
40
|
- spec/git_files/ok.html.erb
|
41
|
+
- spec/git_files/ok.html.slim
|
41
42
|
- spec/git_files/ok_best_practices.rb
|
42
43
|
- spec/git_files/syntax_error.html.erb
|
44
|
+
- spec/git_files/syntax_error.html.slim
|
43
45
|
- spec/git_hooks_helper_spec.rb
|
44
46
|
- spec/spec_helper.rb
|
45
47
|
homepage: https://github.com/BuGo/git-hooks-helper
|
@@ -61,8 +63,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
63
|
- !ruby/object:Gem::Version
|
62
64
|
version: '0'
|
63
65
|
requirements: []
|
64
|
-
rubyforge_project:
|
65
|
-
rubygems_version: 1.8.
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.10
|
66
68
|
signing_key:
|
67
69
|
specification_version: 3
|
68
70
|
summary: Small gem to help write simple git hooks
|