puppet-lint 3.0.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,17 +55,18 @@ describe PuppetLint::Configuration do
55
55
  end
56
56
 
57
57
  expect(config.settings).to eq(
58
- 'with_filename' => false,
59
- 'fail_on_warnings' => false,
60
- 'error_level' => :all,
61
- 'log_format' => '',
62
- 'sarif' => false,
63
- 'with_context' => false,
64
- 'fix' => false,
65
- 'github_actions' => false,
66
- 'show_ignored' => false,
67
- 'json' => false,
68
- 'ignore_paths' => ['vendor/**/*.pp'],
58
+ 'with_filename' => false,
59
+ 'fail_on_warnings' => false,
60
+ 'codeclimate_report_file' => nil,
61
+ 'error_level' => :all,
62
+ 'log_format' => '',
63
+ 'sarif' => false,
64
+ 'with_context' => false,
65
+ 'fix' => false,
66
+ 'github_actions' => false,
67
+ 'show_ignored' => false,
68
+ 'json' => false,
69
+ 'ignore_paths' => ['vendor/**/*.pp'],
69
70
  )
70
71
  end
71
72
 
@@ -78,6 +79,15 @@ describe PuppetLint::Configuration do
78
79
  expect(config.settings['github_actions']).to be(true)
79
80
  end
80
81
 
82
+ it 'defaults codeclimate_report_file to the CODECLIMATE_REPORT_FILE environment variable' do
83
+ override_env do
84
+ ENV['CODECLIMATE_REPORT_FILE'] = '/path/to/report.json'
85
+ config.defaults
86
+ end
87
+
88
+ expect(config.settings['codeclimate_report_file']).to eq('/path/to/report.json')
89
+ end
90
+
81
91
  def override_env
82
92
  old_env = ENV.to_h
83
93
  yield
@@ -33,6 +33,42 @@ describe PuppetLint::Data do
33
33
  }
34
34
  end
35
35
  end
36
+
37
+ context 'when given a defaults declaration' do
38
+ let(:manifest) { "Service { 'foo': }" }
39
+
40
+ it 'returns an empty array' do
41
+ expect(data.resource_indexes).to eq([])
42
+ end
43
+ end
44
+
45
+ context 'when given a set of resource declarations' do
46
+ let(:manifest) { <<-MANIFEST }
47
+ service {
48
+ 'foo':
49
+ ensure => running,
50
+ }
51
+
52
+ service {
53
+ 'bar':
54
+ ensure => running;
55
+ 'foobar':
56
+ ensure => stopped;
57
+ }
58
+
59
+ service { ['first', 'second']:
60
+ ensure => running,
61
+ }
62
+
63
+ service { 'third':
64
+ ensure => running,
65
+ }
66
+ MANIFEST
67
+
68
+ it 'returns an array of resource indexes' do
69
+ expect(data.resource_indexes.length).to eq(5)
70
+ end
71
+ end
36
72
  end
37
73
 
38
74
  describe '.insert' do
@@ -105,5 +105,17 @@ describe 'trailing_whitespace' do
105
105
  expect(manifest).to eq(fixed)
106
106
  end
107
107
  end
108
+
109
+ context 'empty lines with nothing but whitespace' do
110
+ let(:code) { " \n " }
111
+
112
+ it 'detects problems with both empty lines' do
113
+ expect(problems).to have(2).problem
114
+ end
115
+
116
+ it 'fixes the manifest' do
117
+ expect(manifest).to eq("\n")
118
+ end
119
+ end
108
120
  end
109
121
  end
@@ -0,0 +1,447 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'legacy_facts' do
4
+ context 'with fix disabled' do
5
+ context "fact variable using modern $facts['os']['family'] hash" do
6
+ let(:code) { "$facts['os']['family']" }
7
+
8
+ it 'does not detect any problems' do
9
+ expect(problems).to have(0).problem
10
+ end
11
+ end
12
+
13
+ context "fact variable using modern $facts['ssh']['rsa']['key'] hash" do
14
+ let(:code) { "$facts['ssh']['rsa']['key']" }
15
+
16
+ it 'does not detect any problems' do
17
+ expect(problems).to have(0).problem
18
+ end
19
+ end
20
+
21
+ context 'fact variable using legacy $osfamily' do
22
+ let(:code) { '$osfamily' }
23
+
24
+ it 'does not detect any problems' do
25
+ expect(problems).to have(0).problem
26
+ end
27
+ end
28
+
29
+ context "fact variable using legacy $facts['osfamily']" do
30
+ let(:code) { "$facts['osfamily']" }
31
+
32
+ it 'onlies detect a single problem' do
33
+ expect(problems).to have(1).problem
34
+ end
35
+ end
36
+
37
+ context 'fact variable using legacy $::osfamily' do
38
+ let(:code) { '$::osfamily' }
39
+
40
+ it 'onlies detect a single problem' do
41
+ expect(problems).to have(1).problem
42
+ end
43
+ end
44
+
45
+ context 'fact variable using legacy $::blockdevice_sda_model' do
46
+ let(:code) { '$::blockdevice_sda_model' }
47
+
48
+ it 'onlies detect a single problem' do
49
+ expect(problems).to have(1).problem
50
+ end
51
+ end
52
+
53
+ context "fact variable using legacy $facts['ipaddress6_em2']" do
54
+ let(:code) { "$facts['ipaddress6_em2']" }
55
+
56
+ it 'onlies detect a single problem' do
57
+ expect(problems).to have(1).problem
58
+ end
59
+ end
60
+
61
+ context 'fact variable using legacy $::zone_foobar_uuid' do
62
+ let(:code) { '$::zone_foobar_uuid' }
63
+
64
+ it 'onlies detect a single problem' do
65
+ expect(problems).to have(1).problem
66
+ end
67
+ end
68
+
69
+ context 'fact variable using legacy $::processor314' do
70
+ let(:code) { '$::processor314' }
71
+
72
+ it 'onlies detect a single problem' do
73
+ expect(problems).to have(1).problem
74
+ end
75
+ end
76
+
77
+ context 'fact variable using legacy $::sp_l3_cache' do
78
+ let(:code) { '$::sp_l3_cache' }
79
+
80
+ it 'onlies detect a single problem' do
81
+ expect(problems).to have(1).problem
82
+ end
83
+ end
84
+
85
+ context 'fact variable using legacy $::sshrsakey' do
86
+ let(:code) { '$::sshrsakey' }
87
+
88
+ it 'onlies detect a single problem' do
89
+ expect(problems).to have(1).problem
90
+ end
91
+ end
92
+
93
+ context 'fact variable in interpolated string "${::osfamily}"' do
94
+ let(:code) { '"start ${::osfamily} end"' }
95
+
96
+ it 'onlies detect a single problem' do
97
+ expect(problems).to have(1).problem
98
+ end
99
+ end
100
+
101
+ context 'fact variable using legacy variable in double quotes "$::osfamily"' do
102
+ let(:code) { '"$::osfamily"' }
103
+
104
+ it 'onlies detect a single problem' do
105
+ expect(problems).to have(1).problem
106
+ end
107
+ end
108
+
109
+ context 'fact variable using legacy facts hash variable in interpolation' do
110
+ let(:code) { %("${facts['osfamily']}") }
111
+
112
+ it 'detects a single problem' do
113
+ expect(problems).to have(1).problem
114
+ end
115
+ end
116
+
117
+ context 'top scoped fact variable using legacy facts hash variable in interpolation' do
118
+ let(:code) { "$::facts['osfamily']" }
119
+
120
+ it 'detects a single problem' do
121
+ expect(problems).to have(1).problem
122
+ end
123
+ end
124
+ end
125
+
126
+ context 'with fix enabled' do
127
+ before(:each) do
128
+ PuppetLint.configuration.fix = true
129
+ end
130
+
131
+ after(:each) do
132
+ PuppetLint.configuration.fix = false
133
+ end
134
+
135
+ context "fact variable using modern $facts['os']['family'] hash" do
136
+ let(:code) { "$facts['os']['family']" }
137
+
138
+ it 'does not detect any problems' do
139
+ expect(problems).to have(0).problem
140
+ end
141
+ end
142
+
143
+ context "fact variable using modern $facts['ssh']['rsa']['key'] hash" do
144
+ let(:code) { "$facts['ssh']['rsa']['key']" }
145
+
146
+ it 'does not detect any problems' do
147
+ expect(problems).to have(0).problem
148
+ end
149
+ end
150
+
151
+ context 'fact variable using legacy $osfamily' do
152
+ let(:code) { '$osfamily' }
153
+
154
+ it 'does not detect any problems' do
155
+ expect(problems).to have(0).problem
156
+ end
157
+ end
158
+
159
+ context "fact variable using legacy $facts['osfamily']" do
160
+ let(:code) { "$facts['osfamily']" }
161
+ let(:msg) { "legacy fact 'osfamily'" }
162
+
163
+ it 'onlies detect a single problem' do
164
+ expect(problems).to have(1).problem
165
+ end
166
+
167
+ it 'fixes the problem' do
168
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
169
+ end
170
+
171
+ it 'uses the facts hash' do
172
+ expect(manifest).to eq("$facts['os']['family']")
173
+ end
174
+ end
175
+
176
+ context 'fact variable using top scope $::facts hash' do
177
+ let(:code) { "$::facts['os']['family']" }
178
+
179
+ it 'does not detect any problems' do
180
+ expect(problems).to have(0).problem
181
+ end
182
+ end
183
+
184
+ context "fact variable using legacy top scope $::facts['osfamily']" do
185
+ let(:code) { "$::facts['osfamily']" }
186
+ let(:msg) { "legacy fact 'osfamily'" }
187
+
188
+ it 'only detects a single problem' do
189
+ expect(problems).to have(1).problem
190
+ end
191
+
192
+ it 'fixes the problem' do
193
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
194
+ end
195
+
196
+ it 'uses the facts hash' do
197
+ expect(manifest).to eq("$facts['os']['family']")
198
+ end
199
+ end
200
+
201
+ context 'fact variable using legacy $::osfamily' do
202
+ let(:code) { '$::osfamily' }
203
+ let(:msg) { "legacy fact 'osfamily'" }
204
+
205
+ it 'onlies detect a single problem' do
206
+ expect(problems).to have(1).problem
207
+ end
208
+
209
+ it 'fixes the problem' do
210
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
211
+ end
212
+
213
+ it 'uses the facts hash' do
214
+ expect(manifest).to eq("$facts['os']['family']")
215
+ end
216
+ end
217
+
218
+ context 'fact variable using legacy $::sshrsakey' do
219
+ let(:code) { '$::sshrsakey' }
220
+ let(:msg) { "legacy fact 'sshrsakey'" }
221
+
222
+ it 'onlies detect a single problem' do
223
+ expect(problems).to have(1).problem
224
+ end
225
+
226
+ it 'fixes the problem' do
227
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
228
+ end
229
+
230
+ it 'uses the facts hash' do
231
+ expect(manifest).to eq("$facts['ssh']['rsa']['key']")
232
+ end
233
+ end
234
+
235
+ context 'fact variable using legacy $::memoryfree_mb' do
236
+ let(:code) { '$::memoryfree_mb' }
237
+
238
+ it 'onlies detect a single problem' do
239
+ expect(problems).to have(1).problem
240
+ end
241
+
242
+ it 'continues to use the legacy fact' do
243
+ expect(manifest).to eq('$::memoryfree_mb')
244
+ end
245
+ end
246
+
247
+ context 'fact variable using legacy $::blockdevice_sda_model' do
248
+ let(:code) { '$::blockdevice_sda_model' }
249
+
250
+ it 'onlies detect a single problem' do
251
+ expect(problems).to have(1).problem
252
+ end
253
+ it 'uses the facts hash' do
254
+ expect(manifest).to eq("$facts['disks']['sda']['model']")
255
+ end
256
+ end
257
+
258
+ context "fact variable using legacy $facts['ipaddress6_em2']" do
259
+ let(:code) { "$facts['ipaddress6_em2']" }
260
+
261
+ it 'onlies detect a single problem' do
262
+ expect(problems).to have(1).problem
263
+ end
264
+ it 'uses the facts hash' do
265
+ expect(manifest).to eq("$facts['networking']['interfaces']['em2']['ip6']")
266
+ end
267
+ end
268
+
269
+ context 'fact variable using legacy $::zone_foobar_uuid' do
270
+ let(:code) { '$::zone_foobar_uuid' }
271
+
272
+ it 'onlies detect a single problem' do
273
+ expect(problems).to have(1).problem
274
+ end
275
+ it 'uses the facts hash' do
276
+ expect(manifest).to eq("$facts['solaris_zones']['zones']['foobar']['uuid']")
277
+ end
278
+ end
279
+
280
+ context 'fact variable using legacy $::processor314' do
281
+ let(:code) { '$::processor314' }
282
+
283
+ it 'onlies detect a single problem' do
284
+ expect(problems).to have(1).problem
285
+ end
286
+ it 'uses the facts hash' do
287
+ expect(manifest).to eq("$facts['processors']['models'][314]")
288
+ end
289
+ end
290
+
291
+ context 'fact variable using legacy $::sp_l3_cache' do
292
+ let(:code) { '$::sp_l3_cache' }
293
+
294
+ it 'onlies detect a single problem' do
295
+ expect(problems).to have(1).problem
296
+ end
297
+ it 'uses the facts hash' do
298
+ expect(manifest).to eq("$facts['system_profiler']['l3_cache']")
299
+ end
300
+ end
301
+
302
+ context 'fact variable using legacy $::sshrsakey' do
303
+ let(:code) { '$::sshrsakey' }
304
+
305
+ it 'onlies detect a single problem' do
306
+ expect(problems).to have(1).problem
307
+ end
308
+ it 'uses the facts hash' do
309
+ expect(manifest).to eq("$facts['ssh']['rsa']['key']")
310
+ end
311
+ end
312
+
313
+ context 'fact variable in interpolated string "${::osfamily}"' do
314
+ let(:code) { '"start ${::osfamily} end"' }
315
+
316
+ it 'onlies detect a single problem' do
317
+ expect(problems).to have(1).problem
318
+ end
319
+
320
+ it 'uses the facts hash' do
321
+ expect(manifest).to eq('"start '"${facts['os']['family']}"' end"') # rubocop:disable Lint/ImplicitStringConcatenation
322
+ end
323
+ end
324
+
325
+ context 'fact variable using legacy variable in double quotes "$::osfamily"' do
326
+ let(:code) { '"$::osfamily"' }
327
+
328
+ it 'onlies detect a single problem' do
329
+ expect(problems).to have(1).problem
330
+ end
331
+
332
+ it 'uses the facts hash' do
333
+ expect(manifest).to eq("\"$facts['os']['family']\"")
334
+ end
335
+ end
336
+ context 'fact variable using legacy variable in double quotes "$::gid"' do
337
+ let(:code) { '"$::gid"' }
338
+
339
+ it 'onlies detect a single problem' do
340
+ expect(problems).to have(1).problem
341
+ end
342
+
343
+ it 'uses the facts hash' do
344
+ expect(manifest).to eq("\"$facts['identity']['group']\"")
345
+ end
346
+ end
347
+ context 'fact variable using legacy variable in double quotes "$::id"' do
348
+ let(:code) { '"$::id"' }
349
+
350
+ it 'onlies detect a single problem' do
351
+ expect(problems).to have(1).problem
352
+ end
353
+
354
+ it 'uses the facts hash' do
355
+ expect(manifest).to eq("\"$facts['identity']['user']\"")
356
+ end
357
+ end
358
+ context 'fact variable using legacy variable in double quotes "$::lsbdistcodename"' do
359
+ let(:code) { '"$::lsbdistcodename"' }
360
+
361
+ it 'onlies detect a single problem' do
362
+ expect(problems).to have(1).problem
363
+ end
364
+
365
+ it 'uses the facts hash' do
366
+ expect(manifest).to eq("\"$facts['os']['distro']['codename']\"")
367
+ end
368
+ end
369
+ context 'fact variable using legacy variable in double quotes "$::lsbdistdescription"' do
370
+ let(:code) { '"$::lsbdistdescription"' }
371
+
372
+ it 'onlies detect a single problem' do
373
+ expect(problems).to have(1).problem
374
+ end
375
+
376
+ it 'uses the facts hash' do
377
+ expect(manifest).to eq("\"$facts['os']['distro']['description']\"")
378
+ end
379
+ end
380
+ context 'fact variable using legacy variable in double quotes "$::lsbdistid"' do
381
+ let(:code) { '"$::lsbdistid"' }
382
+
383
+ it 'onlies detect a single problem' do
384
+ expect(problems).to have(1).problem
385
+ end
386
+
387
+ it 'uses the facts hash' do
388
+ expect(manifest).to eq("\"$facts['os']['distro']['id']\"")
389
+ end
390
+ end
391
+ context 'fact variable using legacy variable in double quotes "$::lsbdistrelease"' do
392
+ let(:code) { '"$::lsbdistrelease"' }
393
+
394
+ it 'onlies detect a single problem' do
395
+ expect(problems).to have(1).problem
396
+ end
397
+
398
+ it 'uses the facts hash' do
399
+ expect(manifest).to eq("\"$facts['os']['distro']['release']['full']\"")
400
+ end
401
+ end
402
+ context 'fact variable using legacy variable in double quotes "$::lsbmajdistrelease"' do
403
+ let(:code) { '"$::lsbmajdistrelease"' }
404
+
405
+ it 'onlies detect a single problem' do
406
+ expect(problems).to have(1).problem
407
+ end
408
+
409
+ it 'uses the facts hash' do
410
+ expect(manifest).to eq("\"$facts['os']['distro']['release']['major']\"")
411
+ end
412
+ end
413
+ context 'fact variable using legacy variable in double quotes "$::lsbminordistrelease"' do
414
+ let(:code) { '"$::lsbminordistrelease"' }
415
+
416
+ it 'onlies detect a single problem' do
417
+ expect(problems).to have(1).problem
418
+ end
419
+
420
+ it 'uses the facts hash' do
421
+ expect(manifest).to eq("\"$facts['os']['distro']['release']['minor']\"")
422
+ end
423
+ end
424
+ context 'fact variable using legacy variable in double quotes "$::lsbrelease"' do
425
+ let(:code) { '"$::lsbrelease"' }
426
+
427
+ it 'onlies detect a single problem' do
428
+ expect(problems).to have(1).problem
429
+ end
430
+
431
+ it 'uses the facts hash' do
432
+ expect(manifest).to eq("\"$facts['os']['distro']['release']['specification']\"")
433
+ end
434
+ end
435
+ context "fact variable using facts hash in double quotes \"$facts['lsbrelease']\"" do
436
+ let(:code) { "\"${facts['lsbrelease']}\"" }
437
+
438
+ it 'onlies detect a single problem' do
439
+ expect(problems).to have(1).problem
440
+ end
441
+
442
+ it 'uses the facts hash' do
443
+ expect(manifest).to eq("\"${facts['os']['distro']['release']['specification']}\"")
444
+ end
445
+ end
446
+ end
447
+ end