puppet-lint-wmf_styleguide-check 1.0.0 → 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
- SHA1:
3
- metadata.gz: 827734026504a15ef6e6c2e3003499a467f3a222
4
- data.tar.gz: ba471ad1f7f634ca080cc5c0a1d93e9877343420
2
+ SHA256:
3
+ metadata.gz: 7980b85ac1476eb1cfd7107a024a8d01f56d3aaa13bc4adf6542b52edeb862a8
4
+ data.tar.gz: f5b71a6c23db3e26deec5d4f2a2d036ad4dbaeb26e0aa80d2049bf6e95e830eb
5
5
  SHA512:
6
- metadata.gz: 4460a00a245dbfad6e9105287f76479e7182ade5a47bf6f12a0804983a55cbaee7db026c6cd765e31279f211c8d12a09f4576042c56d6ffdc4f0bafadd268fd4
7
- data.tar.gz: 6877ce5a41f58aa4055fd01b0cdbb151cdf0620fd5336c419e4e1c6c7dcbd16a70c7adea13ca0c992f8b080ba3f5284d8edb39be11c29b6621dcd2ed6bd37a51
6
+ metadata.gz: 814e0b269f85a970e883534f42a12f201e0afaf530f47474e7bbfaf685dd0ae549a529de9c639768c6e34f11d53bb66425e7c31a4a25cf0d6bb6d60f9c614238
7
+ data.tar.gz: 8b85af51045fc558202c404ce87f20c0ca14dc76538ea30bde1abd68c3eac4ac154e1a77a309ff08b9e96ed93aca6945e870d117553259a68aa09d45d7b68b91
@@ -1,4 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Class to manage puppet resources.
4
+ # See how we extend PuppetLint::Lexer::Token below to understand how we filter
5
+ # tokens within a parsed resource.
2
6
  class PuppetResource
3
7
  attr_accessor :profile_module, :role_module
4
8
 
@@ -49,63 +53,89 @@ class PuppetResource
49
53
  # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength
50
54
 
51
55
  def params
56
+ # Lazy-load and return all the parameters of the resource
52
57
  @params || parse_params
53
58
  end
54
59
 
55
60
  def profile_module
61
+ # Return the name of the module where profiles are located
56
62
  @profile_module || 'profile'
57
63
  end
58
64
 
59
65
  def role_module
66
+ # Return the name of the module where roles are located
60
67
  @role_module || 'role'
61
68
  end
62
69
 
63
70
  def class?
71
+ # True if this is a class,
64
72
  @resource[:type] == :CLASS
65
73
  end
66
74
 
67
75
  def name
76
+ # Extract a normalized resource name (without the :: prefix if present)
68
77
  @resource[:name_token].value.gsub(/^::/, '')
69
78
  end
70
79
 
71
80
  def path
81
+ # Path of the resource
72
82
  @resource[:path]
73
83
  end
74
84
 
75
85
  def filename
76
- puts @resource
86
+ # File name of the resource
77
87
  @resource[:filename]
78
88
  end
79
89
 
80
90
  def module_name
91
+ # Module containing this resource
81
92
  name.split('::')[0]
82
93
  end
83
94
 
84
95
  def profile?
96
+ # True if the resource is in the profile module
85
97
  class? && (module_name == profile_module)
86
98
  end
87
99
 
88
100
  def role?
101
+ # True if the resource is in the role module
89
102
  class? && (module_name == role_module)
90
103
  end
91
104
 
92
- def hiera_calls
93
- @resource[:tokens].select(&:hiera?)
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
111
+ # Returns an array of all the tokens referencing calls to hiera
112
+ @resource[:tokens].select(&:legacy_hiera?)
113
+ end
114
+
115
+ def legacy_validate_calls
116
+ # Returns an array of all the tokens referencing calls to a stdlib legacy validate function
117
+ @resource[:tokens].select(&:legacy_validate?)
94
118
  end
95
119
 
96
120
  def included_classes
121
+ # Returns an array of all the classes included (with require/include)
97
122
  @resource[:tokens].map(&:included_class).compact
98
123
  end
99
124
 
100
125
  def declared_classes
126
+ # Returns an array of all the declared classes
101
127
  @resource[:tokens].map(&:declared_class).compact
102
128
  end
103
129
 
104
130
  def declared_resources
131
+ # Returns an array of all the declared classes
105
132
  @resource[:tokens].select(&:declared_type?)
106
133
  end
107
134
 
108
135
  def resource?(name)
136
+ # Arguments:
137
+ # name (string) Name of the resource we want to search
138
+ # Returns an array of all the defines of the specified resource
109
139
  @resource[:tokens].select { |t| t.declared_type? && t.value.gsub(/^::/, '') == name }
110
140
  end
111
141
  end
@@ -116,18 +146,32 @@ class PuppetLint
116
146
  class Token
117
147
  # Extend the basic token with utility functions
118
148
  def function?
119
- @type == :NAME && @next_code_token.type == :LPAREN
149
+ # A function is something that has a name and is followed by a left parens
150
+ [:NAME, :FUNCTION_NAME].include?(@type) && @next_code_token.type == :LPAREN
120
151
  end
121
152
 
122
- def hiera?
123
- function? && @value == 'hiera'
153
+ def legacy_hiera?
154
+ # Using old hiera call
155
+ function? && ['hiera', 'hiera_array', 'hiera_hash'].include?(@value)
156
+ end
157
+
158
+ def lookup?
159
+ # A function call specifically calling lookup
160
+ function? && ['lookup'].include?(@value)
161
+ end
162
+
163
+ def legacy_validate?
164
+ # A function calling one of the legacy stdlib validate functions
165
+ function? && @value.start_with?('validate_')
124
166
  end
125
167
 
126
168
  def class_include?
127
- @type == :NAME && ['include', 'require'].include?(@value) && @next_code_token.type != :FARROW
169
+ # Check for include-like objects
170
+ @type == :NAME && ['include', 'require', 'contain'].include?(@value) && @next_code_token.type != :FARROW
128
171
  end
129
172
 
130
173
  def included_class
174
+ # Fetch the token describing the included class
131
175
  return unless class_include?
132
176
  return @next_code_token.next_code_token if @next_code_token.type == :LPAREN
133
177
  @next_code_token
@@ -141,6 +185,7 @@ class PuppetLint
141
185
  end
142
186
 
143
187
  def declared_type?
188
+ # The token is a name and the next token is a {, while the previous one is not "class"
144
189
  @type == :NAME && @next_code_token.type == :LBRACE && @prev_code_token.type != :CLASS
145
190
  end
146
191
 
@@ -149,6 +194,7 @@ class PuppetLint
149
194
  end
150
195
 
151
196
  def role_keyword?
197
+ # This is a function with name "role"
152
198
  @type == :NAME && @value = 'role' && @next_code_token.type == :LPAREN
153
199
  end
154
200
  end
@@ -157,10 +203,10 @@ end
157
203
 
158
204
  # Checks and functions
159
205
  def check_profile(klass)
160
- # All parameters of profiles should have a default value that is a hiera lookup
161
- params_without_hiera_defaults klass
162
- # All hiera lookups should be in parameters
163
- hiera_not_in_params klass
206
+ # All parameters of profiles should have a default value that is a lookup
207
+ params_without_lookup_defaults klass
208
+ # All lookup lookups should be in parameters
209
+ lookup_not_in_params klass
164
210
  # Only a few selected classes should be included in a profile
165
211
  profile_illegal_include klass
166
212
  # System::role only goes in roles
@@ -169,7 +215,7 @@ end
169
215
 
170
216
  def check_role(klass)
171
217
  # Hiera lookups within a role are forbidden
172
- hiera klass
218
+ lookup klass
173
219
  # A role should only include profiles
174
220
  include_not_profile klass
175
221
  # A call, and only one, to system::role will be done
@@ -179,8 +225,8 @@ def check_role(klass)
179
225
  end
180
226
 
181
227
  def check_class(klass)
182
- # No hiera lookups allowed in a class.
183
- hiera klass
228
+ # No lookup lookups allowed in a class.
229
+ lookup klass
184
230
  # Cannot include or declare classes from other modules
185
231
  class_illegal_include klass
186
232
  illegal_class_declaration klass
@@ -189,25 +235,26 @@ def check_class(klass)
189
235
  end
190
236
 
191
237
  def check_define(define)
192
- # No hiera calls are admitted in defines. ever.
193
- hiera define
238
+ # No lookup calls are admitted in defines. ever.
239
+ lookup define
194
240
  # No class can be included in defines, like in classes
195
241
  class_illegal_include define
196
242
  # Non-profile defines should respect the rules for classes
197
243
  illegal_class_declaration define unless define.module_name == 'profile'
198
244
  end
199
245
 
200
- def hiera(klass)
201
- hiera_errors(klass.hiera_calls, klass)
246
+ def lookup(klass)
247
+ # Searches for lookup calls inside classes and defines.
248
+ lookup_errors(klass.lookup_calls, klass)
202
249
  end
203
250
 
204
- def params_without_hiera_defaults(klass)
205
- # Finds parameters that have no hiera-defined default value.
206
- klass.params.each do |name, data|
207
- next unless data[:value].select(&:hiera?).empty?
208
- token = data[:param]
251
+ def legacy_hiera(klass)
252
+ # No calls to legacy hiera
253
+ tokens = klass.legacy_hiera_calls
254
+ tokens.each do |token|
209
255
  msg = {
210
- message: "wmf-style: Parameter '#{name}' of class '#{klass.name}' has no call to hiera",
256
+ message: "wmf-style: Found deprecated function (#{token.value}) " \
257
+ "in #{klass.type} '#{klass.name}', use lookup instead",
211
258
  line: token.line,
212
259
  column: token.column
213
260
  }
@@ -215,19 +262,52 @@ def params_without_hiera_defaults(klass)
215
262
  end
216
263
  end
217
264
 
218
- def hiera_not_in_params(klass)
219
- tokens = klass.hiera_calls.reject do |token|
265
+ def params_without_lookup_defaults(klass)
266
+ # Finds parameters that have no lookup-defined default value.
267
+ klass.params.each do |name, data|
268
+ next unless data[:value].select(&:lookup?).empty?
269
+ common = "wmf-style: Parameter '#{name}' of class '#{klass.name}'"
270
+ message = if data[:value].select(&:legacy_hiera?).empty?
271
+ "#{common} has no call to lookup"
272
+ else
273
+ "#{common} hiera is deprecated use lookup"
274
+ end
275
+ token = data[:param]
276
+ msg = { message: message, line: token.line, column: token.column }
277
+ notify :error, msg
278
+ end
279
+ end
280
+
281
+ def lookup_not_in_params(klass)
282
+ # Checks if a lookup call is not in a parameter declaration. Used to check profiles
283
+
284
+ # Any lookup call that is not inside a parameter declaration is a violation
285
+ tokens = klass.lookup_calls.reject do |token|
220
286
  maybe_param = token.prev_code_token.prev_code_token
221
287
  klass.params.keys.include?(maybe_param.value)
222
288
  end
223
- hiera_errors(tokens, klass)
289
+ lookup_errors(tokens, klass)
224
290
  end
225
291
 
226
- def hiera_errors(tokens, klass)
292
+ def lookup_errors(tokens, klass)
293
+ # Helper for printing lookup errors nicely
227
294
  tokens.each do |token|
295
+ # lookup ( 'some::label' )
228
296
  value = token.next_code_token.next_code_token.value
229
297
  msg = {
230
- message: "wmf-style: Found hiera call in #{klass.type} '#{klass.name}' for '#{value}'",
298
+ message: "wmf-style: Found lookup call in #{klass.type} '#{klass.name}' for '#{value}'",
299
+ line: token.line,
300
+ column: token.column
301
+ }
302
+ notify :error, msg
303
+ end
304
+ end
305
+
306
+ def legacy_validate_errors(klass)
307
+ # Helper for printing errors nicely
308
+ klass.legacy_validate_calls.each do |token|
309
+ msg = {
310
+ message: "wmf-style: Found legacy function (#{token.value}) call in #{klass.type} '#{klass.name}'",
231
311
  line: token.line,
232
312
  column: token.column
233
313
  }
@@ -236,6 +316,9 @@ def hiera_errors(tokens, klass)
236
316
  end
237
317
 
238
318
  def profile_illegal_include(klass)
319
+ # Check if a profile includes any class that's not allowed there.
320
+ # Allowed are: any other profile, or a class from the passwords module,
321
+ # plus a couple parameter classes
239
322
  modules_include_ok = ['profile', 'passwords']
240
323
  classes_include_ok = ['lvs::configuration', 'network::constants']
241
324
  klass.included_classes.each do |token|
@@ -253,6 +336,7 @@ def profile_illegal_include(klass)
253
336
  end
254
337
 
255
338
  def class_illegal_include(klass)
339
+ # A class should only include classes from the same module.
256
340
  modules_include_ok = [klass.module_name]
257
341
  klass.included_classes.each do |token|
258
342
  class_name = token.value.gsub(/^::/, '')
@@ -268,7 +352,8 @@ def class_illegal_include(klass)
268
352
  end
269
353
 
270
354
  def include_not_profile(klass)
271
- modules_include_ok = ['role', 'profile', 'standard']
355
+ # Checks that a role only includes other roles and profiles
356
+ modules_include_ok = ['role', 'profile']
272
357
  klass.included_classes.each do |token|
273
358
  class_name = token.value.gsub(/^::/, '')
274
359
  module_name = class_name.split('::')[0]
@@ -312,6 +397,7 @@ def check_no_system_role(klass)
312
397
  end
313
398
 
314
399
  def check_system_role(klass)
400
+ # Check that a role does indeed declare system::role
315
401
  return if klass.resource?('system::role').length == 1
316
402
  msg = {
317
403
  message: "wmf-style: role '#{klass.name}' should declare system::role once",
@@ -322,6 +408,7 @@ def check_system_role(klass)
322
408
  end
323
409
 
324
410
  def check_no_defines(klass)
411
+ # In a role, check if there is any define apart from one system::role call
325
412
  return if klass.declared_resources == klass.resource?('system::role')
326
413
  msg = {
327
414
  message: "wmf-style: role '#{klass.name}' should not include defines",
@@ -331,18 +418,40 @@ def check_no_defines(klass)
331
418
  notify :error, msg
332
419
  end
333
420
 
421
+ def check_deprecations(resource)
422
+ # Check the resource for declarations of deprecated defines
423
+ legacy_validate_errors resource
424
+ legacy_hiera resource
425
+ deprecated_defines = ['base::service_unit']
426
+ deprecated_defines.each do |deprecated|
427
+ resource.resource?(deprecated).each do |token|
428
+ msg = {
429
+ message: "wmf-style: '#{resource.name}' should not include the deprecated define '#{token.value}'",
430
+ line: token.line,
431
+ column: token.column
432
+ }
433
+ notify :error, msg
434
+ end
435
+ end
436
+ end
437
+
334
438
  # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/CyclomaticComplexity
335
439
  def check_node(node)
336
440
  title = node[:title_tokens].map(&:value).join(', ')
337
441
  node[:tokens].each do |token|
338
442
  msg = nil
339
- if token.hiera?
443
+ if token.lookup?
340
444
  msg = {
341
- message: "wmf-style: Found hiera call in node '#{title}'",
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",
342
452
  line: token.line,
343
453
  column: token.column
344
454
  }
345
-
346
455
  elsif token.class_include?
347
456
  msg = {
348
457
  message: "wmf-style: node '#{title}' includes class #{token.included_class.value}",
@@ -355,18 +464,12 @@ def check_node(node)
355
464
  line: token.line,
356
465
  column: token.column
357
466
  }
358
- elsif token.declared_type?
467
+ elsif token.declared_type? && token.value != 'interface::add_ip6_mapped'
359
468
  msg = {
360
469
  message: "wmf-style: node '#{title}' declares #{token.value}",
361
470
  line: token.line,
362
471
  column: token.column
363
472
  }
364
- elsif token.role_keyword? && token.next_code_token.next_code_token.next_code_token.type != :RPAREN
365
- msg = {
366
- message: "wmf-style: node '#{title}' includes multiple roles",
367
- line: token.line,
368
- column: token.column
369
- }
370
473
  end
371
474
  notify :error, msg if msg
372
475
  end
@@ -420,6 +523,7 @@ PuppetLint.new_check(:wmf_styleguide) do
420
523
  else
421
524
  check_class klass
422
525
  end
526
+ check_deprecations klass
423
527
  end
424
528
  end
425
529
 
@@ -428,6 +532,7 @@ PuppetLint.new_check(:wmf_styleguide) do
428
532
  defined_type_indexes.each do |df|
429
533
  define = PuppetResource.new(df)
430
534
  check_define define
535
+ check_deprecations define
431
536
  end
432
537
  node_indexes.each do |node|
433
538
  check_node node
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  class_ok = <<-EOF
@@ -12,16 +14,23 @@ EOF
12
14
 
13
15
  class_ko = <<-EOF
14
16
  class foo($t=hiera('foo::title')) {
15
- $msg = hiera( "foo::bar")
17
+ $msg = lookup( "foo::bar")
16
18
  notice($msg)
17
19
  notice($t)
18
20
  include ::passwords::redis
19
21
  class { 'bar': }
22
+ validate_foobar($param)
23
+ validate_re($param, '^.*$')
24
+ hiera('foobar')
25
+ hiera_hash('foobar')
26
+ hiera_array('foobar')
20
27
  }
21
28
  EOF
22
29
 
23
30
  profile_ok = <<-EOF
24
- class profile::foobar ($test=hiera('profile::foobar::test')) {
31
+ class profile::foobar (
32
+ $test=lookup('profile::foobar::test'),
33
+ ) {
25
34
  require ::profile::foo
26
35
  include ::passwords::redis
27
36
  class { '::bar': }
@@ -30,17 +39,19 @@ EOF
30
39
 
31
40
  profile_ko = <<-EOF
32
41
  class profile::fixme (
33
- $test,
42
+ $test1,
43
+ $test2=hiera('profile::foobar::foo')
44
+ $test3=hiera_array('profile::foobar::foo')
45
+ $test4=hiera_hash('profile::foobar::foo')
34
46
  ) {
35
47
  include ::apache2::common
36
- $role = hiera('role')
48
+ $role = lookup('role')
37
49
  system::role { $role: }
38
50
  }
39
51
  EOF
40
52
 
41
53
  role_ok = <<-EOF
42
54
  class role::fizzbuz {
43
- include standard
44
55
  include ::profile::base
45
56
  include ::profile::bar
46
57
  system::role { 'fizzbuzz': }
@@ -68,6 +79,11 @@ define_ko = <<-EOF
68
79
  define foo::fixme ($a=hiera('something')) {
69
80
  include ::foo
70
81
  class { '::bar': }
82
+ validate_foobar($param)
83
+ validate_re($param, '^.*$')
84
+ hiera('foobar')
85
+ hiera_hash('foobar')
86
+ hiera_array('foobar')
71
87
  }
72
88
  EOF
73
89
 
@@ -79,12 +95,20 @@ EOF
79
95
 
80
96
  node_ko = <<-EOF
81
97
  node 'fixme' {
82
- role(spare::system,
83
- mediawiki::appserver)
84
98
  include base::firewall
85
99
  interface::mapped { 'eth0':
86
100
  foo => 'bar'
87
101
  }
102
+ lookup('foobar')
103
+ hiera('foobar')
104
+ hiera_array('foobar')
105
+ hiera_hash('foobar')
106
+ }
107
+ EOF
108
+
109
+ deprecation_ko = <<-EOF
110
+ define test() {
111
+ base::service_unit{ 'test2': }
88
112
  }
89
113
  EOF
90
114
 
@@ -112,28 +136,44 @@ describe 'wmf_styleguide' do
112
136
  context 'class with errors' do
113
137
  let(:code) { class_ko }
114
138
  it 'should create errors for hiera declarations' do
115
- expect(problems).to contain_error("wmf-style: Found hiera call in class 'foo' for 'foo::title'").on_line(1).in_column(14)
116
- expect(problems).to contain_error("wmf-style: Found hiera call in class 'foo' for 'foo::bar'").on_line(2).in_column(15)
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)
117
141
  end
118
142
  it 'should create errors for included classes' do
119
143
  expect(problems).to contain_error("wmf-style: class 'foo' includes passwords::redis from another module").on_line(5).in_column(16)
120
144
  expect(problems).to contain_error("wmf-style: class 'foo' declares class bar from another module").on_line(6).in_column(16)
121
145
  end
146
+ it 'should create errors for validate_function' do
147
+ expect(problems).to contain_error("wmf-style: Found legacy function (validate_foobar) call in class 'foo'").on_line(7).in_column(8)
148
+ expect(problems).to contain_error("wmf-style: Found legacy function (validate_re) call in class 'foo'").on_line(8).in_column(8)
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
122
159
  end
123
160
 
124
161
  context 'profile with errors' do
125
162
  let(:code) { profile_ko }
126
163
  it 'should create errors for parameters without hiera defaults' do
127
- expect(problems).to contain_error("wmf-style: Parameter 'test' of class 'profile::fixme' has no call to hiera").on_line(2).in_column(7)
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)
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)
128
168
  end
129
169
  it 'should create errors for hiera calls in body' do
130
- expect(problems).to contain_error("wmf-style: Found hiera call in class 'profile::fixme' for 'role'").on_line(5).in_column(13)
170
+ expect(problems).to contain_error("wmf-style: Found lookup call in class 'profile::fixme' for 'role'").on_line(8).in_column(13)
131
171
  end
132
172
  it 'should create errors for use of system::role' do
133
- expect(problems).to contain_error("wmf-style: class 'profile::fixme' declares system::role, which should only be used in roles").on_line(6).in_column(5)
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)
134
174
  end
135
175
  it 'should create errors for non-explicit class inclusion' do
136
- expect(problems).to contain_error("wmf-style: profile 'profile::fixme' includes non-profile class apache2::common").on_line(4).in_column(13)
176
+ expect(problems).to contain_error("wmf-style: profile 'profile::fixme' includes non-profile class apache2::common").on_line(7).in_column(13)
137
177
  end
138
178
  end
139
179
 
@@ -152,11 +192,24 @@ describe 'wmf_styleguide' do
152
192
  context 'defined type with violations' do
153
193
  let(:code) { define_ko }
154
194
  it 'should not contain hiera calls' do
155
- expect(problems).to contain_error("wmf-style: Found hiera call in defined type 'foo::fixme' for 'something'").on_line(1)
195
+ expect(problems).to contain_error("wmf-style: Found deprecated function (hiera) in defined type 'foo::fixme', use lookup instead").on_line(1)
156
196
  end
157
197
  it 'should not include or define any class' do
158
198
  expect(problems).to contain_error("wmf-style: defined type 'foo::fixme' declares class bar from another module").on_line(3)
159
199
  end
200
+ it 'should create errors for validate_function' do
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)
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)
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
160
213
  end
161
214
 
162
215
  context 'node with no errors' do
@@ -167,14 +220,30 @@ describe 'wmf_styleguide' do
167
220
  end
168
221
  context 'node with violations' do
169
222
  let(:code) { node_ko }
170
- it 'should not have multiple roles applied' do
171
- expect(problems).to contain_error("wmf-style: node 'fixme' includes multiple roles").on_line(2)
172
- end
173
223
  it 'should not include classes directly' do
174
224
  expect(problems).to contain_error("wmf-style: node 'fixme' includes class base::firewall")
175
225
  end
176
226
  it 'should not declare any defined type' do
177
227
  expect(problems).to contain_error("wmf-style: node 'fixme' declares interface::mapped")
178
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
241
+ end
242
+
243
+ context 'defined type with deprecations' do
244
+ let(:code) { deprecation_ko }
245
+ it 'should not' do
246
+ expect(problems).to contain_error("wmf-style: 'test' should not include the deprecated define 'base::service_unit'")
247
+ end
179
248
  end
180
249
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-lint'
2
4
 
3
5
  PuppetLint::Plugins.load_spec_helper
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.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: 2017-10-24 00:00:00.000000000 Z
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: 2.4.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: 2.4.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: git
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.3.0
33
+ version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.3.0
40
+ version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '12.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '12.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -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
 
@@ -118,6 +132,8 @@ description: |2
118
132
  * Check for system::role calls outside of roles
119
133
  * Check for cross-module class inclusion
120
134
  * Check for the use of the include keyword in profiles
135
+ * Check for wmf-deprecated resources usage
136
+ * Check for deprecated validate_* functions
121
137
  email: lavagetto@gmail.com
122
138
  executables: []
123
139
  extensions: []
@@ -128,7 +144,7 @@ files:
128
144
  - lib/puppet-lint/plugins/check_wmf_styleguide.rb
129
145
  - spec/puppet-lint/plugins/check_wmf_styleguide_check_spec.rb
130
146
  - spec/spec_helper.rb
131
- homepage: https://github.com/wikimedia/operations-puppet-lint-wmf_styleguide-check
147
+ homepage: https://github.com/lavagetto/puppet-lint-wmf_styleguide-check
132
148
  licenses:
133
149
  - GPL-3.0
134
150
  metadata: {}
@@ -148,10 +164,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
164
  version: '0'
149
165
  requirements: []
150
166
  rubyforge_project:
151
- rubygems_version: 2.5.2.1
167
+ rubygems_version: 2.7.6.2
152
168
  signing_key:
153
169
  specification_version: 4
154
170
  summary: A puppet-lint plugin to check code adheres to the WMF coding guidelines
155
171
  test_files:
156
- - spec/spec_helper.rb
157
172
  - spec/puppet-lint/plugins/check_wmf_styleguide_check_spec.rb
173
+ - spec/spec_helper.rb