puppet-lint 0.3.2 → 0.4.0.pre1

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.
Files changed (36) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +0 -1
  3. data/README.md +3 -1
  4. data/Rakefile +0 -19
  5. data/lib/puppet-lint.rb +65 -74
  6. data/lib/puppet-lint/bin.rb +21 -0
  7. data/lib/puppet-lint/checkplugin.rb +22 -0
  8. data/lib/puppet-lint/{plugin.rb → checks.rb} +66 -31
  9. data/lib/puppet-lint/configuration.rb +105 -0
  10. data/lib/puppet-lint/lexer.rb +94 -31
  11. data/lib/puppet-lint/lexer/token.rb +38 -2
  12. data/lib/puppet-lint/monkeypatches.rb +2 -0
  13. data/lib/puppet-lint/monkeypatches/string_percent.rb +52 -0
  14. data/lib/puppet-lint/monkeypatches/string_prepend.rb +7 -0
  15. data/lib/puppet-lint/plugins.rb +42 -0
  16. data/lib/puppet-lint/plugins/check_comments.rb +8 -1
  17. data/lib/puppet-lint/plugins/check_resources.rb +25 -3
  18. data/lib/puppet-lint/plugins/check_strings.rb +53 -6
  19. data/lib/puppet-lint/plugins/check_whitespace.rb +69 -26
  20. data/lib/puppet-lint/version.rb +1 -1
  21. data/puppet-lint.gemspec +0 -1
  22. data/spec/puppet-lint/configuration_spec.rb +1 -0
  23. data/spec/puppet-lint/lexer_spec.rb +2 -2
  24. data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +22 -0
  25. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +119 -6
  26. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +30 -3
  27. data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +103 -3
  28. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +39 -0
  29. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +23 -0
  30. data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +88 -0
  31. data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +44 -0
  32. data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +171 -6
  33. data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +22 -0
  34. data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +44 -0
  35. data/spec/puppet-lint_spec.rb +1 -1
  36. metadata +10 -22
@@ -4,8 +4,35 @@ describe 'unquoted_file_mode' do
4
4
  describe '4 digit unquoted file mode' do
5
5
  let(:code) { "file { 'foo': mode => 0777 }" }
6
6
 
7
- its(:problems) {
8
- should only_have_problem :kind => :warning, :message => "unquoted file mode"
9
- }
7
+ its(:problems) do
8
+ should only_have_problem(
9
+ :kind => :warning,
10
+ :message => "unquoted file mode",
11
+ :linenumber => 1,
12
+ :column => 23,
13
+ )
14
+ end
15
+ end
16
+
17
+ describe '4 digit unquoted file mode w/fix' do
18
+ before do
19
+ PuppetLint.configuration.fix = true
20
+ end
21
+
22
+ after do
23
+ PuppetLint.configuration.fix = false
24
+ end
25
+
26
+ let(:code) { "file { 'foo': mode => 0777 }" }
27
+
28
+ its(:problems) do
29
+ should only_have_problem(
30
+ :kind => :fixed,
31
+ :message => "unquoted file mode",
32
+ :linenumber => 1,
33
+ :column => 23,
34
+ )
35
+ end
36
+ its(:manifest) { should == "file { 'foo': mode => '0777' }" }
10
37
  end
11
38
  end
@@ -11,10 +11,38 @@ describe 'unquoted_resource_title' do
11
11
  let(:code) { "file { foo: }" }
12
12
 
13
13
  its(:problems) {
14
- should only_have_problem :kind => :warning, :message => "unquoted resource title", :linenumber => 1
14
+ should only_have_problem(
15
+ :kind => :warning,
16
+ :message => "unquoted resource title",
17
+ :linenumber => 1,
18
+ :column => 8,
19
+ )
15
20
  }
16
21
  end
17
22
 
23
+ describe 'unquoted resource title on single line resource w/fix' do
24
+ before do
25
+ PuppetLint.configuration.fix = true
26
+ end
27
+
28
+ after do
29
+ PuppetLint.configuration.fix = false
30
+ end
31
+
32
+ let(:code) { "file { foo: }" }
33
+
34
+ its(:problems) {
35
+ should only_have_problem(
36
+ :kind => :fixed,
37
+ :message => "unquoted resource title",
38
+ :linenumber => 1,
39
+ :column => 8,
40
+ )
41
+ }
42
+
43
+ its(:manifest) { should == "file { 'foo': }" }
44
+ end
45
+
18
46
  describe 'quoted resource title on multi line resource' do
19
47
  let(:code) { "
20
48
  file { 'foo':
@@ -31,7 +59,41 @@ describe 'unquoted_resource_title' do
31
59
  }
32
60
 
33
61
  its(:problems) {
34
- should only_have_problem :kind => :warning, :message => "unquoted resource title", :linenumber => 2
62
+ should only_have_problem(
63
+ :kind => :warning,
64
+ :message => "unquoted resource title",
65
+ :linenumber => 2,
66
+ :column => 14,
67
+ )
68
+ }
69
+ end
70
+
71
+ describe 'unquoted resource title on multi line resource w/fix' do
72
+ before do
73
+ PuppetLint.configuration.fix = true
74
+ end
75
+
76
+ after do
77
+ PuppetLint.configuration.fix = false
78
+ end
79
+
80
+ let(:code) { "
81
+ file { foo:
82
+ }"
83
+ }
84
+
85
+ its(:problems) {
86
+ should only_have_problem(
87
+ :kind => :fixed,
88
+ :message => "unquoted resource title",
89
+ :linenumber => 2,
90
+ :column => 14,
91
+ )
92
+ }
93
+
94
+ its(:manifest) { should == "
95
+ file { 'foo':
96
+ }"
35
97
  }
36
98
  end
37
99
 
@@ -55,7 +117,45 @@ describe 'unquoted_resource_title' do
55
117
  }
56
118
 
57
119
  its(:problems) {
58
- should only_have_problem :kind => :warning, :message => "unquoted resource title", :linenumber => 4
120
+ should only_have_problem(
121
+ :kind => :warning,
122
+ :message => "unquoted resource title",
123
+ :linenumber => 4,
124
+ :column => 9,
125
+ )
126
+ }
127
+ end
128
+
129
+ describe 'condensed resources with an unquoted title w/fix' do
130
+ before do
131
+ PuppetLint.configuration.fix = true
132
+ end
133
+
134
+ after do
135
+ PuppetLint.configuration.fix = false
136
+ end
137
+
138
+ let(:code) { "
139
+ file {
140
+ 'foo': ;
141
+ bar: ;
142
+ }"
143
+ }
144
+
145
+ its(:problems) {
146
+ should only_have_problem(
147
+ :kind => :fixed,
148
+ :message => "unquoted resource title",
149
+ :linenumber => 4,
150
+ :column => 9,
151
+ )
152
+ }
153
+
154
+ its(:manifest) { should == "
155
+ file {
156
+ 'foo': ;
157
+ 'bar': ;
158
+ }"
59
159
  }
60
160
  end
61
161
 
@@ -7,6 +7,23 @@ describe 'double_quoted_strings' do
7
7
  its(:problems) { should be_empty }
8
8
  end
9
9
 
10
+ describe 'double quoted string containing a variable inside single quotes w/fix' do
11
+ before do
12
+ PuppetLint.configuration.fix = true
13
+ end
14
+
15
+ after do
16
+ PuppetLint.configuration.fix = false
17
+ end
18
+
19
+ let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" }
20
+
21
+ its(:problems) { should be_empty }
22
+ its(:manifest) {
23
+ should == "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }"
24
+ }
25
+ end
26
+
10
27
  describe 'multiple strings in a line' do
11
28
  let(:code) { "\"aoeu\" '${foo}'" }
12
29
 
@@ -20,6 +37,28 @@ describe 'double_quoted_strings' do
20
37
  }
21
38
  end
22
39
 
40
+ describe 'multiple strings in a line w/fix' do
41
+ before do
42
+ PuppetLint.configuration.fix = true
43
+ end
44
+
45
+ after do
46
+ PuppetLint.configuration.fix = false
47
+ end
48
+
49
+ let(:code) { "\"aoeu\" '${foo}'" }
50
+
51
+ its(:problems) {
52
+ should have_problem({
53
+ :kind => :fixed,
54
+ :message => 'double quoted string containing no variables',
55
+ :linenumber => 1,
56
+ :column => 1,
57
+ })
58
+ }
59
+ its(:manifest) { should == "'aoeu' '${foo}'" }
60
+ end
61
+
23
62
  describe 'double quoted string nested in a single quoted string' do
24
63
  let(:code) { "'grep \"status=sent\" /var/log/mail.log'" }
25
64
 
@@ -13,4 +13,27 @@ describe 'only_variable_string' do
13
13
  })
14
14
  }
15
15
  end
16
+
17
+ describe 'string containing only a variable w/fix' do
18
+ before do
19
+ PuppetLint.configuration.fix = true
20
+ end
21
+
22
+ after do
23
+ PuppetLint.configuration.fix = false
24
+ end
25
+
26
+ let(:code) { '"${foo}"' }
27
+
28
+ its(:problems) {
29
+ should only_have_problem({
30
+ :kind => :fixed,
31
+ :message => 'string containing only a variable',
32
+ :linenumber => 1,
33
+ :column => 3,
34
+ })
35
+ }
36
+
37
+ its(:manifest) { should == "$foo" }
38
+ end
16
39
  end
@@ -52,4 +52,92 @@ describe 'quoted_booleans' do
52
52
  })
53
53
  }
54
54
  end
55
+
56
+ describe 'quoted false w/fix' do
57
+ before do
58
+ PuppetLint.configuration.fix = true
59
+ end
60
+
61
+ after do
62
+ PuppetLint.configuration.fix = false
63
+ end
64
+
65
+ let(:code) { "class { 'foo': boolFlag => 'false' }" }
66
+
67
+ its(:problems) {
68
+ should only_have_problem({
69
+ :kind => :fixed,
70
+ :message => 'quoted boolean value found',
71
+ :linenumber => 1,
72
+ :column => 28,
73
+ })
74
+ }
75
+ its(:manifest) { should == "class { 'foo': boolFlag => false }" }
76
+ end
77
+
78
+ describe 'quoted true w/fix' do
79
+ before do
80
+ PuppetLint.configuration.fix = true
81
+ end
82
+
83
+ after do
84
+ PuppetLint.configuration.fix = false
85
+ end
86
+
87
+ let(:code) { "class { 'foo': boolFlag => 'true' }" }
88
+
89
+ its(:problems) {
90
+ should only_have_problem({
91
+ :kind => :fixed,
92
+ :message => 'quoted boolean value found',
93
+ :linenumber => 1,
94
+ :column => 28,
95
+ })
96
+ }
97
+ its(:manifest) { should == "class { 'foo': boolFlag => true }" }
98
+ end
99
+
100
+ describe 'double quoted true w/fix' do
101
+ before do
102
+ PuppetLint.configuration.fix = true
103
+ end
104
+
105
+ after do
106
+ PuppetLint.configuration.fix = false
107
+ end
108
+
109
+ let(:code) { "class { 'foo': boolFlag => \"true\" }" }
110
+
111
+ its(:problems) {
112
+ should have_problem({
113
+ :kind => :fixed,
114
+ :message => 'quoted boolean value found',
115
+ :linenumber => 1,
116
+ :column => 28,
117
+ })
118
+ }
119
+ its(:manifest) { should == "class { 'foo': boolFlag => true }" }
120
+ end
121
+
122
+ describe 'double quoted false w/fix' do
123
+ before do
124
+ PuppetLint.configuration.fix = true
125
+ end
126
+
127
+ after do
128
+ PuppetLint.configuration.fix = false
129
+ end
130
+
131
+ let(:code) { "class { 'foo': boolFlag => \"false\" }" }
132
+
133
+ its(:problems) {
134
+ should have_problem({
135
+ :kind => :fixed,
136
+ :message => 'quoted boolean value found',
137
+ :linenumber => 1,
138
+ :column => 28,
139
+ })
140
+ }
141
+ its(:manifest) { should == "class { 'foo': boolFlag => false }" }
142
+ end
55
143
  end
@@ -14,6 +14,28 @@ describe 'variables_not_enclosed' do
14
14
  }
15
15
  end
16
16
 
17
+ describe 'variable not enclosed in {} w/fix' do
18
+ before do
19
+ PuppetLint.configuration.fix = true
20
+ end
21
+
22
+ after do
23
+ PuppetLint.configuration.fix = false
24
+ end
25
+
26
+ let(:code) { '" $gronk"' }
27
+
28
+ its(:problems) {
29
+ should only_have_problem({
30
+ :kind => :fixed,
31
+ :message => 'variable not enclosed in {}',
32
+ :linenumber => 1,
33
+ :column => 3,
34
+ })
35
+ }
36
+ its(:manifest) { should == '" ${gronk}"' }
37
+ end
38
+
17
39
  describe 'variable not enclosed in {} after many tokens' do
18
40
  let(:code) { ("'groovy'\n" * 20) + '" $gronk"' }
19
41
 
@@ -26,4 +48,26 @@ describe 'variables_not_enclosed' do
26
48
  })
27
49
  }
28
50
  end
51
+
52
+ describe 'variable not enclosed in {} after many tokens w/fix' do
53
+ before do
54
+ PuppetLint.configuration.fix = true
55
+ end
56
+
57
+ after do
58
+ PuppetLint.configuration.fix = false
59
+ end
60
+
61
+ let(:code) { ("'groovy'\n" * 20) + '" $gronk"' }
62
+
63
+ its(:problems) {
64
+ should only_have_problem({
65
+ :kind => :fixed,
66
+ :message => 'variable not enclosed in {}',
67
+ :linenumber => 21,
68
+ :column => 3,
69
+ })
70
+ }
71
+ its(:manifest) { should == ("'groovy'\n" * 20) + '" ${gronk}"' }
72
+ end
29
73
  end
@@ -105,16 +105,85 @@ describe 'arrow_alignment' do
105
105
  should have_problem({
106
106
  :kind => :warning,
107
107
  :message => 'indentation of => is not properly aligned',
108
- :linenumber => 5,
109
- :column => 15,
108
+ :linenumber => 3,
109
+ :column => 13,
110
+ })
111
+ should have_problem({
112
+ :kind => :warning,
113
+ :message => 'indentation of => is not properly aligned',
114
+ :linenumber => 4,
115
+ :column => 13,
116
+ })
117
+ should have_problem({
118
+ :kind => :warning,
119
+ :message => 'indentation of => is not properly aligned',
120
+ :linenumber => 6,
121
+ :column => 14,
110
122
  })
111
123
  should have_problem({
112
124
  :kind => :warning,
113
125
  :message => 'indentation of => is not properly aligned',
126
+ :linenumber => 7,
127
+ :column => 13,
128
+ })
129
+ end
130
+ end
131
+
132
+ describe 'single resource with a misaligned => w/fix' do
133
+ before do
134
+ PuppetLint.configuration.fix = true
135
+ end
136
+
137
+ after do
138
+ PuppetLint.configuration.fix = false
139
+ end
140
+
141
+ let(:code) { "
142
+ file { '/tmp/foo':
143
+ foo => 1,
144
+ bar => 2,
145
+ gronk => 3,
146
+ baz => 4,
147
+ meh => 5,
148
+ }"
149
+ }
150
+
151
+ its(:problems) do
152
+ should have_problem({
153
+ :kind => :fixed,
154
+ :message => 'indentation of => is not properly aligned',
155
+ :linenumber => 3,
156
+ :column => 13,
157
+ })
158
+ should have_problem({
159
+ :kind => :fixed,
160
+ :message => 'indentation of => is not properly aligned',
161
+ :linenumber => 4,
162
+ :column => 13,
163
+ })
164
+ should have_problem({
165
+ :kind => :fixed,
166
+ :message => 'indentation of => is not properly aligned',
114
167
  :linenumber => 6,
115
168
  :column => 14,
116
169
  })
170
+ should have_problem({
171
+ :kind => :fixed,
172
+ :message => 'indentation of => is not properly aligned',
173
+ :linenumber => 7,
174
+ :column => 13,
175
+ })
117
176
  end
177
+
178
+ its(:manifest) { should == "
179
+ file { '/tmp/foo':
180
+ foo => 1,
181
+ bar => 2,
182
+ gronk => 3,
183
+ baz => 4,
184
+ meh => 5,
185
+ }"
186
+ }
118
187
  end
119
188
 
120
189
  describe 'complex resource with a misaligned =>' do
@@ -134,8 +203,8 @@ describe 'arrow_alignment' do
134
203
  should have_problem({
135
204
  :kind => :warning,
136
205
  :message => 'indentation of => is not properly aligned',
137
- :linenumber => 4,
138
- :column => 14,
206
+ :linenumber => 3,
207
+ :column => 13,
139
208
  })
140
209
  should have_problem({
141
210
  :kind => :warning,
@@ -146,10 +215,65 @@ describe 'arrow_alignment' do
146
215
  should have_problem({
147
216
  :kind => :warning,
148
217
  :message => 'indentation of => is not properly aligned',
149
- :linenumber => 8,
150
- :column => 14,
218
+ :linenumber => 9,
219
+ :column => 13,
220
+ })
221
+ end
222
+ end
223
+
224
+ describe 'complex resource with a misaligned => w/fix' do
225
+ before do
226
+ PuppetLint.configuration.fix = true
227
+ end
228
+
229
+ after do
230
+ PuppetLint.configuration.fix = false
231
+ end
232
+
233
+ let(:code) { "
234
+ file { '/tmp/foo':
235
+ foo => 1,
236
+ bar => $baz ? {
237
+ gronk => 2,
238
+ meh => 3,
239
+ },
240
+ meep => 4,
241
+ bah => 5,
242
+ }"
243
+ }
244
+
245
+ its(:problems) do
246
+ should have_problem({
247
+ :kind => :fixed,
248
+ :message => 'indentation of => is not properly aligned',
249
+ :linenumber => 3,
250
+ :column => 13,
251
+ })
252
+ should have_problem({
253
+ :kind => :fixed,
254
+ :message => 'indentation of => is not properly aligned',
255
+ :linenumber => 6,
256
+ :column => 15,
257
+ })
258
+ should have_problem({
259
+ :kind => :fixed,
260
+ :message => 'indentation of => is not properly aligned',
261
+ :linenumber => 9,
262
+ :column => 13,
151
263
  })
152
264
  end
265
+
266
+ its(:manifest) { should == "
267
+ file { '/tmp/foo':
268
+ foo => 1,
269
+ bar => $baz ? {
270
+ gronk => 2,
271
+ meh => 3,
272
+ },
273
+ meep => 4,
274
+ bah => 5,
275
+ }"
276
+ }
153
277
  end
154
278
 
155
279
  describe 'multi-resource with a misaligned =>' do
@@ -174,6 +298,47 @@ describe 'arrow_alignment' do
174
298
  end
175
299
  end
176
300
 
301
+ describe 'multi-resource with a misaligned => w/fix' do
302
+ before do
303
+ PuppetLint.configuration.fix = true
304
+ end
305
+
306
+ after do
307
+ PuppetLint.configuration.fix = false
308
+ end
309
+
310
+ let(:code) { "
311
+ file {
312
+ '/tmp/foo': ;
313
+ '/tmp/bar':
314
+ foo => 'bar';
315
+ '/tmp/baz':
316
+ gronk => 'bah',
317
+ meh => 'no'
318
+ }"
319
+ }
320
+
321
+ its(:problems) do
322
+ should only_have_problem({
323
+ :kind => :fixed,
324
+ :message => 'indentation of => is not properly aligned',
325
+ :linenumber => 8,
326
+ :column => 15,
327
+ })
328
+ end
329
+
330
+ its(:manifest) { should == "
331
+ file {
332
+ '/tmp/foo': ;
333
+ '/tmp/bar':
334
+ foo => 'bar';
335
+ '/tmp/baz':
336
+ gronk => 'bah',
337
+ meh => 'no'
338
+ }"
339
+ }
340
+ end
341
+
177
342
  describe 'multiple single line resources' do
178
343
  let(:code) { "
179
344
  file { 'foo': ensure => file }