puppet-lint-template_file_extension-check 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9ffba03632899b62706b4ea5f7bd1cf8d0ed4e2a
4
- data.tar.gz: 77aee2c96d2523b63ac8eb8e059a7e20c205e0f1
2
+ SHA256:
3
+ metadata.gz: 2ee1d0f1c7cb2c22ac7a06de70b94dd4421017e10fc85eed0c5bfbf2f34d7892
4
+ data.tar.gz: da5d75f475d1c4c7d068dd1f20fd4912511b39dd2bc11a8f4c5e4a4101c5615f
5
5
  SHA512:
6
- metadata.gz: 6adcebd70d56572520f5ea4a22c7555c48d1c9d2e29d29a4b7f5e6d02c2fadac11811f6ab6a21b797b29ff6c239d48706f699ca7b6064cabaa0e5760f9cd6839
7
- data.tar.gz: 2c1d179325475d174ad627fc98b7b78c44a0c0191ee9d92a793e7c30f37e715dd9cfa4b480fb2e3219c63cea51954fec0b032375dd9da10ddda9516c0bfa8b3f
6
+ metadata.gz: e1043a656a1513c52527f5adb856dc276396164c054ab5549c538f2d3331c1e0abdd910f4ac4286cf819705ae997cb0a708ff236e4e81f3c4b5ab3f1181fca2b
7
+ data.tar.gz: a163f9066a8e1e63c386596bd7fb63b8e7c3fee0b6442c918ed9844b50781e430968982c1b3d7da4331e2b142d8d08322422259d8e0d51d5af440cd5d5322325
data/README.md CHANGED
@@ -3,8 +3,9 @@
3
3
  Extends puppet-lint to ensure all file names used in template and epp
4
4
  functions end with the string '.erb' or '.epp' respectively
5
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)
6
+ [![Actions Status](https://github.com/deanwilson/puppet-lint-template_file_extension-check/workflows/Ruby/badge.svg)](https://github.com/deanwilson/puppet-lint-template_file_extension-check/actions)
7
7
 
8
+ [![Actions Status](https://github.com/deanwilson/puppet-lint-template_file_extension-check/workflows/Rubocop%20linter/badge.svg)](https://github.com/deanwilson/puppet-lint-template_file_extension-check/actions)
8
9
 
9
10
  This plugin is an extension of our local style guide and may not suit
10
11
  your own code base. This sample would trigger the `puppet-lint` warning:
@@ -1,42 +1,42 @@
1
1
  PuppetLint.new_check(:template_file_extension) do
2
2
  def check
3
-
4
3
  template_extensions = {
5
- epp: '.epp',
4
+ epp: '.epp',
6
5
  template: '.erb',
7
6
  }
8
7
 
8
+ # the types a filename may be in a `template()` call
9
+ name_types = [:DQPOST, :SSTRING]
10
+
9
11
  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|
12
+ next unless resource[:type].value == 'file'
14
13
 
15
- value_token = content_token.next_code_token.next_code_token
14
+ param_tokens = resource[:param_tokens].select { |pt| pt.value == 'content' }
16
15
 
17
- if matched = value_token.value.match(/^(template|epp)$/)
18
- template_function = matched[1]
19
- extension = template_extensions[template_function.to_sym]
16
+ param_tokens.each do |content_token|
17
+ value_token = content_token.next_code_token.next_code_token
20
18
 
21
- current_token = value_token.next_token
22
- current_token = current_token.next_token while current_token.type == :WHITESPACE
19
+ if (matched = value_token.value.match(/^(template|epp)$/))
20
+ template_function = matched[1]
21
+ extension = template_extensions[template_function.to_sym]
23
22
 
24
- # iterate over all the code tokens until we hit the closing ')'
25
- until current_token.type == :RPAREN || current_token.type == :LBRACE
26
- current_token = current_token.next_code_token
23
+ current_token = value_token.next_token
24
+ current_token = current_token.next_token while current_token.type == :WHITESPACE
27
25
 
28
- if current_token.type == :SSTRING && !current_token.value.end_with?(extension)
26
+ # iterate over all the code tokens until we hit the closing ')'
27
+ until current_token.type == :RPAREN || current_token.type == :LBRACE
28
+ current_token = current_token.next_code_token
29
29
 
30
- warning = "all #{template_function} file names should end with #{extension}"
30
+ if (name_types.include? current_token.type) && !current_token.value.end_with?(extension)
31
+ warning = "all #{template_function} file names should end with #{extension}"
31
32
 
32
- notify :warning, {
33
- message: warning,
34
- line: value_token.line,
35
- column: value_token.column,
36
- param_token: content_token,
37
- value_token: value_token,
38
- }
39
- end
33
+ notify :warning, {
34
+ message: warning,
35
+ line: value_token.line,
36
+ column: value_token.column,
37
+ param_token: content_token,
38
+ value_token: value_token,
39
+ }
40
40
  end
41
41
  end
42
42
  end
@@ -0,0 +1,199 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'template_file_extension' do
4
+ ##########################
5
+ # Valid examples
6
+ ##########################
7
+ context 'when the manifest has no file resources' do
8
+ let(:code) do
9
+ <<-TEST_CLASS
10
+ class no_file_resource {
11
+ host { 'syslog':
12
+ ip => '10.10.10.10',
13
+ }
14
+ }
15
+ TEST_CLASS
16
+ end
17
+
18
+ it 'does not detect any problems' do
19
+ expect(problems).to have(0).problems
20
+ end
21
+ end
22
+
23
+ context 'when a non-template function is called' do
24
+ let(:code) do
25
+ <<-TEST_CLASS
26
+ class random_function {
27
+ file { '/tmp/templated':
28
+ content => random_name('mymodule/single_file.erb'),
29
+ }
30
+ }
31
+ TEST_CLASS
32
+ end
33
+
34
+ it 'does not detect any problems' do
35
+ expect(problems).to have(0).problems
36
+ end
37
+ end
38
+
39
+ context 'when the template function is called with one valid file name' do
40
+ let(:code) do
41
+ <<-TEST_CLASS
42
+ class valid_template_filename {
43
+ file { '/tmp/templated':
44
+ content => template('mymodule/single_file.erb'),
45
+ }
46
+ }
47
+ TEST_CLASS
48
+ end
49
+
50
+ it 'does not detect any problems' do
51
+ expect(problems).to have(0).problems
52
+ end
53
+ end
54
+
55
+ context 'when the epp function is called with one valid file name' do
56
+ let(:code) do
57
+ <<-TEST_CLASS
58
+ class valid_epp_template_filename {
59
+ file { '/tmp/templated':
60
+ content => epp('mymodule/single_file.epp'),
61
+ }
62
+ }
63
+ TEST_CLASS
64
+ end
65
+
66
+ it 'does not detect any problems' do
67
+ expect(problems).to have(0).problems
68
+ end
69
+ end
70
+
71
+ context 'when the epp function is called with one valid file name and parameters' do
72
+ let(:code) do
73
+ <<-TEST_CLASS
74
+ class valid_epp_template_filename {
75
+ file { '/tmp/templated':
76
+ content => epp('mymodule/single_file.epp', {'key' => 'val'}),
77
+ }
78
+ }
79
+ TEST_CLASS
80
+ end
81
+
82
+ it 'does not detect any problems' do
83
+ expect(problems).to have(0).problems
84
+ end
85
+ end
86
+
87
+ context 'when a space it present between the template function and opening paren' do
88
+ let(:code) do
89
+ <<-TEST_CLASS
90
+ class space_between_template_and_opening_paren {
91
+ file { '/tmp/templated':
92
+ content => template ('mymodule/a_file.erb'),
93
+ }
94
+ }
95
+ TEST_CLASS
96
+ end
97
+
98
+ it 'does not detect any problems' do
99
+ expect(problems).to have(0).problems
100
+ end
101
+ end
102
+
103
+ ##########################
104
+ # Invalid examples
105
+ ##########################
106
+
107
+ context 'when the template function is called with a single invalid file name' do
108
+ let(:template_msg) { 'all template file names should end with .erb' }
109
+ let(:code) do
110
+ <<-TEST_CLASS
111
+ class multi_templated_file {
112
+ file { '/tmp/templated':
113
+ content => template('mymodule/first_file.erb', 'mymodule/second_file.conf'),
114
+ }
115
+ }
116
+ TEST_CLASS
117
+ end
118
+
119
+ it 'detects a single problem' do
120
+ expect(problems).to have(1).problem
121
+ end
122
+
123
+ it 'creates a warning' do
124
+ expect(problems).to contain_warning(template_msg).on_line(3).in_column(24)
125
+ end
126
+ end
127
+
128
+ context 'when the epp function is called with a single invalid file name' do
129
+ let(:epp_msg) { 'all epp file names should end with .epp' }
130
+
131
+ let(:code) do
132
+ <<-TEST_CLASS
133
+ class epp_multi_templated_file {
134
+ file { '/tmp/templated':
135
+ content => epp('mymodule/first_file', {'key' => 'val'}),
136
+ }
137
+ }
138
+ TEST_CLASS
139
+ end
140
+
141
+ it 'detects a single problem' do
142
+ expect(problems).to have(1).problem
143
+ end
144
+
145
+ it 'creates a warning' do
146
+ expect(problems).to contain_warning(epp_msg).on_line(3).in_column(24)
147
+ end
148
+ end
149
+
150
+ context 'when there is a space between the template function and opening paren, and no extension is provided' do
151
+ let(:template_msg) { 'all template file names should end with .erb' }
152
+
153
+ let(:code) do
154
+ <<-TEST_CLASS
155
+ class space_between_template_and_opening_paren {
156
+ file { '/tmp/templated':
157
+ content => template ('mymodule/a_file'),
158
+ }
159
+ }
160
+ TEST_CLASS
161
+ end
162
+
163
+ it 'detects a single problem' do
164
+ expect(problems).to have(1).problem
165
+ end
166
+
167
+ it 'creates a warning' do
168
+ expect(problems).to contain_warning(template_msg).on_line(3).in_column(24)
169
+ end
170
+ end
171
+
172
+ ##
173
+ # Reported bugs
174
+ ##
175
+
176
+ ## https://github.com/deanwilson/puppet-lint-template_file_extension-check/issues/48
177
+ context 'when the paramater type is DQPOST not SSTRING and no extension is provided (issue #48)' do
178
+ let(:template_msg) { 'all template file names should end with .erb' }
179
+
180
+ let(:code) do
181
+ <<-TEST_CLASS
182
+ class space_between_template_and_opening_paren {
183
+ file { "/etc/${package_name}.conf":
184
+ ensure => file,
185
+ content => template("allknowingdns/${package_name}.conf"),
186
+ }
187
+ }
188
+ TEST_CLASS
189
+ end
190
+
191
+ it 'detects a single problem' do
192
+ expect(problems).to have(1).problem
193
+ end
194
+
195
+ it 'creates a warning' do
196
+ expect(problems).to contain_warning(template_msg).on_line(4).in_column(24)
197
+ end
198
+ end
199
+ end
@@ -1,3 +1,8 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ enable_coverage :branch
4
+ end
5
+
1
6
  require 'puppet-lint'
2
7
 
3
8
  PuppetLint::Plugins.load_spec_helper
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-template_file_extension-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-19 00:00:00.000000000 Z
11
+ date: 2020-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint
@@ -30,22 +30,36 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 13.0.0
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 13.0.0
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: rspec
35
49
  requirement: !ruby/object:Gem::Requirement
36
50
  requirements:
37
51
  - - "~>"
38
52
  - !ruby/object:Gem::Version
39
- version: 3.5.0
53
+ version: 3.10.0
40
54
  type: :development
41
55
  prerelease: false
42
56
  version_requirements: !ruby/object:Gem::Requirement
43
57
  requirements:
44
58
  - - "~>"
45
59
  - !ruby/object:Gem::Version
46
- version: 3.5.0
60
+ version: 3.10.0
47
61
  - !ruby/object:Gem::Dependency
48
- name: rspec-its
62
+ name: rspec-collection_matchers
49
63
  requirement: !ruby/object:Gem::Requirement
50
64
  requirements:
51
65
  - - "~>"
@@ -59,7 +73,7 @@ dependencies:
59
73
  - !ruby/object:Gem::Version
60
74
  version: '1.0'
61
75
  - !ruby/object:Gem::Dependency
62
- name: rspec-collection_matchers
76
+ name: rspec-its
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
79
  - - "~>"
@@ -73,61 +87,61 @@ dependencies:
73
87
  - !ruby/object:Gem::Version
74
88
  version: '1.0'
75
89
  - !ruby/object:Gem::Dependency
76
- name: rubocop
90
+ name: rspec-json_expectations
77
91
  requirement: !ruby/object:Gem::Requirement
78
92
  requirements:
79
93
  - - "~>"
80
94
  - !ruby/object:Gem::Version
81
- version: 0.47.1
95
+ version: '2.2'
82
96
  type: :development
83
97
  prerelease: false
84
98
  version_requirements: !ruby/object:Gem::Requirement
85
99
  requirements:
86
100
  - - "~>"
87
101
  - !ruby/object:Gem::Version
88
- version: 0.47.1
102
+ version: '2.2'
89
103
  - !ruby/object:Gem::Dependency
90
- name: rake
104
+ name: rubocop
91
105
  requirement: !ruby/object:Gem::Requirement
92
106
  requirements:
93
107
  - - "~>"
94
108
  - !ruby/object:Gem::Version
95
- version: 11.2.0
109
+ version: 0.93.0
96
110
  type: :development
97
111
  prerelease: false
98
112
  version_requirements: !ruby/object:Gem::Requirement
99
113
  requirements:
100
114
  - - "~>"
101
115
  - !ruby/object:Gem::Version
102
- version: 11.2.0
116
+ version: 0.93.0
103
117
  - !ruby/object:Gem::Dependency
104
- name: rspec-json_expectations
118
+ name: rubocop-rspec
105
119
  requirement: !ruby/object:Gem::Requirement
106
120
  requirements:
107
121
  - - "~>"
108
122
  - !ruby/object:Gem::Version
109
- version: '1.4'
123
+ version: 1.44.1
110
124
  type: :development
111
125
  prerelease: false
112
126
  version_requirements: !ruby/object:Gem::Requirement
113
127
  requirements:
114
128
  - - "~>"
115
129
  - !ruby/object:Gem::Version
116
- version: '1.4'
130
+ version: 1.44.1
117
131
  - !ruby/object:Gem::Dependency
118
132
  name: simplecov
119
133
  requirement: !ruby/object:Gem::Requirement
120
134
  requirements:
121
135
  - - "~>"
122
136
  - !ruby/object:Gem::Version
123
- version: 0.15.0
137
+ version: 0.20.0
124
138
  type: :development
125
139
  prerelease: false
126
140
  version_requirements: !ruby/object:Gem::Requirement
127
141
  requirements:
128
142
  - - "~>"
129
143
  - !ruby/object:Gem::Version
130
- version: 0.15.0
144
+ version: 0.20.0
131
145
  description: |2
132
146
  Extends puppet-lint to ensure all filenames used in template and epp functions
133
147
  end with the string '.erb' or '.epp' respectively
@@ -139,7 +153,7 @@ files:
139
153
  - LICENSE
140
154
  - README.md
141
155
  - lib/puppet-lint/plugins/template_file_extension.rb
142
- - spec/puppet-lint/plugins/puppet-lint-template_file_extension_spec.rb
156
+ - spec/puppet-lint/plugins/template_file_extension_spec.rb
143
157
  - spec/spec_helper.rb
144
158
  homepage: https://github.com/deanwilson/puppet-lint-template_file_extension-check
145
159
  licenses:
@@ -153,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
167
  requirements:
154
168
  - - ">="
155
169
  - !ruby/object:Gem::Version
156
- version: '0'
170
+ version: 2.5.0
157
171
  required_rubygems_version: !ruby/object:Gem::Requirement
158
172
  requirements:
159
173
  - - ">="
@@ -161,10 +175,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
175
  version: '0'
162
176
  requirements: []
163
177
  rubyforge_project:
164
- rubygems_version: 2.6.8
178
+ rubygems_version: 2.7.6
165
179
  signing_key:
166
180
  specification_version: 4
167
181
  summary: puppet-lint template_file_extension check
168
182
  test_files:
183
+ - spec/puppet-lint/plugins/template_file_extension_spec.rb
169
184
  - spec/spec_helper.rb
170
- - spec/puppet-lint/plugins/puppet-lint-template_file_extension_spec.rb
@@ -1,142 +0,0 @@
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
- context 'epp function with one valid file name and parameters' do
42
- let(:code) do
43
- <<-EOS
44
- class valid_epp_template_filename {
45
- file { '/tmp/templated':
46
- content => epp('mymodule/single_file.epp', {'key' => 'val'}),
47
- }
48
- }
49
- EOS
50
- end
51
-
52
- it 'should not detect any problems' do
53
- expect(problems).to have(0).problems
54
- end
55
- end
56
-
57
- context 'space between template and opening paren' do
58
- let(:code) do
59
- <<-EOS
60
- class space_between_template_and_opening_paren {
61
- file { '/tmp/templated':
62
- content => template ('mymodule/a_file.erb'),
63
- }
64
- }
65
- EOS
66
- end
67
-
68
- it 'should not detect any problems' do
69
- expect(problems).to have(0).problems
70
- end
71
- end
72
-
73
- ##########################
74
- # Invalid examples
75
- ##########################
76
-
77
- let(:template_msg) { 'all template file names should end with .erb' }
78
-
79
- context 'template function with single invalid file name' do
80
- let(:code) do
81
- <<-EOS
82
- class multi_templated_file {
83
- file { '/tmp/templated':
84
- content => template('mymodule/first_file.erb', 'mymodule/second_file.conf'),
85
- }
86
- }
87
- EOS
88
- end
89
-
90
- it 'should detect a single problem' do
91
- expect(problems).to have(1).problem
92
- end
93
-
94
- it 'should create a warning' do
95
- expect(problems).to contain_warning(template_msg).on_line(3).in_column(24)
96
- end
97
- end
98
-
99
- let(:epp_msg) { 'all epp file names should end with .epp' }
100
-
101
- context 'epp function with single invalid file name' do
102
- let(:code) do
103
- <<-EOS
104
- class epp_multi_templated_file {
105
- file { '/tmp/templated':
106
- content => epp('mymodule/first_file', {'key' => 'val'}),
107
- }
108
- }
109
- EOS
110
- end
111
-
112
- it 'should detect a single problem' do
113
- expect(problems).to have(1).problem
114
- end
115
-
116
- it 'should create a warning' do
117
- expect(problems).to contain_warning(epp_msg).on_line(3).in_column(24)
118
- end
119
- end
120
-
121
- context 'space between template and opening paren and no extension' do
122
- let(:code) do
123
- <<-EOS
124
- class space_between_template_and_opening_paren {
125
- file { '/tmp/templated':
126
- content => template ('mymodule/a_file'),
127
- }
128
- }
129
- EOS
130
- end
131
-
132
- it 'should detect a single problem' do
133
- expect(problems).to have(1).problem
134
- end
135
-
136
- it 'should create a warning' do
137
- expect(problems).to contain_warning(template_msg).on_line(3).in_column(26)
138
- end
139
- end
140
-
141
-
142
- end