puppet-lint-non_erb_template_filename-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 +38 -0
- data/lib/puppet-lint/plugins/non_erb_template_filename.rb +37 -0
- data/spec/puppet-lint/plugins/puppet-lint-non_erb_template_filename_spec.rb +44 -0
- data/spec/spec_helper.rb +3 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df0164452fb5c913b2873aa423338f68bb199357
|
4
|
+
data.tar.gz: c844583061c43b99977337e04ec7f54a0e12ed61
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 778b836787cf8ea8788f3350ab91ef37f50cbb82efbd0314d9b86e5a5dc828f50f8cd16c69ea236d7246f73fff2d941ceba0b04e46356fa9f3f9bce7da56a6f7
|
7
|
+
data.tar.gz: b75a4c5fa0eb22c3d9c7d93139306551dfee7014ef0d7682268faa74265732c5735238e1eae1c72b0b23430c06303d627b523177503a7bd65d73d982bb76c01e
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 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,38 @@
|
|
1
|
+
# puppet-lint non ERB template file name check
|
2
|
+
|
3
|
+
Extends puppet-lint to ensure all file names used in template functions
|
4
|
+
end with the string '.erb'.
|
5
|
+
|
6
|
+
This plugin is an extension of our local style guide and may not suit
|
7
|
+
your own code base. This sample would trigger the `puppet-lint` warning:
|
8
|
+
|
9
|
+
class valid_template_filename {
|
10
|
+
file { '/tmp/templated':
|
11
|
+
content => template('mymodule/single_file.config'),
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
# all template file names should end with ".erb"
|
16
|
+
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
To use this plugin add the following line to your Gemfile
|
21
|
+
|
22
|
+
gem 'puppet-lint-non_erb_template_filename-check'
|
23
|
+
|
24
|
+
and then run `bundle install`.
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
This plugin provides a new check to `puppet-lint`.
|
29
|
+
|
30
|
+
all template file names should end with ".erb"
|
31
|
+
|
32
|
+
#### Author
|
33
|
+
|
34
|
+
[Dean Wilson](http://www.unixdaemon.net)
|
35
|
+
|
36
|
+
### License
|
37
|
+
|
38
|
+
* MIT
|
@@ -0,0 +1,37 @@
|
|
1
|
+
PuppetLint.new_check(:non_erb_template_filename) do
|
2
|
+
def check
|
3
|
+
resource_indexes.each do |resource|
|
4
|
+
if resource[:type].value == 'file'
|
5
|
+
resource[:param_tokens].select { |param_token|
|
6
|
+
param_token.value == 'content'
|
7
|
+
}.each do |content_token|
|
8
|
+
|
9
|
+
value_token = content_token.next_code_token.next_code_token
|
10
|
+
|
11
|
+
if value_token.value == 'template'
|
12
|
+
|
13
|
+
current_token = value_token.next_token
|
14
|
+
|
15
|
+
# iterate over all the code tokens until we hit the closing ')'
|
16
|
+
until current_token.type == :RPAREN
|
17
|
+
current_token = current_token.next_code_token
|
18
|
+
|
19
|
+
if current_token.type == :SSTRING && !current_token.value.end_with?('.erb')
|
20
|
+
|
21
|
+
warning = 'all template file names should end with ".erb"'
|
22
|
+
|
23
|
+
notify :warning, {
|
24
|
+
:message => warning,
|
25
|
+
:line => value_token.line,
|
26
|
+
:column => value_token.column,
|
27
|
+
:param_token => content_token,
|
28
|
+
:value_token => value_token,
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'non_erb_template_filename' do
|
4
|
+
|
5
|
+
let(:msg) { 'all template file names should end with ".erb"' }
|
6
|
+
|
7
|
+
context 'template function with one valid file name' do
|
8
|
+
let(:code) do
|
9
|
+
<<-EOS
|
10
|
+
class valid_template_filename {
|
11
|
+
file { '/tmp/templated':
|
12
|
+
content => template('mymodule/single_file.erb'),
|
13
|
+
}
|
14
|
+
}
|
15
|
+
EOS
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should not detect any problems' do
|
19
|
+
expect(problems).to have(0).problems
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
context 'template function with single invalid file name' do
|
25
|
+
let(:code) do
|
26
|
+
<<-EOS
|
27
|
+
class multi_templated_file {
|
28
|
+
file { '/tmp/templated':
|
29
|
+
content => template('mymodule/first_file.erb', 'mymodule/second_file.conf'),
|
30
|
+
}
|
31
|
+
}
|
32
|
+
EOS
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should detect a single problem' do
|
36
|
+
expect(problems).to have(1).problem
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should create a warning' do
|
40
|
+
expect(problems).to contain_warning(msg).on_line(3).in_column(24)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppet-lint-non_erb_template_filename-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: 2016-06-28 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
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-its
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-collection_matchers
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: |2
|
112
|
+
Extends puppet-lint to ensure all filenames used in template functions
|
113
|
+
end with the string '.erb'
|
114
|
+
email: dean.wilson@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- LICENSE
|
120
|
+
- README.md
|
121
|
+
- lib/puppet-lint/plugins/non_erb_template_filename.rb
|
122
|
+
- spec/puppet-lint/plugins/puppet-lint-non_erb_template_filename_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
homepage: https://github.com/deanwilson/puppet-lint-non_erb_template_filename-check
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.4.8
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: puppet-lint non_erb_template_filename check
|
148
|
+
test_files:
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
- spec/puppet-lint/plugins/puppet-lint-non_erb_template_filename_spec.rb
|
151
|
+
has_rdoc:
|