puppet-lint-wmf_styleguide-check 1.0.7 → 1.1.0
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
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7980b85ac1476eb1cfd7107a024a8d01f56d3aaa13bc4adf6542b52edeb862a8
|
4
|
+
data.tar.gz: f5b71a6c23db3e26deec5d4f2a2d036ad4dbaeb26e0aa80d2049bf6e95e830eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 814e0b269f85a970e883534f42a12f201e0afaf530f47474e7bbfaf685dd0ae549a529de9c639768c6e34f11d53bb66425e7c31a4a25cf0d6bb6d60f9c614238
|
7
|
+
data.tar.gz: 8b85af51045fc558202c404ce87f20c0ca14dc76538ea30bde1abd68c3eac4ac154e1a77a309ff08b9e96ed93aca6945e870d117553259a68aa09d45d7b68b91
|
@@ -102,9 +102,14 @@ class PuppetResource
|
|
102
102
|
class? && (module_name == role_module)
|
103
103
|
end
|
104
104
|
|
105
|
-
def
|
105
|
+
def lookup_calls
|
106
|
+
# Returns an array of all the tokens referencing calls to lookup
|
107
|
+
@resource[:tokens].select(&:lookup?)
|
108
|
+
end
|
109
|
+
|
110
|
+
def legacy_hiera_calls
|
106
111
|
# Returns an array of all the tokens referencing calls to hiera
|
107
|
-
@resource[:tokens].select(&:
|
112
|
+
@resource[:tokens].select(&:legacy_hiera?)
|
108
113
|
end
|
109
114
|
|
110
115
|
def legacy_validate_calls
|
@@ -145,9 +150,9 @@ class PuppetLint
|
|
145
150
|
[:NAME, :FUNCTION_NAME].include?(@type) && @next_code_token.type == :LPAREN
|
146
151
|
end
|
147
152
|
|
148
|
-
def
|
149
|
-
#
|
150
|
-
function? && ['hiera', 'hiera_array', 'hiera_hash'
|
153
|
+
def legacy_hiera?
|
154
|
+
# Using old hiera call
|
155
|
+
function? && ['hiera', 'hiera_array', 'hiera_hash'].include?(@value)
|
151
156
|
end
|
152
157
|
|
153
158
|
def lookup?
|
@@ -198,10 +203,10 @@ end
|
|
198
203
|
|
199
204
|
# Checks and functions
|
200
205
|
def check_profile(klass)
|
201
|
-
# All parameters of profiles should have a default value that is a
|
206
|
+
# All parameters of profiles should have a default value that is a lookup
|
202
207
|
params_without_lookup_defaults klass
|
203
|
-
# All
|
204
|
-
|
208
|
+
# All lookup lookups should be in parameters
|
209
|
+
lookup_not_in_params klass
|
205
210
|
# Only a few selected classes should be included in a profile
|
206
211
|
profile_illegal_include klass
|
207
212
|
# System::role only goes in roles
|
@@ -210,7 +215,7 @@ end
|
|
210
215
|
|
211
216
|
def check_role(klass)
|
212
217
|
# Hiera lookups within a role are forbidden
|
213
|
-
|
218
|
+
lookup klass
|
214
219
|
# A role should only include profiles
|
215
220
|
include_not_profile klass
|
216
221
|
# A call, and only one, to system::role will be done
|
@@ -220,8 +225,8 @@ def check_role(klass)
|
|
220
225
|
end
|
221
226
|
|
222
227
|
def check_class(klass)
|
223
|
-
# No
|
224
|
-
|
228
|
+
# No lookup lookups allowed in a class.
|
229
|
+
lookup klass
|
225
230
|
# Cannot include or declare classes from other modules
|
226
231
|
class_illegal_include klass
|
227
232
|
illegal_class_declaration klass
|
@@ -230,28 +235,42 @@ def check_class(klass)
|
|
230
235
|
end
|
231
236
|
|
232
237
|
def check_define(define)
|
233
|
-
# No
|
234
|
-
|
238
|
+
# No lookup calls are admitted in defines. ever.
|
239
|
+
lookup define
|
235
240
|
# No class can be included in defines, like in classes
|
236
241
|
class_illegal_include define
|
237
242
|
# Non-profile defines should respect the rules for classes
|
238
243
|
illegal_class_declaration define unless define.module_name == 'profile'
|
239
244
|
end
|
240
245
|
|
241
|
-
def
|
242
|
-
# Searches for
|
243
|
-
|
246
|
+
def lookup(klass)
|
247
|
+
# Searches for lookup calls inside classes and defines.
|
248
|
+
lookup_errors(klass.lookup_calls, klass)
|
249
|
+
end
|
250
|
+
|
251
|
+
def legacy_hiera(klass)
|
252
|
+
# No calls to legacy hiera
|
253
|
+
tokens = klass.legacy_hiera_calls
|
254
|
+
tokens.each do |token|
|
255
|
+
msg = {
|
256
|
+
message: "wmf-style: Found deprecated function (#{token.value}) " \
|
257
|
+
"in #{klass.type} '#{klass.name}', use lookup instead",
|
258
|
+
line: token.line,
|
259
|
+
column: token.column
|
260
|
+
}
|
261
|
+
notify :error, msg
|
262
|
+
end
|
244
263
|
end
|
245
264
|
|
246
265
|
def params_without_lookup_defaults(klass)
|
247
|
-
# Finds parameters that have no
|
266
|
+
# Finds parameters that have no lookup-defined default value.
|
248
267
|
klass.params.each do |name, data|
|
249
268
|
next unless data[:value].select(&:lookup?).empty?
|
250
269
|
common = "wmf-style: Parameter '#{name}' of class '#{klass.name}'"
|
251
|
-
message = if data[:value].select(&:
|
270
|
+
message = if data[:value].select(&:legacy_hiera?).empty?
|
252
271
|
"#{common} has no call to lookup"
|
253
272
|
else
|
254
|
-
"#{common}
|
273
|
+
"#{common} hiera is deprecated use lookup"
|
255
274
|
end
|
256
275
|
token = data[:param]
|
257
276
|
msg = { message: message, line: token.line, column: token.column }
|
@@ -259,24 +278,24 @@ def params_without_lookup_defaults(klass)
|
|
259
278
|
end
|
260
279
|
end
|
261
280
|
|
262
|
-
def
|
263
|
-
# Checks if a
|
281
|
+
def lookup_not_in_params(klass)
|
282
|
+
# Checks if a lookup call is not in a parameter declaration. Used to check profiles
|
264
283
|
|
265
|
-
# Any
|
266
|
-
tokens = klass.
|
284
|
+
# Any lookup call that is not inside a parameter declaration is a violation
|
285
|
+
tokens = klass.lookup_calls.reject do |token|
|
267
286
|
maybe_param = token.prev_code_token.prev_code_token
|
268
287
|
klass.params.keys.include?(maybe_param.value)
|
269
288
|
end
|
270
|
-
|
289
|
+
lookup_errors(tokens, klass)
|
271
290
|
end
|
272
291
|
|
273
|
-
def
|
274
|
-
# Helper for printing
|
292
|
+
def lookup_errors(tokens, klass)
|
293
|
+
# Helper for printing lookup errors nicely
|
275
294
|
tokens.each do |token|
|
276
|
-
#
|
295
|
+
# lookup ( 'some::label' )
|
277
296
|
value = token.next_code_token.next_code_token.value
|
278
297
|
msg = {
|
279
|
-
message: "wmf-style: Found
|
298
|
+
message: "wmf-style: Found lookup call in #{klass.type} '#{klass.name}' for '#{value}'",
|
280
299
|
line: token.line,
|
281
300
|
column: token.column
|
282
301
|
}
|
@@ -402,6 +421,7 @@ end
|
|
402
421
|
def check_deprecations(resource)
|
403
422
|
# Check the resource for declarations of deprecated defines
|
404
423
|
legacy_validate_errors resource
|
424
|
+
legacy_hiera resource
|
405
425
|
deprecated_defines = ['base::service_unit']
|
406
426
|
deprecated_defines.each do |deprecated|
|
407
427
|
resource.resource?(deprecated).each do |token|
|
@@ -420,13 +440,18 @@ def check_node(node)
|
|
420
440
|
title = node[:title_tokens].map(&:value).join(', ')
|
421
441
|
node[:tokens].each do |token|
|
422
442
|
msg = nil
|
423
|
-
if token.
|
443
|
+
if token.lookup?
|
424
444
|
msg = {
|
425
|
-
message: "wmf-style:
|
445
|
+
message: "wmf-style: node '#{title}' calls lookup function",
|
446
|
+
line: token.line,
|
447
|
+
column: token.column
|
448
|
+
}
|
449
|
+
elsif token.legacy_hiera?
|
450
|
+
msg = {
|
451
|
+
message: "wmf-style: node '#{title}' calls legacy #{token.value} function",
|
426
452
|
line: token.line,
|
427
453
|
column: token.column
|
428
454
|
}
|
429
|
-
|
430
455
|
elsif token.class_include?
|
431
456
|
msg = {
|
432
457
|
message: "wmf-style: node '#{title}' includes class #{token.included_class.value}",
|
@@ -445,12 +470,6 @@ def check_node(node)
|
|
445
470
|
line: token.line,
|
446
471
|
column: token.column
|
447
472
|
}
|
448
|
-
elsif token.role_keyword? && token.next_code_token.next_code_token.next_code_token.type != :RPAREN
|
449
|
-
msg = {
|
450
|
-
message: "wmf-style: node '#{title}' includes multiple roles",
|
451
|
-
line: token.line,
|
452
|
-
column: token.column
|
453
|
-
}
|
454
473
|
end
|
455
474
|
notify :error, msg if msg
|
456
475
|
end
|
@@ -14,13 +14,16 @@ EOF
|
|
14
14
|
|
15
15
|
class_ko = <<-EOF
|
16
16
|
class foo($t=hiera('foo::title')) {
|
17
|
-
$msg =
|
17
|
+
$msg = lookup( "foo::bar")
|
18
18
|
notice($msg)
|
19
19
|
notice($t)
|
20
20
|
include ::passwords::redis
|
21
21
|
class { 'bar': }
|
22
22
|
validate_foobar($param)
|
23
23
|
validate_re($param, '^.*$')
|
24
|
+
hiera('foobar')
|
25
|
+
hiera_hash('foobar')
|
26
|
+
hiera_array('foobar')
|
24
27
|
}
|
25
28
|
EOF
|
26
29
|
|
@@ -42,7 +45,7 @@ class profile::fixme (
|
|
42
45
|
$test4=hiera_hash('profile::foobar::foo')
|
43
46
|
) {
|
44
47
|
include ::apache2::common
|
45
|
-
$role =
|
48
|
+
$role = lookup('role')
|
46
49
|
system::role { $role: }
|
47
50
|
}
|
48
51
|
EOF
|
@@ -78,6 +81,9 @@ define foo::fixme ($a=hiera('something')) {
|
|
78
81
|
class { '::bar': }
|
79
82
|
validate_foobar($param)
|
80
83
|
validate_re($param, '^.*$')
|
84
|
+
hiera('foobar')
|
85
|
+
hiera_hash('foobar')
|
86
|
+
hiera_array('foobar')
|
81
87
|
}
|
82
88
|
EOF
|
83
89
|
|
@@ -89,12 +95,14 @@ EOF
|
|
89
95
|
|
90
96
|
node_ko = <<-EOF
|
91
97
|
node 'fixme' {
|
92
|
-
role(spare::system,
|
93
|
-
mediawiki::appserver)
|
94
98
|
include base::firewall
|
95
99
|
interface::mapped { 'eth0':
|
96
100
|
foo => 'bar'
|
97
101
|
}
|
102
|
+
lookup('foobar')
|
103
|
+
hiera('foobar')
|
104
|
+
hiera_array('foobar')
|
105
|
+
hiera_hash('foobar')
|
98
106
|
}
|
99
107
|
EOF
|
100
108
|
|
@@ -128,8 +136,8 @@ describe 'wmf_styleguide' do
|
|
128
136
|
context 'class with errors' do
|
129
137
|
let(:code) { class_ko }
|
130
138
|
it 'should create errors for hiera declarations' do
|
131
|
-
expect(problems).to contain_error("wmf-style: Found hiera
|
132
|
-
expect(problems).to contain_error("wmf-style: Found
|
139
|
+
expect(problems).to contain_error("wmf-style: Found deprecated function (hiera) in class 'foo', use lookup instead").on_line(1).in_column(14)
|
140
|
+
expect(problems).to contain_error("wmf-style: Found lookup call in class 'foo' for 'foo::bar'").on_line(2).in_column(15)
|
133
141
|
end
|
134
142
|
it 'should create errors for included classes' do
|
135
143
|
expect(problems).to contain_error("wmf-style: class 'foo' includes passwords::redis from another module").on_line(5).in_column(16)
|
@@ -139,18 +147,27 @@ describe 'wmf_styleguide' do
|
|
139
147
|
expect(problems).to contain_error("wmf-style: Found legacy function (validate_foobar) call in class 'foo'").on_line(7).in_column(8)
|
140
148
|
expect(problems).to contain_error("wmf-style: Found legacy function (validate_re) call in class 'foo'").on_line(8).in_column(8)
|
141
149
|
end
|
150
|
+
it 'should create errors for hiera function' do
|
151
|
+
expect(problems).to contain_error("wmf-style: Found deprecated function (hiera) in class 'foo', use lookup instead").on_line(9).in_column(8)
|
152
|
+
end
|
153
|
+
it 'should create errors for hiera_hash function' do
|
154
|
+
expect(problems).to contain_error("wmf-style: Found deprecated function (hiera_hash) in class 'foo', use lookup instead").on_line(10).in_column(8)
|
155
|
+
end
|
156
|
+
it 'should create errors for hiera_array function' do
|
157
|
+
expect(problems).to contain_error("wmf-style: Found deprecated function (hiera_array) in class 'foo', use lookup instead").on_line(11).in_column(8)
|
158
|
+
end
|
142
159
|
end
|
143
160
|
|
144
161
|
context 'profile with errors' do
|
145
162
|
let(:code) { profile_ko }
|
146
163
|
it 'should create errors for parameters without hiera defaults' do
|
147
164
|
expect(problems).to contain_error("wmf-style: Parameter 'test1' of class 'profile::fixme' has no call to lookup").on_line(2).in_column(7)
|
148
|
-
expect(problems).to contain_error("wmf-style: Parameter 'test2' of class 'profile::fixme'
|
149
|
-
expect(problems).to contain_error("wmf-style: Parameter 'test3' of class 'profile::fixme'
|
150
|
-
expect(problems).to contain_error("wmf-style: Parameter 'test4' of class 'profile::fixme'
|
165
|
+
expect(problems).to contain_error("wmf-style: Parameter 'test2' of class 'profile::fixme' hiera is deprecated use lookup").on_line(3).in_column(7)
|
166
|
+
expect(problems).to contain_error("wmf-style: Parameter 'test3' of class 'profile::fixme' hiera is deprecated use lookup").on_line(4).in_column(7)
|
167
|
+
expect(problems).to contain_error("wmf-style: Parameter 'test4' of class 'profile::fixme' hiera is deprecated use lookup").on_line(5).in_column(7)
|
151
168
|
end
|
152
169
|
it 'should create errors for hiera calls in body' do
|
153
|
-
expect(problems).to contain_error("wmf-style: Found
|
170
|
+
expect(problems).to contain_error("wmf-style: Found lookup call in class 'profile::fixme' for 'role'").on_line(8).in_column(13)
|
154
171
|
end
|
155
172
|
it 'should create errors for use of system::role' do
|
156
173
|
expect(problems).to contain_error("wmf-style: class 'profile::fixme' declares system::role, which should only be used in roles").on_line(9).in_column(5)
|
@@ -175,7 +192,7 @@ describe 'wmf_styleguide' do
|
|
175
192
|
context 'defined type with violations' do
|
176
193
|
let(:code) { define_ko }
|
177
194
|
it 'should not contain hiera calls' do
|
178
|
-
expect(problems).to contain_error("wmf-style: Found hiera
|
195
|
+
expect(problems).to contain_error("wmf-style: Found deprecated function (hiera) in defined type 'foo::fixme', use lookup instead").on_line(1)
|
179
196
|
end
|
180
197
|
it 'should not include or define any class' do
|
181
198
|
expect(problems).to contain_error("wmf-style: defined type 'foo::fixme' declares class bar from another module").on_line(3)
|
@@ -184,6 +201,15 @@ describe 'wmf_styleguide' do
|
|
184
201
|
expect(problems).to contain_error("wmf-style: Found legacy function (validate_foobar) call in defined type 'foo::fixme'").on_line(4).in_column(8)
|
185
202
|
expect(problems).to contain_error("wmf-style: Found legacy function (validate_re) call in defined type 'foo::fixme'").on_line(5).in_column(8)
|
186
203
|
end
|
204
|
+
it 'should create errors for hiera function' do
|
205
|
+
expect(problems).to contain_error("wmf-style: Found deprecated function (hiera) in defined type 'foo::fixme', use lookup instead").on_line(6).in_column(8)
|
206
|
+
end
|
207
|
+
it 'should create errors for hiera_hash function' do
|
208
|
+
expect(problems).to contain_error("wmf-style: Found deprecated function (hiera_hash) in defined type 'foo::fixme', use lookup instead").on_line(7).in_column(8)
|
209
|
+
end
|
210
|
+
it 'should create errors for hiera_array function' do
|
211
|
+
expect(problems).to contain_error("wmf-style: Found deprecated function (hiera_array) in defined type 'foo::fixme', use lookup instead").on_line(8).in_column(8)
|
212
|
+
end
|
187
213
|
end
|
188
214
|
|
189
215
|
context 'node with no errors' do
|
@@ -194,15 +220,24 @@ describe 'wmf_styleguide' do
|
|
194
220
|
end
|
195
221
|
context 'node with violations' do
|
196
222
|
let(:code) { node_ko }
|
197
|
-
it 'should not have multiple roles applied' do
|
198
|
-
expect(problems).to contain_error("wmf-style: node 'fixme' includes multiple roles").on_line(2)
|
199
|
-
end
|
200
223
|
it 'should not include classes directly' do
|
201
224
|
expect(problems).to contain_error("wmf-style: node 'fixme' includes class base::firewall")
|
202
225
|
end
|
203
226
|
it 'should not declare any defined type' do
|
204
227
|
expect(problems).to contain_error("wmf-style: node 'fixme' declares interface::mapped")
|
205
228
|
end
|
229
|
+
it 'should not call lookup' do
|
230
|
+
expect(problems).to contain_error("wmf-style: node 'fixme' calls lookup function")
|
231
|
+
end
|
232
|
+
it 'should not call hiera' do
|
233
|
+
expect(problems).to contain_error("wmf-style: node 'fixme' calls legacy hiera function")
|
234
|
+
end
|
235
|
+
it 'should not call hiera_array' do
|
236
|
+
expect(problems).to contain_error("wmf-style: node 'fixme' calls legacy hiera_array function")
|
237
|
+
end
|
238
|
+
it 'should not call hiera_hash' do
|
239
|
+
expect(problems).to contain_error("wmf-style: node 'fixme' calls legacy hiera_hash function")
|
240
|
+
end
|
206
241
|
end
|
207
242
|
|
208
243
|
context 'defined type with deprecations' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-lint-wmf_styleguide-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giuseppe Lavagetto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet-lint
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 0.49.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.17.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.17.1
|
111
125
|
description: |2
|
112
126
|
A puppet-lint plugin to check that the code adheres to the WMF coding guidelines:
|
113
127
|
|
@@ -149,10 +163,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
163
|
- !ruby/object:Gem::Version
|
150
164
|
version: '0'
|
151
165
|
requirements: []
|
152
|
-
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 2.7.6.2
|
153
168
|
signing_key:
|
154
169
|
specification_version: 4
|
155
170
|
summary: A puppet-lint plugin to check code adheres to the WMF coding guidelines
|
156
171
|
test_files:
|
157
|
-
- spec/spec_helper.rb
|
158
172
|
- spec/puppet-lint/plugins/check_wmf_styleguide_check_spec.rb
|
173
|
+
- spec/spec_helper.rb
|