puppet-lint 2.3.0 → 2.3.1

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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +74 -0
  3. data/.rubocop_todo.yml +89 -0
  4. data/.travis.yml +11 -9
  5. data/CHANGELOG.md +54 -0
  6. data/Gemfile +3 -0
  7. data/Rakefile +14 -3
  8. data/appveyor.yml +1 -4
  9. data/bin/puppet-lint +1 -1
  10. data/lib/puppet-lint.rb +25 -21
  11. data/lib/puppet-lint/bin.rb +15 -19
  12. data/lib/puppet-lint/checkplugin.rb +24 -17
  13. data/lib/puppet-lint/checks.rb +42 -31
  14. data/lib/puppet-lint/configuration.rb +11 -8
  15. data/lib/puppet-lint/data.rb +236 -164
  16. data/lib/puppet-lint/lexer.rb +225 -203
  17. data/lib/puppet-lint/lexer/token.rb +34 -18
  18. data/lib/puppet-lint/optparser.rb +33 -30
  19. data/lib/puppet-lint/plugins.rb +42 -38
  20. data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +26 -28
  21. data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +21 -20
  22. data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +8 -9
  23. data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +9 -8
  24. data/lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb +12 -11
  25. data/lib/puppet-lint/plugins/check_classes/names_containing_dash.rb +13 -12
  26. data/lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb +14 -13
  27. data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +9 -10
  28. data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +40 -31
  29. data/lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb +3 -2
  30. data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +21 -24
  31. data/lib/puppet-lint/plugins/check_comments/slash_comments.rb +3 -2
  32. data/lib/puppet-lint/plugins/check_comments/star_comments.rb +6 -5
  33. data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +21 -20
  34. data/lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb +10 -13
  35. data/lib/puppet-lint/plugins/check_documentation/documentation.rb +26 -17
  36. data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +11 -11
  37. data/lib/puppet-lint/plugins/check_resources/duplicate_params.rb +4 -3
  38. data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +17 -18
  39. data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +17 -16
  40. data/lib/puppet-lint/plugins/check_resources/file_mode.rb +22 -23
  41. data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +14 -13
  42. data/lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb +9 -8
  43. data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +8 -8
  44. data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +29 -42
  45. data/lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb +5 -4
  46. data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +3 -2
  47. data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +4 -3
  48. data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +3 -2
  49. data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +9 -8
  50. data/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +9 -8
  51. data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +9 -9
  52. data/lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb +4 -3
  53. data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +10 -10
  54. data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +23 -22
  55. data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +3 -2
  56. data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +3 -2
  57. data/lib/puppet-lint/tasks/puppet-lint.rb +3 -3
  58. data/lib/puppet-lint/version.rb +1 -1
  59. data/puppet-lint.gemspec +4 -4
  60. data/spec/puppet-lint/bin_spec.rb +268 -140
  61. data/spec/puppet-lint/checks_spec.rb +229 -0
  62. data/spec/puppet-lint/configuration_spec.rb +10 -9
  63. data/spec/puppet-lint/data_spec.rb +84 -0
  64. data/spec/puppet-lint/ignore_overrides_spec.rb +71 -40
  65. data/spec/puppet-lint/lexer/token_spec.rb +1 -1
  66. data/spec/puppet-lint/lexer_spec.rb +306 -73
  67. data/spec/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb +12 -6
  68. data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +10 -10
  69. data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +15 -11
  70. data/spec/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb +26 -21
  71. data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +3 -3
  72. data/spec/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb +4 -5
  73. data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +13 -0
  74. data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +33 -25
  75. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +80 -55
  76. data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +2 -2
  77. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +165 -130
  78. data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +2 -2
  79. data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +53 -35
  80. data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +59 -49
  81. data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +18 -14
  82. data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +14 -10
  83. data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +7 -7
  84. data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +54 -44
  85. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +114 -89
  86. data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +41 -30
  87. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +46 -40
  88. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +46 -40
  89. data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +95 -71
  90. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +28 -24
  91. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +11 -9
  92. data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +1 -2
  93. data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +18 -14
  94. data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +1 -1
  95. data/spec/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb +1 -1
  96. data/spec/puppet-lint/plugins/check_whitespace/140chars_spec.rb +22 -15
  97. data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +8 -6
  98. data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +23 -29
  99. data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +588 -494
  100. data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +1 -1
  101. data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +27 -19
  102. data/spec/puppet-lint_spec.rb +2 -12
  103. data/spec/spec_helper.rb +35 -30
  104. metadata +6 -5
  105. data/lib/puppet-lint/monkeypatches.rb +0 -2
  106. data/lib/puppet-lint/monkeypatches/string_percent.rb +0 -52
  107. data/lib/puppet-lint/monkeypatches/string_prepend.rb +0 -13
@@ -4,7 +4,7 @@ describe 'right_to_left_relationship' do
4
4
  let(:msg) { 'right-to-left (<-) relationship' }
5
5
 
6
6
  context 'chain 2 resources left to right' do
7
- let(:code) { "Class[foo] -> Class[bar]" }
7
+ let(:code) { 'Class[foo] -> Class[bar]' }
8
8
 
9
9
  it 'should not detect any problems' do
10
10
  expect(problems).to have(0).problems
@@ -12,7 +12,7 @@ describe 'right_to_left_relationship' do
12
12
  end
13
13
 
14
14
  context 'chain 2 resources right to left' do
15
- let(:code) { "Class[foo] <- Class[bar]" }
15
+ let(:code) { 'Class[foo] <- Class[bar]' }
16
16
 
17
17
  it 'should only detect a single problem' do
18
18
  expect(problems).to have(1).problem
@@ -4,27 +4,31 @@ describe 'variable_scope' do
4
4
  let(:msg) { 'top-scope variable being used without an explicit namespace' }
5
5
 
6
6
  context 'class with no variables declared accessing top scope' do
7
- let(:code) { "
8
- class foo {
9
- $bar = $baz
10
- }"
11
- }
7
+ let(:code) do
8
+ <<-END
9
+ class foo {
10
+ $bar = $baz
11
+ }
12
+ END
13
+ end
12
14
 
13
15
  it 'should only detect a single problem' do
14
16
  expect(problems).to have(1).problem
15
17
  end
16
18
 
17
19
  it 'should create a warning' do
18
- expect(problems).to contain_warning(msg).on_line(3).in_column(16)
20
+ expect(problems).to contain_warning(msg).on_line(2).in_column(18)
19
21
  end
20
22
  end
21
23
 
22
24
  context 'class with no variables declared accessing top scope explicitly' do
23
- let(:code) { "
24
- class foo {
25
- $bar = $::baz
26
- }"
27
- }
25
+ let(:code) do
26
+ <<-END
27
+ class foo {
28
+ $bar = $::baz
29
+ }
30
+ END
31
+ end
28
32
 
29
33
  it 'should not detect any problems' do
30
34
  expect(problems).to have(0).problems
@@ -32,12 +36,14 @@ describe 'variable_scope' do
32
36
  end
33
37
 
34
38
  context 'class with no variables declared accessing local array index' do
35
- let(:code) { "
36
- class foo {
37
- $bar = ['one', 'two', 'three']
38
- $baz = $bar[1]
39
- }"
40
- }
39
+ let(:code) do
40
+ <<-END
41
+ class foo {
42
+ $bar = ['one', 'two', 'three']
43
+ $baz = $bar[1]
44
+ }
45
+ END
46
+ end
41
47
 
42
48
  it 'should not detect any problems' do
43
49
  expect(problems).to have(0).problems
@@ -45,30 +51,33 @@ describe 'variable_scope' do
45
51
  end
46
52
 
47
53
  context 'class with no variables declared accessing local hash key' do
48
- let(:code) { "
49
- class foo {
50
- $bar = {
51
- 'one' => 1,
52
- 'two' => 2,
53
- 'three' => 3,
54
+ let(:code) do
55
+ <<-END
56
+ class foo {
57
+ $bar = {
58
+ 'one' => 1,
59
+ 'two' => 2,
60
+ 'three' => 3,
61
+ }
62
+ $baz = $bar['two']
54
63
  }
55
- $baz = $bar['two']
56
- }"
57
- }
64
+ END
65
+ end
58
66
 
59
67
  it 'should not detect any problems' do
60
68
  expect(problems).to have(0).problems
61
69
  end
62
70
  end
63
71
 
64
-
65
72
  context 'class with variables declared accessing local scope' do
66
- let(:code) { "
67
- class foo {
68
- $bar = 1
69
- $baz = $bar
70
- }"
71
- }
73
+ let(:code) do
74
+ <<-END
75
+ class foo {
76
+ $bar = 1
77
+ $baz = $bar
78
+ }
79
+ END
80
+ end
72
81
 
73
82
  it 'should not detect any problems' do
74
83
  expect(problems).to have(0).problems
@@ -76,11 +85,13 @@ describe 'variable_scope' do
76
85
  end
77
86
 
78
87
  context 'class with parameters accessing local scope' do
79
- let(:code) { "
80
- class foo($bar='UNSET') {
81
- $baz = $bar
82
- }"
83
- }
88
+ let(:code) do
89
+ <<-END
90
+ class foo($bar='UNSET') {
91
+ $baz = $bar
92
+ }
93
+ END
94
+ end
84
95
 
85
96
  it 'should not detect any problems' do
86
97
  expect(problems).to have(0).problems
@@ -88,27 +99,31 @@ describe 'variable_scope' do
88
99
  end
89
100
 
90
101
  context 'defined type with no variables declared accessing top scope' do
91
- let(:code) { "
92
- define foo() {
93
- $bar = $fqdn
94
- }"
95
- }
102
+ let(:code) do
103
+ <<-END
104
+ define foo() {
105
+ $bar = $fqdn
106
+ }
107
+ END
108
+ end
96
109
 
97
110
  it 'should only detect a single problem' do
98
111
  expect(problems).to have(1).problem
99
112
  end
100
113
 
101
114
  it 'should create a warning' do
102
- expect(problems).to contain_warning(msg).on_line(3).in_column(16)
115
+ expect(problems).to contain_warning(msg).on_line(2).in_column(18)
103
116
  end
104
117
  end
105
118
 
106
119
  context 'defined type with no variables declared accessing top scope explicitly' do
107
- let(:code) { "
108
- define foo() {
109
- $bar = $::fqdn
110
- }"
111
- }
120
+ let(:code) do
121
+ <<-END
122
+ define foo() {
123
+ $bar = $::fqdn
124
+ }
125
+ END
126
+ end
112
127
 
113
128
  it 'should not detect any problems' do
114
129
  expect(problems).to have(0).problems
@@ -116,14 +131,16 @@ describe 'variable_scope' do
116
131
  end
117
132
 
118
133
  context '$name should be auto defined' do
119
- let(:code) { "
120
- define foo() {
121
- $bar = $name
122
- $baz = $title
123
- $gronk = $module_name
124
- $meep = $1
125
- }"
126
- }
134
+ let(:code) do
135
+ <<-END
136
+ define foo() {
137
+ $bar = $name
138
+ $baz = $title
139
+ $gronk = $module_name
140
+ $meep = $1
141
+ }
142
+ END
143
+ end
127
144
 
128
145
  it 'should not detect any problems' do
129
146
  expect(problems).to have(0).problems
@@ -131,13 +148,15 @@ describe 'variable_scope' do
131
148
  end
132
149
 
133
150
  context 'define with required parameter' do
134
- let(:code) { "
135
- define tomcat::base (
136
- $max_perm_gen,
137
- $owner = hiera('app_user'),
138
- $system_properties = {},
139
- ) { }"
140
- }
151
+ let(:code) do
152
+ <<-END
153
+ define tomcat::base (
154
+ $max_perm_gen,
155
+ $owner = hiera('app_user'),
156
+ $system_properties = {},
157
+ ) { }
158
+ END
159
+ end
141
160
 
142
161
  it 'should not detect any problems' do
143
162
  expect(problems).to have(0).problems
@@ -145,68 +164,74 @@ describe 'variable_scope' do
145
164
  end
146
165
 
147
166
  context 'future parser blocks' do
148
- let(:code) { "
149
- class foo() {
150
- $foo = {1=>2, 3=>4}
151
- $foo.each |$a, $b| {
152
- $a # should cause no warnings
153
- $c # top-scope variable warning
154
- }
155
- $b # top-scope variable warning
156
- $foo.each |$d| {
157
- $d[1] # should cause no warnings
167
+ let(:code) do
168
+ <<-END
169
+ class foo() {
170
+ $foo = {1=>2, 3=>4}
171
+ $foo.each |$a, $b| {
172
+ $a # should cause no warnings
173
+ $c # top-scope variable warning
174
+ }
175
+ $b # top-scope variable warning
176
+ $foo.each |$d| {
177
+ $d[1] # should cause no warnings
178
+ }
158
179
  }
159
- }
160
- " }
180
+ END
181
+ end
161
182
 
162
183
  it 'should only detect two problems' do
163
184
  expect(problems).to have(2).problem
164
185
  end
165
186
 
166
187
  it 'should create two warnings' do
167
- expect(problems).to contain_warning(msg).on_line(8).in_column(9)
168
- expect(problems).to contain_warning(msg).on_line(6).in_column(11)
188
+ expect(problems).to contain_warning(msg).on_line(7).in_column(11)
189
+ expect(problems).to contain_warning(msg).on_line(5).in_column(13)
169
190
  end
170
191
  end
171
192
 
172
193
  context 'nested future parser blocks' do
173
- let(:code) { "
174
- class foo() {
175
- $foo = {1=>2, 3=>4}
176
- $bar = [1, 2, 3]
177
- $foo.each |$k ,$v| {
178
- $k
179
- $v
180
- $x # top-scope warning
181
- $bar.each |$x| {
194
+ let(:code) do
195
+ <<-END
196
+ class foo() {
197
+ $foo = {1=>2, 3=>4}
198
+ $bar = [1, 2, 3]
199
+ $foo.each |$k ,$v| {
182
200
  $k
183
201
  $v
184
- $x
185
- $p # top-scope warning
202
+ $x # top-scope warning
203
+ $bar.each |$x| {
204
+ $k
205
+ $v
206
+ $x
207
+ $p # top-scope warning
208
+ }
209
+ $x # top-scope warning
186
210
  }
187
- $x # top-scope warning
188
211
  }
189
- }
190
- " }
212
+ END
213
+ end
191
214
 
192
215
  it 'should only detect three problems' do
193
216
  expect(problems).to have(3).problem
194
217
  end
195
218
 
196
219
  it 'should create three warnings' do
197
- expect(problems).to contain_warning(msg).on_line(8).in_column(11)
198
- expect(problems).to contain_warning(msg).on_line(13).in_column(13)
199
- expect(problems).to contain_warning(msg).on_line(15).in_column(11)
220
+ expect(problems).to contain_warning(msg).on_line(7).in_column(13)
221
+ expect(problems).to contain_warning(msg).on_line(12).in_column(15)
222
+ expect(problems).to contain_warning(msg).on_line(14).in_column(13)
200
223
  end
201
224
  end
202
225
 
203
- %w{alias audit before loglevel noop notify require schedule stage subscribe tag}.each do |metaparam|
226
+ %w[alias audit before loglevel noop notify require schedule stage subscribe tag].each do |metaparam|
204
227
  context "referencing #{metaparam} metaparam value as a variable" do
205
- let(:code) { "
206
- class foo() {
207
- $#{metaparam}
208
- }
209
- " }
228
+ let(:code) do
229
+ <<-END
230
+ class foo() {
231
+ $#{metaparam}
232
+ }
233
+ END
234
+ end
210
235
 
211
236
  it 'should not detect any problems' do
212
237
  expect(problems).to have(0).problems
@@ -215,13 +240,15 @@ describe 'variable_scope' do
215
240
  end
216
241
 
217
242
  context 'support the use of facts and trusted facts for Puppet 3.5 onwards' do
218
- let(:code) { "
219
- class foo() {
220
- if $facts['osfamily'] == 'redhat' or $trusted['osfamily'] == 'redhat' {
221
- $redhat = true
243
+ let(:code) do
244
+ <<-END
245
+ class foo() {
246
+ if $facts['osfamily'] == 'redhat' or $trusted['osfamily'] == 'redhat' {
247
+ $redhat = true
248
+ }
222
249
  }
223
- }
224
- " }
250
+ END
251
+ end
225
252
 
226
253
  it 'should not detect any problems' do
227
254
  expect(problems).to have(0).problems
@@ -229,11 +256,13 @@ describe 'variable_scope' do
229
256
  end
230
257
 
231
258
  context 'multiple left hand variable assign' do
232
- let(:code) { "
233
- class test {
234
- [$foo, $bar] = something()
235
- }
236
- " }
259
+ let(:code) do
260
+ <<-END
261
+ class test {
262
+ [$foo, $bar] = something()
263
+ }
264
+ END
265
+ end
237
266
 
238
267
  it 'should not detect any problems' do
239
268
  expect(problems).to have(0).problems
@@ -241,11 +270,13 @@ describe 'variable_scope' do
241
270
  end
242
271
 
243
272
  context 'nested variable assignment' do
244
- let(:code) { "
245
- class test {
246
- [$foo, [[$bar, $baz], $qux]] = something()
247
- }
248
- " }
273
+ let(:code) do
274
+ <<-END
275
+ class test {
276
+ [$foo, [[$bar, $baz], $qux]] = something()
277
+ }
278
+ END
279
+ end
249
280
 
250
281
  it 'should not detect any problems' do
251
282
  expect(problems).to have(0).problems
@@ -253,12 +284,14 @@ describe 'variable_scope' do
253
284
  end
254
285
 
255
286
  context 'function calls inside string interpolation' do
256
- let(:code) { "
257
- class test {
258
- \"${split('1,2,3', ',')}\" # split is a function
259
- \"${lookup('foo::bar')}\" # lookup is a function
260
- }
261
- " }
287
+ let(:code) do
288
+ <<-END
289
+ class test {
290
+ "${split('1,2,3', ',')}" # split is a function
291
+ "${lookup('foo::bar')}" # lookup is a function
292
+ }
293
+ END
294
+ end
262
295
 
263
296
  it 'should not detect any problems' do
264
297
  expect(problems).to have(0).problems
@@ -266,19 +299,21 @@ describe 'variable_scope' do
266
299
  end
267
300
 
268
301
  context 'variables in string interpolation' do
269
- let(:code) { "
270
- class test {
271
- \"${foo.split(',')}\" # foo is a top-scope variable
272
- \"${::bar.split(',')}\"
273
- }
274
- " }
302
+ let(:code) do
303
+ <<-END
304
+ class test {
305
+ "${foo.split(',')}" # foo is a top-scope variable
306
+ "${::bar.split(',')}"
307
+ }
308
+ END
309
+ end
275
310
 
276
311
  it 'should only detect one problem' do
277
312
  expect(problems).to have(1).problems
278
313
  end
279
314
 
280
315
  it 'should create one warning' do
281
- expect(problems).to contain_warning(msg).on_line(3).in_column(11)
316
+ expect(problems).to contain_warning(msg).on_line(2).in_column(13)
282
317
  end
283
318
  end
284
319
  end