Skip to content

Commit aeb19c5

Browse files
authored
Merge pull request chriskuehl#11 from pillarsdotnet/master
Add hooks for r10k/g10k and ruby -wc.
2 parents 6723f54 + d73882c commit aeb19c5

File tree

6 files changed

+145
-44
lines changed

6 files changed

+145
-44
lines changed

.pre-commit-hooks.yaml

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,53 @@
1-
- id: puppet-validate
2-
name: Validate Puppet manifests
3-
description: Validate syntax of Puppet manifests
4-
entry: puppet-validate
5-
language: ruby
6-
files: \.pp$
7-
additional_dependencies: ['puppet']
1+
- id: epp-validate
2+
additional_dependencies: ['puppet']
3+
description: Validate syntax of Puppet EPP templates
4+
entry: epp-validate
5+
files: \.epp$
6+
language: ruby
7+
name: Validate EPP templates
88

9-
- id: erb-validate
10-
name: Validate ERB templates
11-
description: Validate syntax of Ruby ERB templates
12-
entry: erb-validate
13-
language: ruby
14-
files: \.erb$
9+
- id: erb-validate
10+
description: Validate syntax of Ruby ERB templates
11+
entry: erb-validate
12+
files: \.erb$
13+
language: ruby
14+
name: Validate ERB templates
1515

16-
- id: epp-validate
17-
name: Validate EPP templates
18-
description: Validate syntax of Puppet EPP templates
19-
entry: epp-validate
20-
language: ruby
21-
files: \.epp$
22-
additional_dependencies: ['puppet']
16+
- id: g10k-validate
17+
description: Validate syntax of Puppetfile using g10k
18+
entry: g10k-validate
19+
files: ^Puppetfile$
20+
language: ruby
21+
name: Validate g10k Puppetfile
2322

24-
- id: puppet-lint
25-
name: puppet-lint
26-
description: Check Puppet manifests for stylistic problems
27-
entry: puppet-lint
28-
language: ruby
29-
files: \.pp$
30-
additional_dependencies: ['puppet-lint']
23+
- id: puppet-lint
24+
additional_dependencies: ['puppet-lint']
25+
description: Check Puppet manifests for stylistic problems
26+
entry: puppet-lint
27+
files: \.pp$
28+
language: ruby
29+
name: puppet-lint
30+
31+
- id: puppet-validate
32+
additional_dependencies: ['puppet']
33+
description: Validate syntax of Puppet manifests
34+
entry: puppet-validate
35+
files: \.pp$
36+
language: ruby
37+
name: Validate Puppet manifests
38+
39+
- id: r10k-validate
40+
additional_dependencies: ['r10k']
41+
description: Validate syntax of Puppetfile using r10k
42+
entry: r10k-validate
43+
files: ^Puppetfile$
44+
language: ruby
45+
name: Validate r10k Puppetfile
46+
47+
- id: ruby-validate
48+
additional_dependencies: ['ruby']
49+
description: Validate syntax of ruby code
50+
entry: ruby-validate
51+
files: \.rb$
52+
language: ruby
53+
name: Validate ruby syntax

README.md

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,32 @@ Puppet pre-commit hooks
55

66
Provides the following hooks:
77

8-
* **puppet-validate:** uses `puppet parser validate` to check the syntax of
9-
Puppet manifests.
8+
* **epp-validate:** validates and syntax-checks [Puppet's epp templates][epp].
9+
10+
* **erb-validate:** compiles and syntax-checks [Ruby erb templates][erb].
11+
12+
* **g10k-validate:** uses [g10k][g10k] to validate [Puppetfile][puppetfile] syntax.
1013

1114
* **puppet-lint:** uses [`puppet-lint`](http://puppet-lint.com/) to check for
12-
stylistic issues with your Puppet manifests.
15+
stylistic issues with Puppet manifests.
1316

14-
* **erb-validate:** compiles and syntax-checks Ruby erb templates.
17+
* **puppet-validate:** uses [`puppet parser validate`][puppet-parser] to check the syntax of
18+
Puppet manifests.
1519

16-
* **epp-validate:** validates and syntax-checks [Puppet's epp templates][epp].
20+
* **r10k-validate:** uses [r10k][r10k] to validate [Puppetfile][puppetfile] syntax.
21+
22+
* **ruby-validate:** uses [`ruby -c`][ruby-c] to validate the syntax of ruby code.
1723

1824

1925
[epp]: https://docs.puppet.com/puppet/latest/lang_template_epp.html
26+
[erb]: https://puppet.com/docs/puppet/latest/lang_template_erb.html
27+
[g10k]: https://github.com/xorpaul/g10k
28+
[puppetfile]: https://puppet.com/docs/pe/latest/puppetfile.html
29+
[puppet-parser]: https://puppet.com/docs/puppet/latest/man/parser.html#EXAMPLES
30+
[r10k]: https://github.com/puppetlabs/r10k
31+
[rubocop]: https://github.com/rubocop-hq/rubocop
32+
[ruby-c]: https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/options.html
33+
[yamllint]: https://github.com/adrienverge/yamllint
2034

2135
## Usage
2236

@@ -26,24 +40,46 @@ Provides the following hooks:
2640
root of your git repository:
2741

2842
```yaml
29-
- repo: https://github.com/chriskuehl/puppet-pre-commit-hooks.git
30-
sha: v2.0.2
31-
hooks:
32-
- id: puppet-validate
33-
- id: erb-validate
34-
- id: epp-validate
35-
- id: puppet-lint
36-
args:
43+
- repo: https://github.com/chriskuehl/puppet-pre-commit-hooks.git
44+
sha: v2.0.2
45+
hooks:
46+
- id: epp-validate
47+
- id: erb-validate
48+
- id: puppet-lint
49+
args:
3750
- --fail-on-warnings
51+
- id: puppet-validate
52+
- id: r10k-validate
53+
- id: ruby-validate
3854
```
3955
4056
You'll almost certainly want to adjust the puppet-lint args for your
4157
project. I find the following most helpful:
4258
4359
```yaml
44-
- --no-80chars-check
45-
- --no-documentation-check
46-
- --no-puppet_url_without_modules-check
60+
- --no-80chars-check
61+
- --no-documentation-check
62+
- --no-puppet_url_without_modules-check
63+
```
64+
65+
To check ruby *style* as well as *syntax*, you may find it useful
66+
to add a hook for [`rubocop`][rubocop]:
67+
68+
```yaml
69+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
70+
rev: 1.11.0
71+
hooks:
72+
- id: reek
73+
- id: rubocop
74+
```
75+
76+
To check yaml syntax, you may want to add a hook for [`yamllint`][yamllint]:
77+
78+
```yaml
79+
- repo: 'https://github.com/adrienverge/yamllint'
80+
rev: v1.15.0
81+
hooks:
82+
- id: 'yamllint'
4783
```
4884

4985
3. Run `pre-commit install` to add pre-commit git hooks.

pre_commit_fake_gem.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ Gem::Specification.new do |s|
66
s.description = 'pre-commit hooks for Puppet projects'
77

88
s.bindir = 'ruby-stubs'
9-
s.executables = ['puppet-validate', 'erb-validate', 'epp-validate']
9+
s.executables = ['erb-validate', 'epp-validate', 'g10k-validate', 'puppet-validate', 'r10k-validate', 'ruby-validate']
1010
end

ruby-stubs/g10k-validate

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'English'
2+
3+
status = 0
4+
ARGV.each do |file|
5+
output = `g10k -dryrun -puppetfile -puppetfilelocation "#{file}" check 2>&1`
6+
next unless output =~ /^Error:/
7+
puts "#{file}: failed g10k validation"
8+
puts output
9+
status = 1
10+
end
11+
12+
exit status
13+
14+
# vim: ft=ruby

ruby-stubs/r10k-validate

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'English'
2+
3+
status = 0
4+
ARGV.each do |file|
5+
output = `(cd $(dirname "#{file}") && r10k puppetfile check 2>&1)`
6+
next if $CHILD_STATUS.exitstatus == 0
7+
puts "#{file}: failed r10k validation"
8+
puts output
9+
status = 1
10+
end
11+
12+
exit status
13+
14+
# vim: ft=ruby

ruby-stubs/ruby-validate

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'English'
2+
3+
status = 0
4+
ARGV.each do |file|
5+
output = `ruby -wc "#{file}" 2>&1`
6+
next if $CHILD_STATUS.exitstatus == 0
7+
puts "#{file}: failed ruby syntax check"
8+
puts output
9+
status = 1
10+
end
11+
12+
exit status
13+
14+
# vim: ft=ruby

0 commit comments

Comments
 (0)