puppet-lint-manifest_whitespace-check 0.0.1 → 0.1.6
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.
- checksums.yaml +5 -5
- data/README.md +25 -3
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_inherits_single_space.rb +28 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb +10 -10
- data/lib/puppet-lint/plugins/check_manifest_whitespace_closing_brace.rb +96 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_closing_bracket.rb +86 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_empty_lines.rb +35 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_opening_brace.rb +83 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_opening_bracket.rb +79 -0
- data/lib/puppet-lint/plugins/tools.rb +16 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_class_header_spec.rb +35 -158
- data/spec/puppet-lint/plugins/manifest_whitespace_class_inherits_spec.rb +69 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_closing_brace_spec.rb +460 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_closing_bracket_spec.rb +277 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_double_newline_spec.rb +60 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_opening_brace_spec.rb +792 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_opening_bracket_spec.rb +470 -0
- metadata +54 -37
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_opening_curly_brace.rb +0 -40
@@ -0,0 +1,277 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'manifest_whitespace_closing_bracket_before' do
|
6
|
+
let(:closing_bracket_msg) { 'there should be no whitespace or a single newline before a closing bracket' }
|
7
|
+
|
8
|
+
context 'with no spaces' do
|
9
|
+
let(:code) do
|
10
|
+
<<~EOF
|
11
|
+
# example
|
12
|
+
#
|
13
|
+
# Main class, includes all other classes.
|
14
|
+
#
|
15
|
+
|
16
|
+
class example (
|
17
|
+
String $content,
|
18
|
+
) {
|
19
|
+
$value = [{ 'key' => 'value' }]
|
20
|
+
$value2 = [
|
21
|
+
{
|
22
|
+
'key' => 'value1',
|
23
|
+
},
|
24
|
+
{
|
25
|
+
'key' => 'value2',
|
26
|
+
},
|
27
|
+
]
|
28
|
+
$value3 = myfunc($value1)
|
29
|
+
$value4 = ['somekey']
|
30
|
+
$value5 = []
|
31
|
+
$value6 = {}
|
32
|
+
$value7 = "x${server_facts['environment']}y"
|
33
|
+
|
34
|
+
if somecondition {
|
35
|
+
class { 'example2':
|
36
|
+
param1 => 'value1',
|
37
|
+
require => File['somefile'],
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
EOF
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with fix disabled' do
|
45
|
+
it 'should detect 0 problems' do
|
46
|
+
expect(problems).to have(0).problem
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with too many spaces' do
|
52
|
+
let(:code) do
|
53
|
+
<<~EOF
|
54
|
+
# example
|
55
|
+
#
|
56
|
+
# Main class, includes all other classes.
|
57
|
+
#
|
58
|
+
|
59
|
+
class example (
|
60
|
+
String $content,
|
61
|
+
) {
|
62
|
+
$value = [{ 'key' => 'value' } ]
|
63
|
+
$value2 = [
|
64
|
+
{
|
65
|
+
'key' => 'value1',
|
66
|
+
},
|
67
|
+
{
|
68
|
+
'key' => 'value2',
|
69
|
+
},
|
70
|
+
|
71
|
+
]
|
72
|
+
$value3 = myfunc($value1)
|
73
|
+
$value4 = ['somekey' ]
|
74
|
+
$value5 = [ ]
|
75
|
+
$value6 = {}
|
76
|
+
$value7 = "x${server_facts['environment']}y"
|
77
|
+
|
78
|
+
if somecondition {
|
79
|
+
class { 'example2':
|
80
|
+
param1 => 'value1',
|
81
|
+
require => File['somefile' ],
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
EOF
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'with fix disabled' do
|
89
|
+
it 'should detect 5 problems' do
|
90
|
+
expect(problems).to have(5).problems
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should create a error' do
|
94
|
+
expect(problems).to contain_error(closing_bracket_msg).on_line(9).in_column(33)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'with fix enabled' do
|
99
|
+
before do
|
100
|
+
PuppetLint.configuration.fix = true
|
101
|
+
end
|
102
|
+
|
103
|
+
after do
|
104
|
+
PuppetLint.configuration.fix = false
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should detect 5 problems' do
|
108
|
+
expect(problems).to have(5).problems
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should fix a error' do
|
112
|
+
expect(problems).to contain_fixed(closing_bracket_msg)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should add spaces' do
|
116
|
+
expect(manifest).to eq(
|
117
|
+
<<~EOF,
|
118
|
+
# example
|
119
|
+
#
|
120
|
+
# Main class, includes all other classes.
|
121
|
+
#
|
122
|
+
|
123
|
+
class example (
|
124
|
+
String $content,
|
125
|
+
) {
|
126
|
+
$value = [{ 'key' => 'value' }]
|
127
|
+
$value2 = [
|
128
|
+
{
|
129
|
+
'key' => 'value1',
|
130
|
+
},
|
131
|
+
{
|
132
|
+
'key' => 'value2',
|
133
|
+
},
|
134
|
+
]
|
135
|
+
$value3 = myfunc($value1)
|
136
|
+
$value4 = ['somekey']
|
137
|
+
$value5 = []
|
138
|
+
$value6 = {}
|
139
|
+
$value7 = "x${server_facts['environment']}y"
|
140
|
+
|
141
|
+
if somecondition {
|
142
|
+
class { 'example2':
|
143
|
+
param1 => 'value1',
|
144
|
+
require => File['somefile'],
|
145
|
+
}
|
146
|
+
}
|
147
|
+
}
|
148
|
+
EOF
|
149
|
+
)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe 'manifest_whitespace_closing_bracket_after' do
|
156
|
+
let(:closing_bracket_msg) { 'there should be either a bracket, comma, colon, closing quote or a newline after a closing bracket, or whitespace and none of the aforementioned' }
|
157
|
+
|
158
|
+
context 'with spaces' do
|
159
|
+
let(:code) do
|
160
|
+
<<~EOF
|
161
|
+
# example
|
162
|
+
#
|
163
|
+
# Main class, includes all other classes.
|
164
|
+
#
|
165
|
+
|
166
|
+
class example (
|
167
|
+
String $content,
|
168
|
+
) {
|
169
|
+
$value = { 'key' => ['value'] }
|
170
|
+
$value2 = [
|
171
|
+
{
|
172
|
+
'key' => 'value1',
|
173
|
+
},
|
174
|
+
{
|
175
|
+
'key' => 'value2',
|
176
|
+
} ,
|
177
|
+
]
|
178
|
+
|
179
|
+
$value2bis = [
|
180
|
+
'value',
|
181
|
+
] # this comment is fine
|
182
|
+
|
183
|
+
$value3 = myfunc([] )
|
184
|
+
$value4 = ['somekey']
|
185
|
+
$value5 = []
|
186
|
+
$value6 = {}
|
187
|
+
$value7 = "x${server_facts['environment']}y"
|
188
|
+
|
189
|
+
if somecondition {
|
190
|
+
class { 'example2':
|
191
|
+
param1 => 'value1',
|
192
|
+
require => File['somefile'] ,
|
193
|
+
}
|
194
|
+
class { 'example3': }
|
195
|
+
}
|
196
|
+
if someothercondition { include ::otherclass }
|
197
|
+
|
198
|
+
package { ['package1', 'package2']:
|
199
|
+
ensure => installed,
|
200
|
+
}
|
201
|
+
}
|
202
|
+
EOF
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'with fix disabled' do
|
206
|
+
it 'should detect 3 problems' do
|
207
|
+
expect(problems).to have(3).problem
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'should create a error' do
|
211
|
+
expect(problems).to contain_error(closing_bracket_msg).on_line(9).in_column(32)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context 'with fix enabled' do
|
216
|
+
before do
|
217
|
+
PuppetLint.configuration.fix = true
|
218
|
+
end
|
219
|
+
|
220
|
+
after do
|
221
|
+
PuppetLint.configuration.fix = false
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'should fix a error' do
|
225
|
+
expect(problems).to contain_fixed(closing_bracket_msg)
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'should add spaces' do
|
229
|
+
expect(manifest).to eq(
|
230
|
+
<<~EOF,
|
231
|
+
# example
|
232
|
+
#
|
233
|
+
# Main class, includes all other classes.
|
234
|
+
#
|
235
|
+
|
236
|
+
class example (
|
237
|
+
String $content,
|
238
|
+
) {
|
239
|
+
$value = { 'key' => ['value']}
|
240
|
+
$value2 = [
|
241
|
+
{
|
242
|
+
'key' => 'value1',
|
243
|
+
},
|
244
|
+
{
|
245
|
+
'key' => 'value2',
|
246
|
+
} ,
|
247
|
+
]
|
248
|
+
|
249
|
+
$value2bis = [
|
250
|
+
'value',
|
251
|
+
] # this comment is fine
|
252
|
+
|
253
|
+
$value3 = myfunc([])
|
254
|
+
$value4 = ['somekey']
|
255
|
+
$value5 = []
|
256
|
+
$value6 = {}
|
257
|
+
$value7 = "x${server_facts['environment']}y"
|
258
|
+
|
259
|
+
if somecondition {
|
260
|
+
class { 'example2':
|
261
|
+
param1 => 'value1',
|
262
|
+
require => File['somefile'],
|
263
|
+
}
|
264
|
+
class { 'example3': }
|
265
|
+
}
|
266
|
+
if someothercondition { include ::otherclass }
|
267
|
+
|
268
|
+
package { ['package1', 'package2']:
|
269
|
+
ensure => installed,
|
270
|
+
}
|
271
|
+
}
|
272
|
+
EOF
|
273
|
+
)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'manifest_whitespace_two_empty_lines' do
|
6
|
+
let(:single_space_msg) { 'there should be no two consecutive empty lines' }
|
7
|
+
|
8
|
+
context 'with two spaces' do
|
9
|
+
let(:code) do
|
10
|
+
<<~EOF
|
11
|
+
class { 'example2':
|
12
|
+
param1 => 'value1',
|
13
|
+
|
14
|
+
|
15
|
+
param2 => 'value2',
|
16
|
+
}
|
17
|
+
EOF
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with fix disabled' do
|
21
|
+
it 'should detect a single problem' do
|
22
|
+
expect(problems).to have(1).problem
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should create a error' do
|
26
|
+
expect(problems).to contain_error(single_space_msg).on_line(4).in_column(1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with fix enabled' do
|
31
|
+
before do
|
32
|
+
PuppetLint.configuration.fix = true
|
33
|
+
end
|
34
|
+
|
35
|
+
after do
|
36
|
+
PuppetLint.configuration.fix = false
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should detect a single problem' do
|
40
|
+
expect(problems).to have(1).problem
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should fix the manifest' do
|
44
|
+
expect(problems).to contain_fixed(single_space_msg)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should fix the space' do
|
48
|
+
expect(manifest).to eq(
|
49
|
+
<<~EOF,
|
50
|
+
class { 'example2':
|
51
|
+
param1 => 'value1',
|
52
|
+
|
53
|
+
param2 => 'value2',
|
54
|
+
}
|
55
|
+
EOF
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,792 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'manifest_whitespace_opening_brace_before' do
|
6
|
+
let(:opening_brace_msg) { 'there should be a single space before an opening brace' }
|
7
|
+
|
8
|
+
context 'with comment only' do
|
9
|
+
let(:code) do
|
10
|
+
<<~EOF
|
11
|
+
$value7 = {
|
12
|
+
# nothing
|
13
|
+
}
|
14
|
+
EOF
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should detect no problems' do
|
18
|
+
expect(problems).to have(0).problem
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with no spaces' do
|
23
|
+
let(:code) do
|
24
|
+
<<~EOF
|
25
|
+
# example
|
26
|
+
#
|
27
|
+
# Main class, includes all other classes.
|
28
|
+
#
|
29
|
+
|
30
|
+
class example (
|
31
|
+
String $content,
|
32
|
+
){
|
33
|
+
$value = [{ 'key' => 'value' }]
|
34
|
+
$value2 = [
|
35
|
+
{
|
36
|
+
'key' => 'value1',
|
37
|
+
},
|
38
|
+
{
|
39
|
+
'key' => 'value2',
|
40
|
+
},
|
41
|
+
]
|
42
|
+
$value3 = myfunc($value1)
|
43
|
+
$value4 = ['somekey']
|
44
|
+
$value5 = []
|
45
|
+
$value6 = {}
|
46
|
+
$value7 = {
|
47
|
+
# nothing
|
48
|
+
}
|
49
|
+
|
50
|
+
if somecondition{
|
51
|
+
class{ 'example2':
|
52
|
+
param1 => 'value1',
|
53
|
+
require => File['somefile'],
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
EOF
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with fix disabled' do
|
61
|
+
it 'should detect three problems' do
|
62
|
+
expect(problems).to have(3).problem
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should create a error' do
|
66
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(8).in_column(2)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'with fix enabled' do
|
71
|
+
before do
|
72
|
+
PuppetLint.configuration.fix = true
|
73
|
+
end
|
74
|
+
|
75
|
+
after do
|
76
|
+
PuppetLint.configuration.fix = false
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should detect three problems' do
|
80
|
+
expect(problems).to have(3).problem
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should create a error' do
|
84
|
+
expect(problems).to contain_fixed(opening_brace_msg)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should add spaces' do
|
88
|
+
expect(manifest).to eq(
|
89
|
+
<<~EOF,
|
90
|
+
# example
|
91
|
+
#
|
92
|
+
# Main class, includes all other classes.
|
93
|
+
#
|
94
|
+
|
95
|
+
class example (
|
96
|
+
String $content,
|
97
|
+
) {
|
98
|
+
$value = [{ 'key' => 'value' }]
|
99
|
+
$value2 = [
|
100
|
+
{
|
101
|
+
'key' => 'value1',
|
102
|
+
},
|
103
|
+
{
|
104
|
+
'key' => 'value2',
|
105
|
+
},
|
106
|
+
]
|
107
|
+
$value3 = myfunc($value1)
|
108
|
+
$value4 = ['somekey']
|
109
|
+
$value5 = []
|
110
|
+
$value6 = {}
|
111
|
+
$value7 = {
|
112
|
+
# nothing
|
113
|
+
}
|
114
|
+
|
115
|
+
if somecondition {
|
116
|
+
class { 'example2':
|
117
|
+
param1 => 'value1',
|
118
|
+
require => File['somefile'],
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
EOF
|
123
|
+
)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'with two spaces' do
|
129
|
+
let(:code) do
|
130
|
+
<<~EOF
|
131
|
+
# example
|
132
|
+
#
|
133
|
+
# Main class, includes all other classes.
|
134
|
+
#
|
135
|
+
|
136
|
+
class example (
|
137
|
+
String $content,
|
138
|
+
) {
|
139
|
+
$value = [{ 'key' => 'value' }]
|
140
|
+
$value2 = [
|
141
|
+
{
|
142
|
+
'key' => 'value1',
|
143
|
+
},
|
144
|
+
{
|
145
|
+
'key' => 'value2',
|
146
|
+
},
|
147
|
+
]
|
148
|
+
$value3 = myfunc($value1)
|
149
|
+
|
150
|
+
if somecondition {
|
151
|
+
class { 'example2':
|
152
|
+
param1 => 'value1',
|
153
|
+
require => File['somefile'],
|
154
|
+
}
|
155
|
+
}
|
156
|
+
}
|
157
|
+
EOF
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'with fix disabled' do
|
161
|
+
it 'should detect a single problem' do
|
162
|
+
expect(problems).to have(3).problem
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should create a error' do
|
166
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(8).in_column(4)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'with fix enabled' do
|
171
|
+
before do
|
172
|
+
PuppetLint.configuration.fix = true
|
173
|
+
end
|
174
|
+
|
175
|
+
after do
|
176
|
+
PuppetLint.configuration.fix = false
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'should detect a single problem' do
|
180
|
+
expect(problems).to have(3).problem
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should create a error' do
|
184
|
+
expect(problems).to contain_fixed(opening_brace_msg)
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should remove a space' do
|
188
|
+
expect(manifest).to eq(
|
189
|
+
<<~EOF,
|
190
|
+
# example
|
191
|
+
#
|
192
|
+
# Main class, includes all other classes.
|
193
|
+
#
|
194
|
+
|
195
|
+
class example (
|
196
|
+
String $content,
|
197
|
+
) {
|
198
|
+
$value = [{ 'key' => 'value' }]
|
199
|
+
$value2 = [
|
200
|
+
{
|
201
|
+
'key' => 'value1',
|
202
|
+
},
|
203
|
+
{
|
204
|
+
'key' => 'value2',
|
205
|
+
},
|
206
|
+
]
|
207
|
+
$value3 = myfunc($value1)
|
208
|
+
|
209
|
+
if somecondition {
|
210
|
+
class { 'example2':
|
211
|
+
param1 => 'value1',
|
212
|
+
require => File['somefile'],
|
213
|
+
}
|
214
|
+
}
|
215
|
+
}
|
216
|
+
EOF
|
217
|
+
)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'with newline' do
|
223
|
+
let(:code) do
|
224
|
+
<<~EOF
|
225
|
+
# example
|
226
|
+
#
|
227
|
+
# Main class, includes all other classes.
|
228
|
+
#
|
229
|
+
|
230
|
+
class example (
|
231
|
+
String $content,
|
232
|
+
)
|
233
|
+
{
|
234
|
+
$value = [{ 'key' => 'value' }]
|
235
|
+
$value2 = [
|
236
|
+
{
|
237
|
+
'key' => 'value1',
|
238
|
+
},
|
239
|
+
{
|
240
|
+
'key' => 'value2',
|
241
|
+
},
|
242
|
+
]
|
243
|
+
$value3 = myfunc($value1)
|
244
|
+
|
245
|
+
if somecondition
|
246
|
+
{
|
247
|
+
class
|
248
|
+
{ 'example2':
|
249
|
+
param1 => 'value1',
|
250
|
+
require => File['somefile'],
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}
|
254
|
+
EOF
|
255
|
+
end
|
256
|
+
|
257
|
+
context 'with fix disabled' do
|
258
|
+
it 'should detect a single problem' do
|
259
|
+
expect(problems).to have(3).problem
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'should create a error' do
|
263
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(1)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context 'with fix enabled' do
|
268
|
+
before do
|
269
|
+
PuppetLint.configuration.fix = true
|
270
|
+
end
|
271
|
+
|
272
|
+
after do
|
273
|
+
PuppetLint.configuration.fix = false
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'should detect a single problem' do
|
277
|
+
expect(problems).to have(3).problem
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'should create a error' do
|
281
|
+
expect(problems).to contain_fixed(opening_brace_msg)
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'should fix the newline' do
|
285
|
+
expect(manifest).to eq(
|
286
|
+
<<~EOF,
|
287
|
+
# example
|
288
|
+
#
|
289
|
+
# Main class, includes all other classes.
|
290
|
+
#
|
291
|
+
|
292
|
+
class example (
|
293
|
+
String $content,
|
294
|
+
) {
|
295
|
+
$value = [{ 'key' => 'value' }]
|
296
|
+
$value2 = [
|
297
|
+
{
|
298
|
+
'key' => 'value1',
|
299
|
+
},
|
300
|
+
{
|
301
|
+
'key' => 'value2',
|
302
|
+
},
|
303
|
+
]
|
304
|
+
$value3 = myfunc($value1)
|
305
|
+
|
306
|
+
if somecondition {
|
307
|
+
class { 'example2':
|
308
|
+
param1 => 'value1',
|
309
|
+
require => File['somefile'],
|
310
|
+
}
|
311
|
+
}
|
312
|
+
}
|
313
|
+
EOF
|
314
|
+
)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
context 'with comment' do
|
320
|
+
let(:code) do
|
321
|
+
<<~EOF
|
322
|
+
# example
|
323
|
+
#
|
324
|
+
# Main class, includes all other classes.
|
325
|
+
#
|
326
|
+
|
327
|
+
class example (
|
328
|
+
String $content,
|
329
|
+
) # some generic comment
|
330
|
+
{
|
331
|
+
$value = [{ 'key' => 'value' }]
|
332
|
+
$value2 = [
|
333
|
+
{
|
334
|
+
'key' => 'value1',
|
335
|
+
},
|
336
|
+
{
|
337
|
+
'key' => 'value2',
|
338
|
+
},
|
339
|
+
]
|
340
|
+
$value3 = myfunc($value1)
|
341
|
+
|
342
|
+
if somecondition # some generic comment
|
343
|
+
{
|
344
|
+
class { 'example2':
|
345
|
+
param1 => 'value1',
|
346
|
+
require => File['somefile'],
|
347
|
+
}
|
348
|
+
}
|
349
|
+
}
|
350
|
+
EOF
|
351
|
+
end
|
352
|
+
|
353
|
+
context 'with fix disabled' do
|
354
|
+
it 'should detect a single problem' do
|
355
|
+
expect(problems).to have(0).problem
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
context 'with good inherits' do
|
361
|
+
let(:code) do
|
362
|
+
<<~EOF
|
363
|
+
# example
|
364
|
+
#
|
365
|
+
# Main class, includes all other classes.
|
366
|
+
#
|
367
|
+
|
368
|
+
class example (
|
369
|
+
String $content,
|
370
|
+
) inherits otherclass {
|
371
|
+
$value = [{ 'key' => 'value' }]
|
372
|
+
$value2 = [
|
373
|
+
{
|
374
|
+
'key' => 'value1',
|
375
|
+
},
|
376
|
+
{
|
377
|
+
'key' => 'value2',
|
378
|
+
},
|
379
|
+
]
|
380
|
+
$value3 = myfunc($value1)
|
381
|
+
|
382
|
+
if somecondition {
|
383
|
+
class { 'example2':
|
384
|
+
param1 => 'value1',
|
385
|
+
require => File['somefile'],
|
386
|
+
}
|
387
|
+
}
|
388
|
+
}
|
389
|
+
EOF
|
390
|
+
end
|
391
|
+
|
392
|
+
context 'with fix disabled' do
|
393
|
+
it 'should detect no problem' do
|
394
|
+
expect(problems).to have(0).problems
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
context 'with bad inherits' do
|
400
|
+
let(:code) do
|
401
|
+
<<~EOF
|
402
|
+
# example
|
403
|
+
#
|
404
|
+
# Main class, includes all other classes.
|
405
|
+
#
|
406
|
+
|
407
|
+
class example (
|
408
|
+
String $content,
|
409
|
+
) inherits otherclass{
|
410
|
+
$value = [{ 'key' => 'value' }]
|
411
|
+
$value2 = [
|
412
|
+
{
|
413
|
+
'key' => 'value1',
|
414
|
+
},
|
415
|
+
{
|
416
|
+
'key' => 'value2',
|
417
|
+
},
|
418
|
+
]
|
419
|
+
$value3 = myfunc($value1)
|
420
|
+
|
421
|
+
if somecondition {
|
422
|
+
class { 'example2':
|
423
|
+
param1 => 'value1',
|
424
|
+
require => File['somefile'],
|
425
|
+
}
|
426
|
+
}
|
427
|
+
}
|
428
|
+
EOF
|
429
|
+
end
|
430
|
+
|
431
|
+
context 'with fix disabled' do
|
432
|
+
it 'should detect a single problem' do
|
433
|
+
expect(problems).to have(1).problem
|
434
|
+
end
|
435
|
+
|
436
|
+
it 'should create a error' do
|
437
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(8).in_column(22)
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
context 'with fix enabled' do
|
442
|
+
before do
|
443
|
+
PuppetLint.configuration.fix = true
|
444
|
+
end
|
445
|
+
|
446
|
+
after do
|
447
|
+
PuppetLint.configuration.fix = false
|
448
|
+
end
|
449
|
+
|
450
|
+
it 'should detect a missing space' do
|
451
|
+
expect(problems).to have(1).problem
|
452
|
+
end
|
453
|
+
|
454
|
+
it 'should add the space' do
|
455
|
+
expect(manifest).to eq(
|
456
|
+
<<~EOF,
|
457
|
+
# example
|
458
|
+
#
|
459
|
+
# Main class, includes all other classes.
|
460
|
+
#
|
461
|
+
|
462
|
+
class example (
|
463
|
+
String $content,
|
464
|
+
) inherits otherclass {
|
465
|
+
$value = [{ 'key' => 'value' }]
|
466
|
+
$value2 = [
|
467
|
+
{
|
468
|
+
'key' => 'value1',
|
469
|
+
},
|
470
|
+
{
|
471
|
+
'key' => 'value2',
|
472
|
+
},
|
473
|
+
]
|
474
|
+
$value3 = myfunc($value1)
|
475
|
+
|
476
|
+
if somecondition {
|
477
|
+
class { 'example2':
|
478
|
+
param1 => 'value1',
|
479
|
+
require => File['somefile'],
|
480
|
+
}
|
481
|
+
}
|
482
|
+
}
|
483
|
+
EOF
|
484
|
+
)
|
485
|
+
end
|
486
|
+
end
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
describe 'manifest_whitespace_opening_brace_after' do
|
491
|
+
let(:opening_brace_msg) { 'there should be a single space or single newline after an opening brace' }
|
492
|
+
|
493
|
+
context 'with two spaces' do
|
494
|
+
let(:code) do
|
495
|
+
<<~EOF
|
496
|
+
# example
|
497
|
+
#
|
498
|
+
# Main class, includes all other classes.
|
499
|
+
#
|
500
|
+
|
501
|
+
class example (
|
502
|
+
String $content,
|
503
|
+
) {
|
504
|
+
$value = [{ 'key' => 'value' }]
|
505
|
+
$value2 = [
|
506
|
+
{
|
507
|
+
'key' => 'value1',
|
508
|
+
},
|
509
|
+
{
|
510
|
+
'key' => 'value2',
|
511
|
+
},
|
512
|
+
]
|
513
|
+
$value3 = myfunc($value1)
|
514
|
+
$value4 = ['somekey']
|
515
|
+
$value5 = []
|
516
|
+
$value6 = {}
|
517
|
+
$value7 = {
|
518
|
+
# nothing
|
519
|
+
}
|
520
|
+
|
521
|
+
if somecondition {
|
522
|
+
class { 'example2':
|
523
|
+
param1 => 'value1',
|
524
|
+
require => File['somefile'],
|
525
|
+
}
|
526
|
+
}
|
527
|
+
}
|
528
|
+
EOF
|
529
|
+
end
|
530
|
+
|
531
|
+
context 'with fix disabled' do
|
532
|
+
it 'should detect 2 problems' do
|
533
|
+
expect(problems).to have(2).problem
|
534
|
+
end
|
535
|
+
|
536
|
+
it 'should create a error' do
|
537
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(14)
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
context 'with fix enabled' do
|
542
|
+
before do
|
543
|
+
PuppetLint.configuration.fix = true
|
544
|
+
end
|
545
|
+
|
546
|
+
after do
|
547
|
+
PuppetLint.configuration.fix = false
|
548
|
+
end
|
549
|
+
|
550
|
+
it 'should detect 2 problems' do
|
551
|
+
expect(problems).to have(2).problem
|
552
|
+
end
|
553
|
+
|
554
|
+
it 'should create a error' do
|
555
|
+
expect(problems).to contain_fixed(opening_brace_msg)
|
556
|
+
end
|
557
|
+
|
558
|
+
it 'should add spaces' do
|
559
|
+
expect(manifest).to eq(
|
560
|
+
<<~EOF,
|
561
|
+
# example
|
562
|
+
#
|
563
|
+
# Main class, includes all other classes.
|
564
|
+
#
|
565
|
+
|
566
|
+
class example (
|
567
|
+
String $content,
|
568
|
+
) {
|
569
|
+
$value = [{ 'key' => 'value' }]
|
570
|
+
$value2 = [
|
571
|
+
{
|
572
|
+
'key' => 'value1',
|
573
|
+
},
|
574
|
+
{
|
575
|
+
'key' => 'value2',
|
576
|
+
},
|
577
|
+
]
|
578
|
+
$value3 = myfunc($value1)
|
579
|
+
$value4 = ['somekey']
|
580
|
+
$value5 = []
|
581
|
+
$value6 = {}
|
582
|
+
$value7 = {
|
583
|
+
# nothing
|
584
|
+
}
|
585
|
+
|
586
|
+
if somecondition {
|
587
|
+
class { 'example2':
|
588
|
+
param1 => 'value1',
|
589
|
+
require => File['somefile'],
|
590
|
+
}
|
591
|
+
}
|
592
|
+
}
|
593
|
+
EOF
|
594
|
+
)
|
595
|
+
end
|
596
|
+
end
|
597
|
+
end
|
598
|
+
|
599
|
+
context 'with no spaces' do
|
600
|
+
let(:code) do
|
601
|
+
<<~EOF
|
602
|
+
# example
|
603
|
+
#
|
604
|
+
# Main class, includes all other classes.
|
605
|
+
#
|
606
|
+
|
607
|
+
class example (
|
608
|
+
String $content,
|
609
|
+
) {
|
610
|
+
$value = [{'key' => 'value' }]
|
611
|
+
$value2 = [
|
612
|
+
{
|
613
|
+
'key' => 'value1',
|
614
|
+
},
|
615
|
+
{
|
616
|
+
'key' => 'value2',
|
617
|
+
},
|
618
|
+
]
|
619
|
+
$value3 = myfunc($value1)
|
620
|
+
|
621
|
+
if somecondition {
|
622
|
+
class {'example2':
|
623
|
+
param1 => 'value1',
|
624
|
+
require => File['somefile'],
|
625
|
+
}
|
626
|
+
}
|
627
|
+
}
|
628
|
+
EOF
|
629
|
+
end
|
630
|
+
|
631
|
+
context 'with fix disabled' do
|
632
|
+
it 'should detect 2 problems' do
|
633
|
+
expect(problems).to have(2).problem
|
634
|
+
end
|
635
|
+
|
636
|
+
it 'should create a error' do
|
637
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(14)
|
638
|
+
end
|
639
|
+
end
|
640
|
+
|
641
|
+
context 'with fix enabled' do
|
642
|
+
before do
|
643
|
+
PuppetLint.configuration.fix = true
|
644
|
+
end
|
645
|
+
|
646
|
+
after do
|
647
|
+
PuppetLint.configuration.fix = false
|
648
|
+
end
|
649
|
+
|
650
|
+
it 'should detect 2 problems' do
|
651
|
+
expect(problems).to have(2).problem
|
652
|
+
end
|
653
|
+
|
654
|
+
it 'should create a error' do
|
655
|
+
expect(problems).to contain_fixed(opening_brace_msg)
|
656
|
+
end
|
657
|
+
|
658
|
+
it 'should add spaces' do
|
659
|
+
expect(manifest).to eq(
|
660
|
+
<<~EOF,
|
661
|
+
# example
|
662
|
+
#
|
663
|
+
# Main class, includes all other classes.
|
664
|
+
#
|
665
|
+
|
666
|
+
class example (
|
667
|
+
String $content,
|
668
|
+
) {
|
669
|
+
$value = [{ 'key' => 'value' }]
|
670
|
+
$value2 = [
|
671
|
+
{
|
672
|
+
'key' => 'value1',
|
673
|
+
},
|
674
|
+
{
|
675
|
+
'key' => 'value2',
|
676
|
+
},
|
677
|
+
]
|
678
|
+
$value3 = myfunc($value1)
|
679
|
+
|
680
|
+
if somecondition {
|
681
|
+
class { 'example2':
|
682
|
+
param1 => 'value1',
|
683
|
+
require => File['somefile'],
|
684
|
+
}
|
685
|
+
}
|
686
|
+
}
|
687
|
+
EOF
|
688
|
+
)
|
689
|
+
end
|
690
|
+
end
|
691
|
+
end
|
692
|
+
|
693
|
+
context 'with two newlines' do
|
694
|
+
let(:code) do
|
695
|
+
<<~EOF
|
696
|
+
# example
|
697
|
+
#
|
698
|
+
# Main class, includes all other classes.
|
699
|
+
#
|
700
|
+
|
701
|
+
class example (
|
702
|
+
String $content,
|
703
|
+
) {
|
704
|
+
|
705
|
+
$value = [{ 'key' => 'value' }]
|
706
|
+
$value2 = [
|
707
|
+
{
|
708
|
+
|
709
|
+
'key' => 'value1',
|
710
|
+
},
|
711
|
+
{
|
712
|
+
'key' => 'value2',
|
713
|
+
},
|
714
|
+
]
|
715
|
+
$value3 = myfunc($value1)
|
716
|
+
|
717
|
+
if somecondition {
|
718
|
+
|
719
|
+
class {
|
720
|
+
|
721
|
+
'example2':
|
722
|
+
param1 => 'value1',
|
723
|
+
require => File['somefile'],
|
724
|
+
}
|
725
|
+
}
|
726
|
+
}
|
727
|
+
EOF
|
728
|
+
end
|
729
|
+
|
730
|
+
context 'with fix disabled' do
|
731
|
+
it 'should detect 4 problems' do
|
732
|
+
expect(problems).to have(4).problem
|
733
|
+
end
|
734
|
+
|
735
|
+
it 'should create a error' do
|
736
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(1)
|
737
|
+
end
|
738
|
+
end
|
739
|
+
|
740
|
+
context 'with fix enabled' do
|
741
|
+
before do
|
742
|
+
PuppetLint.configuration.fix = true
|
743
|
+
end
|
744
|
+
|
745
|
+
after do
|
746
|
+
PuppetLint.configuration.fix = false
|
747
|
+
end
|
748
|
+
|
749
|
+
it 'should detect 4 problems' do
|
750
|
+
expect(problems).to have(4).problem
|
751
|
+
end
|
752
|
+
|
753
|
+
it 'should create a error' do
|
754
|
+
expect(problems).to contain_fixed(opening_brace_msg)
|
755
|
+
end
|
756
|
+
|
757
|
+
it 'should add spaces' do
|
758
|
+
expect(manifest).to eq(
|
759
|
+
<<~EOF,
|
760
|
+
# example
|
761
|
+
#
|
762
|
+
# Main class, includes all other classes.
|
763
|
+
#
|
764
|
+
|
765
|
+
class example (
|
766
|
+
String $content,
|
767
|
+
) {
|
768
|
+
$value = [{ 'key' => 'value' }]
|
769
|
+
$value2 = [
|
770
|
+
{
|
771
|
+
'key' => 'value1',
|
772
|
+
},
|
773
|
+
{
|
774
|
+
'key' => 'value2',
|
775
|
+
},
|
776
|
+
]
|
777
|
+
$value3 = myfunc($value1)
|
778
|
+
|
779
|
+
if somecondition {
|
780
|
+
class {
|
781
|
+
'example2':
|
782
|
+
param1 => 'value1',
|
783
|
+
require => File['somefile'],
|
784
|
+
}
|
785
|
+
}
|
786
|
+
}
|
787
|
+
EOF
|
788
|
+
)
|
789
|
+
end
|
790
|
+
end
|
791
|
+
end
|
792
|
+
end
|