puppet-lint-template_file_extension-check 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +57 -0
- data/lib/puppet-lint/plugins/template_file_extension.rb +45 -0
- data/spec/puppet-lint/plugins/puppet-lint-template_file_extension_spec.rb +90 -0
- data/spec/spec_helper.rb +3 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c386f651f5d324b4ef4ee45599cca5e7d12349fe
|
4
|
+
data.tar.gz: 6f3677dfabf9e6a8dd418c8ccba30bafc4791a92
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 358d8b7f6b3877b178061d4914d69cd9fd2cc540f2d2dc382c13f1f1216244833a4d940071ada74569f55afeed4a4e3e67084c023050fd1d6a536aa59651dc30
|
7
|
+
data.tar.gz: cc413fe0da5d88b9008cca8012d7162ae6fb2d54ac4608a1b1e1e404631dac435619c0ca9a0cc2b9157eb43fde1f1c4569ca243074ac6d162c871fe81b6a9b78
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Dean Wilson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# puppet-lint template file extension check
|
2
|
+
|
3
|
+
Extends puppet-lint to ensure all file names used in template and epp
|
4
|
+
functions end with the string '.erb' or '.epp' respectively
|
5
|
+
|
6
|
+
[![Build Status](https://travis-ci.org/deanwilson/puppet-lint-template_file_extension-check.svg?branch=master)](https://travis-ci.org/deanwilson/puppet-lint-template_file_extension-check)
|
7
|
+
|
8
|
+
|
9
|
+
This plugin is an extension of our local style guide and may not suit
|
10
|
+
your own code base. This sample would trigger the `puppet-lint` warning:
|
11
|
+
|
12
|
+
class valid_template_filename {
|
13
|
+
file { '/tmp/templated':
|
14
|
+
content => template('mymodule/single_file.config'),
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
# all template file names should end with .erb
|
19
|
+
|
20
|
+
And this would trigger an EPP (Embedded Puppet) specific warning:
|
21
|
+
|
22
|
+
class epp_multi_templated_file {
|
23
|
+
file { '/tmp/templated':
|
24
|
+
content => epp('mymodule/first_file.epp', 'mymodule/second_file.conf'),
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
# all epp file names should end with .epp
|
29
|
+
|
30
|
+
## Installation
|
31
|
+
|
32
|
+
To use this plugin add the following line to your Gemfile
|
33
|
+
|
34
|
+
gem 'puppet-lint-template_file_extension-check'
|
35
|
+
|
36
|
+
and then run `bundle install`.
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
This plugin provides a new check to `puppet-lint`.
|
41
|
+
|
42
|
+
all template file names should end with .erb
|
43
|
+
|
44
|
+
all epp file names should end with .epp
|
45
|
+
|
46
|
+
## Other puppet-lint plugins
|
47
|
+
|
48
|
+
You can find a list of my `puppet-lint` plugins in the
|
49
|
+
[unixdaemon puppet-lint-plugins](https://github.com/deanwilson/unixdaemon-puppet-lint-plugins) repo.
|
50
|
+
|
51
|
+
### Author
|
52
|
+
|
53
|
+
[Dean Wilson](https://www.unixdaemon.net)
|
54
|
+
|
55
|
+
### License
|
56
|
+
|
57
|
+
* MIT
|
@@ -0,0 +1,45 @@
|
|
1
|
+
PuppetLint.new_check(:template_file_extension) do
|
2
|
+
def check
|
3
|
+
|
4
|
+
template_extensions = {
|
5
|
+
epp: '.epp',
|
6
|
+
template: '.erb',
|
7
|
+
}
|
8
|
+
|
9
|
+
resource_indexes.each do |resource|
|
10
|
+
if resource[:type].value == 'file'
|
11
|
+
resource[:param_tokens].select { |param_token|
|
12
|
+
param_token.value == 'content'
|
13
|
+
}.each do |content_token|
|
14
|
+
|
15
|
+
value_token = content_token.next_code_token.next_code_token
|
16
|
+
|
17
|
+
if matched = value_token.value.match(/^(template|epp)$/)
|
18
|
+
template_function = matched[1]
|
19
|
+
extension = template_extensions[template_function.to_sym]
|
20
|
+
|
21
|
+
current_token = value_token.next_token
|
22
|
+
|
23
|
+
# iterate over all the code tokens until we hit the closing ')'
|
24
|
+
until current_token.type == :RPAREN
|
25
|
+
current_token = current_token.next_code_token
|
26
|
+
|
27
|
+
if current_token.type == :SSTRING && !current_token.value.end_with?(extension)
|
28
|
+
|
29
|
+
warning = "all #{template_function} file names should end with #{extension}"
|
30
|
+
|
31
|
+
notify :warning, {
|
32
|
+
message: warning,
|
33
|
+
line: value_token.line,
|
34
|
+
column: value_token.column,
|
35
|
+
param_token: content_token,
|
36
|
+
value_token: value_token,
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'template_file_extension' do
|
4
|
+
|
5
|
+
##########################
|
6
|
+
# Valid examples
|
7
|
+
##########################
|
8
|
+
|
9
|
+
context 'template function with one valid file name' do
|
10
|
+
let(:code) do
|
11
|
+
<<-EOS
|
12
|
+
class valid_template_filename {
|
13
|
+
file { '/tmp/templated':
|
14
|
+
content => template('mymodule/single_file.erb'),
|
15
|
+
}
|
16
|
+
}
|
17
|
+
EOS
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should not detect any problems' do
|
21
|
+
expect(problems).to have(0).problems
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'epp function with one valid file name' do
|
26
|
+
let(:code) do
|
27
|
+
<<-EOS
|
28
|
+
class valid_epp_template_filename {
|
29
|
+
file { '/tmp/templated':
|
30
|
+
content => epp('mymodule/single_file.epp'),
|
31
|
+
}
|
32
|
+
}
|
33
|
+
EOS
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should not detect any problems' do
|
37
|
+
expect(problems).to have(0).problems
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
##########################
|
43
|
+
# Invalid examples
|
44
|
+
##########################
|
45
|
+
|
46
|
+
let(:template_msg) { 'all template file names should end with .erb' }
|
47
|
+
|
48
|
+
context 'template function with single invalid file name' do
|
49
|
+
let(:code) do
|
50
|
+
<<-EOS
|
51
|
+
class multi_templated_file {
|
52
|
+
file { '/tmp/templated':
|
53
|
+
content => template('mymodule/first_file.erb', 'mymodule/second_file.conf'),
|
54
|
+
}
|
55
|
+
}
|
56
|
+
EOS
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should detect a single problem' do
|
60
|
+
expect(problems).to have(1).problem
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should create a warning' do
|
64
|
+
expect(problems).to contain_warning(template_msg).on_line(3).in_column(24)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
let(:epp_msg) { 'all epp file names should end with .epp' }
|
69
|
+
|
70
|
+
context 'epp function with single invalid file name' do
|
71
|
+
let(:code) do
|
72
|
+
<<-EOS
|
73
|
+
class epp_multi_templated_file {
|
74
|
+
file { '/tmp/templated':
|
75
|
+
content => epp('mymodule/first_file.epp', 'mymodule/second_file.conf'),
|
76
|
+
}
|
77
|
+
}
|
78
|
+
EOS
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should detect a single problem' do
|
82
|
+
expect(problems).to have(1).problem
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should create a warning' do
|
86
|
+
expect(problems).to contain_warning(epp_msg).on_line(3).in_column(24)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppet-lint-template_file_extension-check
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dean Wilson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: puppet-lint
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.1'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 3.5.0
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.5.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec-its
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec-collection_matchers
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rubocop
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.47.1
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.47.1
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rake
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 11.2.0
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 11.2.0
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rspec-json_expectations
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.4'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.4'
|
117
|
+
description: |2
|
118
|
+
Extends puppet-lint to ensure all filenames used in template and epp functions
|
119
|
+
end with the string '.erb' or '.epp' respectively
|
120
|
+
email: dean.wilson@gmail.com
|
121
|
+
executables: []
|
122
|
+
extensions: []
|
123
|
+
extra_rdoc_files: []
|
124
|
+
files:
|
125
|
+
- LICENSE
|
126
|
+
- README.md
|
127
|
+
- lib/puppet-lint/plugins/template_file_extension.rb
|
128
|
+
- spec/puppet-lint/plugins/puppet-lint-template_file_extension_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
homepage: https://github.com/deanwilson/puppet-lint-template_file_extension-check
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.5.2
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: puppet-lint template_file_extension check
|
154
|
+
test_files:
|
155
|
+
- spec/puppet-lint/plugins/puppet-lint-template_file_extension_spec.rb
|
156
|
+
- spec/spec_helper.rb
|
157
|
+
has_rdoc:
|