puppet-lint 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.rspec +1 -0
  4. data/.travis.yml +11 -2
  5. data/CHANGELOG.md +657 -0
  6. data/Gemfile +19 -0
  7. data/README.md +6 -1
  8. data/lib/puppet-lint.rb +1 -1
  9. data/lib/puppet-lint/checks.rb +1 -5
  10. data/lib/puppet-lint/lexer.rb +4 -2
  11. data/lib/puppet-lint/optparser.rb +11 -2
  12. data/lib/puppet-lint/plugins/check_classes.rb +5 -1
  13. data/lib/puppet-lint/plugins/check_comments.rb +6 -8
  14. data/lib/puppet-lint/plugins/check_resources.rb +4 -3
  15. data/lib/puppet-lint/plugins/check_variables.rb +21 -3
  16. data/lib/puppet-lint/plugins/check_whitespace.rb +21 -1
  17. data/lib/puppet-lint/tasks/puppet-lint.rb +4 -0
  18. data/lib/puppet-lint/version.rb +1 -1
  19. data/puppet-lint.gemspec +1 -4
  20. data/spec/puppet-lint/bin_spec.rb +1 -1
  21. data/spec/puppet-lint/lexer_spec.rb +38 -0
  22. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +51 -47
  23. data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +22 -0
  24. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +19 -0
  25. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +96 -0
  26. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +28 -0
  27. data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +3 -3
  28. data/spec/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb +25 -0
  29. data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +71 -0
  30. data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +37 -37
  31. data/spec/puppet-lint_spec.rb +6 -0
  32. metadata +13 -50
@@ -29,6 +29,28 @@ describe 'star_comments' do
29
29
  PuppetLint.configuration.fix = false
30
30
  end
31
31
 
32
+ context 'multiline comment w/ no indents' do
33
+ let(:code) { "/* foo *
34
+ * *
35
+ * bar */"}
36
+
37
+ let(:fixed) { "# foo *
38
+ # *
39
+ # bar"}
40
+
41
+ it 'should only detect a single problem' do
42
+ expect(problems).to have(1).problem
43
+ end
44
+
45
+ it 'should create a warning' do
46
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
47
+ end
48
+
49
+ it 'should convert the multiline comment' do
50
+ expect(manifest).to eq(fixed)
51
+ end
52
+ end
53
+
32
54
  context 'multiline comment w/ one line of content' do
33
55
  let(:code) { "
34
56
  /* foo
@@ -52,4 +52,23 @@ describe 'ensure_first_param' do
52
52
  expect(problems).to have(0).problems
53
53
  end
54
54
  end
55
+
56
+ context 'ensure as a hash key in classes does not need to be first' do
57
+ let(:code) { "
58
+ class thing {
59
+ class {'thang':
60
+ stuff => {
61
+ 'stuffing' => {
62
+ ensure => 'present',
63
+ blah => 'bleah',
64
+ }
65
+ },
66
+ }
67
+ }"
68
+ }
69
+
70
+ it 'should not detect any problems' do
71
+ expect(problems).to have(0).problems
72
+ end
73
+ end
55
74
  end
@@ -67,6 +67,70 @@ describe 'file_mode' do
67
67
  expect(problems).to have(0).problems
68
68
  end
69
69
  end
70
+
71
+ context '3 digit concat mode' do
72
+ let(:code) { "concat { 'foo': mode => '777' }" }
73
+
74
+ it 'should only detect a single problem' do
75
+ expect(problems).to have(1).problem
76
+ end
77
+
78
+ it 'should create a warning' do
79
+ expect(problems).to contain_warning(msg).on_line(1).in_column(25)
80
+ end
81
+ end
82
+
83
+ context '4 digit concat mode' do
84
+ let(:code) { "concat { 'foo': mode => '0777' }" }
85
+
86
+ it 'should not detect any problems' do
87
+ expect(problems).to have(0).problems
88
+ end
89
+ end
90
+
91
+ context 'concat mode as a variable' do
92
+ let(:code) { "concat { 'foo': mode => $concat_mode }" }
93
+
94
+ it 'should not detect any problems' do
95
+ expect(problems).to have(0).problems
96
+ end
97
+ end
98
+
99
+ context 'symbolic concat mode' do
100
+ let(:code) { "concat { 'foo': mode => 'u=rw,og=r' }" }
101
+
102
+ it 'should not detect any problems' do
103
+ expect(problems).to have(0).problems
104
+ end
105
+ end
106
+
107
+ context 'concat mode undef unquoted' do
108
+ let(:code) { "concat { 'foo': mode => undef }" }
109
+
110
+ it 'should not detect any problems' do
111
+ expect(problems).to have(0).problems
112
+ end
113
+ end
114
+
115
+ context 'concat mode undef quoted' do
116
+ let(:code) { "concat { 'foo': mode => 'undef' }" }
117
+
118
+ it 'should only detect a single problem' do
119
+ expect(problems).to have(1).problem
120
+ end
121
+
122
+ it 'should create a warning' do
123
+ expect(problems).to contain_warning(msg).on_line(1).in_column(25)
124
+ end
125
+ end
126
+
127
+ context 'mode as audit value' do
128
+ let(:code) { "concat { '/etc/passwd': audit => [ owner, mode ], }" }
129
+
130
+ it 'should not detect any problems' do
131
+ expect(problems).to have(0).problems
132
+ end
133
+ end
70
134
  end
71
135
 
72
136
  context 'with fix enabled' do
@@ -109,5 +173,37 @@ describe 'file_mode' do
109
173
  expect(manifest).to eq(code)
110
174
  end
111
175
  end
176
+
177
+ context '3 digit concat mode' do
178
+ let(:code) { "concat { 'foo': mode => '777' }" }
179
+
180
+ it 'should only detect a single problem' do
181
+ expect(problems).to have(1).problem
182
+ end
183
+
184
+ it 'should fix the manifest' do
185
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(25)
186
+ end
187
+
188
+ it 'should zero pad the concat mode' do
189
+ expect(manifest).to eq("concat { 'foo': mode => '0777' }")
190
+ end
191
+ end
192
+
193
+ context 'concat mode undef quoted' do
194
+ let(:code) { "concat { 'foo': mode => 'undef' }" }
195
+
196
+ it 'should only detect a single problem' do
197
+ expect(problems).to have(1).problem
198
+ end
199
+
200
+ it 'should create a warning' do
201
+ expect(problems).to contain_warning(msg).on_line(1).in_column(25)
202
+ end
203
+
204
+ it 'should not modify the original manifest' do
205
+ expect(manifest).to eq(code)
206
+ end
207
+ end
112
208
  end
113
209
  end
@@ -15,6 +15,18 @@ describe 'unquoted_file_mode' do
15
15
  expect(problems).to contain_warning(msg).on_line(1).in_column(23)
16
16
  end
17
17
  end
18
+
19
+ context '4 digit unquoted file mode' do
20
+ let(:code) { "concat { 'foo': mode => 0777 }" }
21
+
22
+ it 'should only detect a single problem' do
23
+ expect(problems).to have(1).problem
24
+ end
25
+
26
+ it 'should create a warning' do
27
+ expect(problems).to contain_warning(msg).on_line(1).in_column(25)
28
+ end
29
+ end
18
30
  end
19
31
 
20
32
  context 'with fix enabled' do
@@ -41,5 +53,21 @@ describe 'unquoted_file_mode' do
41
53
  expect(manifest).to eq("file { 'foo': mode => '0777' }")
42
54
  end
43
55
  end
56
+
57
+ context '4 digit unquoted file mode w/fix' do
58
+ let(:code) { "concat { 'foo': mode => 0777 }" }
59
+
60
+ it 'should only detect a single problem' do
61
+ expect(problems).to have(1).problem
62
+ end
63
+
64
+ it 'should fix the manifest' do
65
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(25)
66
+ end
67
+
68
+ it 'should single quote the file mode' do
69
+ expect(manifest).to eq("concat { 'foo': mode => '0777' }")
70
+ end
71
+ end
44
72
  end
45
73
  end
@@ -39,10 +39,10 @@ describe 'variables_not_enclosed' do
39
39
  end
40
40
 
41
41
  context 'variable not enclosed in {}' do
42
- let(:code) { '" $gronk"' }
42
+ let(:code) { '" $gronk-$grouik"' }
43
43
 
44
44
  it 'should only detect a single problem' do
45
- expect(problems).to have(1).problem
45
+ expect(problems).to have(2).problem
46
46
  end
47
47
 
48
48
  it 'should fix the manifest' do
@@ -50,7 +50,7 @@ describe 'variables_not_enclosed' do
50
50
  end
51
51
 
52
52
  it 'should enclose the variable in braces' do
53
- expect(manifest).to eq('" ${gronk}"')
53
+ expect(manifest).to eq('" ${gronk}-${grouik}"')
54
54
  end
55
55
  end
56
56
 
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'variable_is_lowercase' do
4
+ let(:msg) { 'variable contains an uppercase letter' }
5
+
6
+ context 'a variable containing an uppercase letter' do
7
+ let(:code) { '$fooBar' }
8
+
9
+ it 'should only detect a single problem' do
10
+ expect(problems).to have(1).problem
11
+ end
12
+
13
+ it 'should create a warning' do
14
+ expect(problems).to contain_warning(msg).on_line(1).in_column(1)
15
+ end
16
+ end
17
+
18
+ context 'a variable containing only lowercase letters' do
19
+ let(:code) { '$foobar' }
20
+
21
+ it 'should not detect any problems' do
22
+ expect(problems).to have(0).problems
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe '80chars' do
5
+ before do
6
+ PuppetLint.configuration.send("enable_80chars")
7
+ end
8
+
9
+ let(:msg) { 'line has more than 80 characters' }
10
+
11
+ context 'file resource with a source line > 80c' do
12
+ let(:code) { "
13
+ file {
14
+ source => 'puppet:///modules/certificates/etc/ssl/private/wildcard.example.com.crt',
15
+ }"
16
+ }
17
+
18
+ it 'should not detect any problems' do
19
+ expect(problems).to have(0).problems
20
+ end
21
+ end
22
+
23
+ context 'file resource with a template line > 80c' do
24
+ let(:code) { "
25
+ file {
26
+ content => template('mymodule/this/is/a/truely/absurdly/long/path/that/should/make/you/feel/bad'),
27
+ }"
28
+ }
29
+
30
+ it 'should not detect any problems' do
31
+ expect(problems).to have(0).problems
32
+ end
33
+ end
34
+
35
+ context 'length of lines with UTF-8 characters' do
36
+ let(:code) { "
37
+ # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
38
+ # ┃ Configuration ┃
39
+ # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
40
+ }
41
+
42
+ it 'should not detect any problems' do
43
+ expect(problems).to have(0).problems
44
+ end
45
+ end
46
+
47
+ context '81 character line' do
48
+ let(:code) { 'a' * 81 }
49
+
50
+ it 'should only detect a single problem' do
51
+ expect(problems).to have(1).problem
52
+ end
53
+
54
+ it 'should create a warning' do
55
+ expect(problems).to contain_warning(msg).on_line(1).in_column(80)
56
+ end
57
+ end
58
+
59
+ # TODO: figure out why rspec keeps enabling this check!
60
+ #
61
+ # context '81 character line with disabled check' do
62
+ # let(:code) { 'a' * 81 }
63
+ #
64
+ # PuppetLint.configuration.send("disable_80chars")
65
+ #
66
+ # it 'should not detect any problems' do
67
+ # expect(problems).to have(0).problem
68
+ # end
69
+ # end
70
+
71
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'arrow_alignment' do
4
- let(:msg) { 'indentation of => is not properly aligned' }
4
+ let(:msg) { 'indentation of => is not properly aligned (expected in column %d, but found it in column %d)' }
5
5
 
6
6
  context 'with fix disabled' do
7
7
  context 'selectors inside a resource' do
@@ -119,10 +119,10 @@ describe 'arrow_alignment' do
119
119
  end
120
120
 
121
121
  it 'should create four warnings' do
122
- expect(problems).to contain_warning(msg).on_line(3).in_column(15)
123
- expect(problems).to contain_warning(msg).on_line(4).in_column(15)
124
- expect(problems).to contain_warning(msg).on_line(6).in_column(16)
125
- expect(problems).to contain_warning(msg).on_line(7).in_column(15)
122
+ expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(3).in_column(15)
123
+ expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(4).in_column(15)
124
+ expect(problems).to contain_warning(sprintf(msg,17,16)).on_line(6).in_column(16)
125
+ expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(7).in_column(15)
126
126
  end
127
127
  end
128
128
 
@@ -142,10 +142,10 @@ describe 'arrow_alignment' do
142
142
  end
143
143
 
144
144
  it 'should create four warnings' do
145
- expect(problems).to contain_warning(msg).on_line(3).in_column(15)
146
- expect(problems).to contain_warning(msg).on_line(4).in_column(15)
147
- expect(problems).to contain_warning(msg).on_line(6).in_column(16)
148
- expect(problems).to contain_warning(msg).on_line(7).in_column(15)
145
+ expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(3).in_column(15)
146
+ expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(4).in_column(15)
147
+ expect(problems).to contain_warning(sprintf(msg,17,16)).on_line(6).in_column(16)
148
+ expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(7).in_column(15)
149
149
  end
150
150
  end
151
151
  context 'complex resource with a misaligned =>' do
@@ -166,9 +166,9 @@ describe 'arrow_alignment' do
166
166
  end
167
167
 
168
168
  it 'should create three warnings' do
169
- expect(problems).to contain_warning(msg).on_line(3).in_column(15)
170
- expect(problems).to contain_warning(msg).on_line(6).in_column(17)
171
- expect(problems).to contain_warning(msg).on_line(9).in_column(15)
169
+ expect(problems).to contain_warning(sprintf(msg,16,15)).on_line(3).in_column(15)
170
+ expect(problems).to contain_warning(sprintf(msg,19,17)).on_line(6).in_column(17)
171
+ expect(problems).to contain_warning(sprintf(msg,16,15)).on_line(9).in_column(15)
172
172
  end
173
173
  end
174
174
 
@@ -189,7 +189,7 @@ describe 'arrow_alignment' do
189
189
  end
190
190
 
191
191
  it 'should create a warning' do
192
- expect(problems).to contain_warning(msg).on_line(8).in_column(17)
192
+ expect(problems).to contain_warning(sprintf(msg,19,17)).on_line(8).in_column(17)
193
193
  end
194
194
  end
195
195
 
@@ -214,10 +214,10 @@ describe 'arrow_alignment' do
214
214
  end
215
215
 
216
216
  it 'should create a warning' do
217
- expect(problems).to contain_warning(msg).on_line(5).in_column(19)
218
- expect(problems).to contain_warning(msg).on_line(6).in_column(18)
219
- expect(problems).to contain_warning(msg).on_line(11).in_column(19)
220
- expect(problems).to contain_warning(msg).on_line(12).in_column(18)
217
+ expect(problems).to contain_warning(sprintf(msg,20,19)).on_line(5).in_column(19)
218
+ expect(problems).to contain_warning(sprintf(msg,20,18)).on_line(6).in_column(18)
219
+ expect(problems).to contain_warning(sprintf(msg,20,19)).on_line(11).in_column(19)
220
+ expect(problems).to contain_warning(sprintf(msg,20,18)).on_line(12).in_column(18)
221
221
  end
222
222
  end
223
223
 
@@ -282,8 +282,8 @@ describe 'arrow_alignment' do
282
282
  end
283
283
 
284
284
  it 'should create 2 warnings' do
285
- expect(problems).to contain_warning(msg).on_line(3).in_column(19)
286
- expect(problems).to contain_warning(msg).on_line(4).in_column(19)
285
+ expect(problems).to contain_warning(sprintf(msg,18,19)).on_line(3).in_column(19)
286
+ expect(problems).to contain_warning(sprintf(msg,18,19)).on_line(4).in_column(19)
287
287
  end
288
288
  end
289
289
 
@@ -314,8 +314,8 @@ describe 'arrow_alignment' do
314
314
  end
315
315
 
316
316
  it 'should create 2 warnings' do
317
- expect(problems).to contain_warning(msg).on_line(3).in_column(13)
318
- expect(problems).to contain_warning(msg).on_line(3).in_column(26)
317
+ expect(problems).to contain_warning(sprintf(msg,15,13)).on_line(3).in_column(13)
318
+ expect(problems).to contain_warning(sprintf(msg,15,26)).on_line(3).in_column(26)
319
319
  end
320
320
  end
321
321
 
@@ -368,10 +368,10 @@ describe 'arrow_alignment' do
368
368
  end
369
369
 
370
370
  it 'should fix the manifest' do
371
- expect(problems).to contain_fixed(msg).on_line(3).in_column(15)
372
- expect(problems).to contain_fixed(msg).on_line(4).in_column(15)
373
- expect(problems).to contain_fixed(msg).on_line(6).in_column(16)
374
- expect(problems).to contain_fixed(msg).on_line(7).in_column(15)
371
+ expect(problems).to contain_fixed(sprintf(msg,17,15)).on_line(3).in_column(15)
372
+ expect(problems).to contain_fixed(sprintf(msg,17,15)).on_line(4).in_column(15)
373
+ expect(problems).to contain_fixed(sprintf(msg,17,16)).on_line(6).in_column(16)
374
+ expect(problems).to contain_fixed(sprintf(msg,17,15)).on_line(7).in_column(15)
375
375
  end
376
376
 
377
377
  it 'should align the arrows' do
@@ -408,9 +408,9 @@ describe 'arrow_alignment' do
408
408
  end
409
409
 
410
410
  it 'should fix the manifest' do
411
- expect(problems).to contain_fixed(msg).on_line(3).in_column(15)
412
- expect(problems).to contain_fixed(msg).on_line(6).in_column(17)
413
- expect(problems).to contain_fixed(msg).on_line(9).in_column(15)
411
+ expect(problems).to contain_fixed(sprintf(msg,16,15)).on_line(3).in_column(15)
412
+ expect(problems).to contain_fixed(sprintf(msg,19,17)).on_line(6).in_column(17)
413
+ expect(problems).to contain_fixed(sprintf(msg,16,15)).on_line(9).in_column(15)
414
414
  end
415
415
 
416
416
  it 'should align the arrows' do
@@ -445,7 +445,7 @@ describe 'arrow_alignment' do
445
445
  end
446
446
 
447
447
  it 'should fix the manifest' do
448
- expect(problems).to contain_fixed(msg).on_line(8).in_column(17)
448
+ expect(problems).to contain_fixed(sprintf(msg,19,17)).on_line(8).in_column(17)
449
449
  end
450
450
 
451
451
  it 'should align the arrows' do
@@ -473,8 +473,8 @@ describe 'arrow_alignment' do
473
473
  end
474
474
 
475
475
  it 'should create 2 warnings' do
476
- expect(problems).to contain_fixed(msg).on_line(3).in_column(19)
477
- expect(problems).to contain_fixed(msg).on_line(4).in_column(19)
476
+ expect(problems).to contain_fixed(sprintf(msg,18,19)).on_line(3).in_column(19)
477
+ expect(problems).to contain_fixed(sprintf(msg,18,19)).on_line(4).in_column(19)
478
478
  end
479
479
 
480
480
  it 'should realign the arrows with the minimum whitespace' do
@@ -502,7 +502,7 @@ describe 'arrow_alignment' do
502
502
  end
503
503
 
504
504
  it 'should fix the problem' do
505
- expect(problems).to contain_fixed(msg).on_line(4).in_column(17)
505
+ expect(problems).to contain_fixed(sprintf(msg,18,17)).on_line(4).in_column(17)
506
506
  end
507
507
 
508
508
  it 'should add whitespace between the param and the arrow' do
@@ -531,8 +531,8 @@ describe 'arrow_alignment' do
531
531
  end
532
532
 
533
533
  it 'should fix 2 problems' do
534
- expect(problems).to contain_fixed(msg).on_line(3).in_column(13)
535
- expect(problems).to contain_fixed(msg).on_line(3).in_column(26)
534
+ expect(problems).to contain_fixed(sprintf(msg,15,13)).on_line(3).in_column(13)
535
+ expect(problems).to contain_fixed(sprintf(msg,15,26)).on_line(3).in_column(26)
536
536
  end
537
537
 
538
538
  it 'should move the extra param onto its own line and realign' do
@@ -561,9 +561,9 @@ describe 'arrow_alignment' do
561
561
  end
562
562
 
563
563
  it 'should fix 2 problems' do
564
- expect(problems).to contain_fixed(msg).on_line(3).in_column(13)
565
- expect(problems).to contain_fixed(msg).on_line(3).in_column(29)
566
- expect(problems).to contain_fixed(msg).on_line(4).in_column(15)
564
+ expect(problems).to contain_fixed(sprintf(msg,17,13)).on_line(3).in_column(13)
565
+ expect(problems).to contain_fixed(sprintf(msg,17,29)).on_line(3).in_column(29)
566
+ expect(problems).to contain_fixed(sprintf(msg,17,15)).on_line(4).in_column(15)
567
567
  end
568
568
 
569
569
  it 'should move the extra param onto its own line and realign' do