puppet-lint-manifest_whitespace-check 0.1.5 → 0.1.10
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 +4 -4
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb +6 -15
- data/lib/puppet-lint/plugins/check_manifest_whitespace_closing_brace.rb +3 -3
- data/lib/puppet-lint/plugins/check_manifest_whitespace_closing_bracket.rb +3 -1
- data/lib/puppet-lint/plugins/check_manifest_whitespace_opening_brace.rb +3 -1
- data/lib/puppet-lint/plugins/tools.rb +1 -1
- data/spec/puppet-lint/plugins/manifest_whitespace_class_header_spec.rb +27 -27
- data/spec/puppet-lint/plugins/manifest_whitespace_closing_brace_spec.rb +42 -1
- data/spec/puppet-lint/plugins/manifest_whitespace_closing_bracket_spec.rb +17 -1
- data/spec/puppet-lint/plugins/manifest_whitespace_opening_brace_spec.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 490924a99a241b6362b189a9279316ace251905f99ff547f8c1f3a1801b196c0
|
4
|
+
data.tar.gz: 425fbd3f5b29ea52822bcf76d93c50261b23991e1a37558f3a999f50152feedc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73d1cb558a99dc97ce5e23f7d0ecde9f05016f830832e7ac534675a9a2b0cd0154c552b0df1acd0f77bd143ed90c6e7bbdf3e8ae015e382a4d2de75cf44cd5e0
|
7
|
+
data.tar.gz: 67bf90d141158f7af8ab63f922eff6b98ffdbf36d69d3f489153c6d02c1823843c31e1ee7453a4d488e56c5f624ea766610f27e1760344d135b64970d1933d51
|
@@ -36,13 +36,13 @@ PuppetLint.new_check(:manifest_whitespace_class_name_single_space_after) do
|
|
36
36
|
next unless name_token
|
37
37
|
|
38
38
|
next_token = name_token.next_token
|
39
|
-
|
40
|
-
next unless tokens.index(name_token) != tokens.index(
|
39
|
+
next_code_token = next_non_space_token(name_token)
|
40
|
+
next unless tokens.index(name_token) != tokens.index(next_code_token) - 2 ||
|
41
41
|
!is_single_space(next_token)
|
42
42
|
|
43
43
|
notify(
|
44
44
|
:error,
|
45
|
-
message: 'there should be a single space between the class or resource name and the
|
45
|
+
message: 'there should be a single space between the class or resource name and the next item',
|
46
46
|
line: next_token.line,
|
47
47
|
column: next_token.column,
|
48
48
|
token: next_token,
|
@@ -52,22 +52,13 @@ PuppetLint.new_check(:manifest_whitespace_class_name_single_space_after) do
|
|
52
52
|
|
53
53
|
def fix(problem)
|
54
54
|
token = problem[:token]
|
55
|
-
|
56
|
-
|
57
|
-
if token == brace_token
|
58
|
-
add_token(tokens.index(brace_token), new_single_space)
|
59
|
-
return
|
60
|
-
end
|
61
|
-
|
62
|
-
while token != brace_token
|
63
|
-
unless %i[WHITESPACE INDENT NEWLINE].include?(token.type)
|
64
|
-
raise PuppetLint::NoFix
|
65
|
-
end
|
55
|
+
next_code_token = next_non_space_token(token.prev_token)
|
66
56
|
|
57
|
+
while token != next_code_token
|
67
58
|
remove_token(token)
|
68
59
|
token = token.next_token
|
69
60
|
end
|
70
61
|
|
71
|
-
add_token(tokens.index(
|
62
|
+
add_token(tokens.index(next_code_token), new_single_space)
|
72
63
|
end
|
73
64
|
end
|
@@ -7,9 +7,9 @@ PuppetLint.new_check(:manifest_whitespace_closing_brace_before) do
|
|
7
7
|
prev_code_token = prev_non_space_token(brace_token)
|
8
8
|
|
9
9
|
next unless prev_token && prev_code_token
|
10
|
-
next if %i[LBRACE
|
10
|
+
next if %i[LBRACE].include?(prev_token.type)
|
11
11
|
|
12
|
-
unless %i[LBRACE
|
12
|
+
unless %i[LBRACE].include?(prev_code_token.type)
|
13
13
|
if is_single_space(prev_token) && tokens.index(prev_code_token) == tokens.index(brace_token) - 2
|
14
14
|
next
|
15
15
|
end
|
@@ -73,7 +73,7 @@ PuppetLint.new_check(:manifest_whitespace_closing_brace_after) do
|
|
73
73
|
|
74
74
|
notify(
|
75
75
|
:error,
|
76
|
-
message: 'there should be either a bracket,
|
76
|
+
message: 'there should be either a bracket, punctuation mark, closing quote or a newline after a closing brace, or whitespace and none of the aforementioned',
|
77
77
|
line: next_token.line,
|
78
78
|
column: next_token.column,
|
79
79
|
token: next_token,
|
@@ -55,6 +55,8 @@ PuppetLint.new_check(:manifest_whitespace_closing_bracket_after) do
|
|
55
55
|
next unless next_token
|
56
56
|
next if after_bracket_tokens.include?(next_token.type)
|
57
57
|
|
58
|
+
warn next_token.inspect
|
59
|
+
|
58
60
|
if next_token.type == :WHITESPACE
|
59
61
|
next_code_token = next_non_space_token(bracket_token)
|
60
62
|
next unless next_code_token
|
@@ -63,7 +65,7 @@ PuppetLint.new_check(:manifest_whitespace_closing_bracket_after) do
|
|
63
65
|
|
64
66
|
notify(
|
65
67
|
:error,
|
66
|
-
message: 'there should be either a bracket,
|
68
|
+
message: 'there should be either a bracket, punctuation mark, closing quote or a newline after a closing bracket, or whitespace and none of the aforementioned',
|
67
69
|
line: next_token.line,
|
68
70
|
column: next_token.column,
|
69
71
|
token: next_token,
|
@@ -7,7 +7,9 @@ PuppetLint.new_check(:manifest_whitespace_opening_brace_before) do
|
|
7
7
|
prev_code_token = prev_non_space_token(brace_token)
|
8
8
|
|
9
9
|
next unless prev_token && prev_code_token
|
10
|
-
|
10
|
+
if %i[LBRACK LBRACE COLON COMMA COMMENT].include?(prev_code_token.type)
|
11
|
+
next
|
12
|
+
end
|
11
13
|
next unless tokens.index(prev_code_token) != tokens.index(brace_token) - 2 ||
|
12
14
|
!is_single_space(prev_token)
|
13
15
|
|
@@ -66,10 +66,34 @@ describe 'manifest_whitespace_class_name_single_space_before' do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
context 'with inherits' do
|
71
|
+
let(:code) do
|
72
|
+
'class example inherits otherexample {'
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should detect no problems' do
|
76
|
+
expect(problems).to have(0).problem
|
77
|
+
end
|
78
|
+
end
|
69
79
|
end
|
70
80
|
|
71
81
|
describe 'manifest_whitespace_class_name_single_space_after' do
|
72
|
-
let(:single_space_msg) { 'there should be a single space between the class or resource name and the
|
82
|
+
let(:single_space_msg) { 'there should be a single space between the class or resource name and the next item' }
|
83
|
+
|
84
|
+
context 'with inherits' do
|
85
|
+
let(:code) do
|
86
|
+
<<~EOF
|
87
|
+
class example inherits otherexample {
|
88
|
+
assert_private()
|
89
|
+
}
|
90
|
+
EOF
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should detect no problems' do
|
94
|
+
expect(problems).to have(0).problem
|
95
|
+
end
|
96
|
+
end
|
73
97
|
|
74
98
|
context 'with parameters and no spaces' do
|
75
99
|
let(:code) do
|
@@ -405,32 +429,8 @@ describe 'manifest_whitespace_class_name_single_space_after' do
|
|
405
429
|
EOF
|
406
430
|
end
|
407
431
|
|
408
|
-
|
409
|
-
|
410
|
-
expect(problems).to have(1).problem
|
411
|
-
end
|
412
|
-
|
413
|
-
it 'should create a error' do
|
414
|
-
expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
context 'with fix enabled' do
|
419
|
-
before do
|
420
|
-
PuppetLint.configuration.fix = true
|
421
|
-
end
|
422
|
-
|
423
|
-
after do
|
424
|
-
PuppetLint.configuration.fix = false
|
425
|
-
end
|
426
|
-
|
427
|
-
it 'should detect a single problem' do
|
428
|
-
expect(problems).to have(1).problem
|
429
|
-
end
|
430
|
-
|
431
|
-
it 'should not fix the manifest' do
|
432
|
-
expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
|
433
|
-
end
|
432
|
+
it 'should detect no problem' do
|
433
|
+
expect(problems).to have(0).problems
|
434
434
|
end
|
435
435
|
end
|
436
436
|
end
|
@@ -5,6 +5,34 @@ require 'spec_helper'
|
|
5
5
|
describe 'manifest_whitespace_closing_brace_before' do
|
6
6
|
let(:closing_brace_msg) { 'there should be a bracket or a single newline before a closing brace' }
|
7
7
|
|
8
|
+
context 'with nested hash' do
|
9
|
+
let(:code) do
|
10
|
+
<<~EOF
|
11
|
+
Hash $instances = { 'localhost' => { 'url' => 'http://localhost/mod_status?auto' } },
|
12
|
+
EOF
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should detect no problems' do
|
16
|
+
expect(problems).to have(0).problem
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with iterator' do
|
21
|
+
let(:code) do
|
22
|
+
<<~EOF
|
23
|
+
['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
|
24
|
+
}
|
25
|
+
|
26
|
+
['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
|
27
|
+
}
|
28
|
+
EOF
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should detect no problems' do
|
32
|
+
expect(problems).to have(0).problem
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
8
36
|
context 'with comment only' do
|
9
37
|
let(:code) do
|
10
38
|
<<~EOF
|
@@ -344,7 +372,20 @@ describe 'manifest_whitespace_closing_brace_before' do
|
|
344
372
|
end
|
345
373
|
|
346
374
|
describe 'manifest_whitespace_closing_brace_after' do
|
347
|
-
let(:closing_brace_msg) { 'there should be either a bracket,
|
375
|
+
let(:closing_brace_msg) { 'there should be either a bracket, punctuation mark, closing quote or a newline after a closing brace, or whitespace and none of the aforementioned' }
|
376
|
+
|
377
|
+
context 'with iterator' do
|
378
|
+
let(:code) do
|
379
|
+
<<~EOF
|
380
|
+
['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
|
381
|
+
}
|
382
|
+
EOF
|
383
|
+
end
|
384
|
+
|
385
|
+
it 'should detect no problems' do
|
386
|
+
expect(problems).to have(0).problem
|
387
|
+
end
|
388
|
+
end
|
348
389
|
|
349
390
|
context 'with spaces' do
|
350
391
|
let(:code) do
|
@@ -153,7 +153,23 @@ describe 'manifest_whitespace_closing_bracket_before' do
|
|
153
153
|
end
|
154
154
|
|
155
155
|
describe 'manifest_whitespace_closing_bracket_after' do
|
156
|
-
let(:closing_bracket_msg) { 'there should be either a bracket,
|
156
|
+
let(:closing_bracket_msg) { 'there should be either a bracket, punctuation mark, closing quote or a newline after a closing bracket, or whitespace and none of the aforementioned' }
|
157
|
+
|
158
|
+
context 'with iterator' do
|
159
|
+
let(:code) do
|
160
|
+
<<~EOF
|
161
|
+
['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
|
162
|
+
}
|
163
|
+
|
164
|
+
['ib0', 'ib1', 'ib2', 'ib3', 'pub', 'oob', '0', '184'].each |String $name| {
|
165
|
+
}
|
166
|
+
EOF
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should detect no problems' do
|
170
|
+
expect(problems).to have(0).problem
|
171
|
+
end
|
172
|
+
end
|
157
173
|
|
158
174
|
context 'with spaces' do
|
159
175
|
let(:code) do
|
@@ -19,6 +19,21 @@ describe 'manifest_whitespace_opening_brace_before' do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
context 'with cases' do
|
23
|
+
let(:code) do
|
24
|
+
<<~EOF
|
25
|
+
case $facts['kernel'] {
|
26
|
+
'OpenBSD': { $has_wordexp = false }
|
27
|
+
default: { $has_wordexp = true }
|
28
|
+
}
|
29
|
+
EOF
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should detect no problems' do
|
33
|
+
expect(problems).to have(0).problem
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
22
37
|
context 'with no spaces' do
|
23
38
|
let(:code) do
|
24
39
|
<<~EOF
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-lint-manifest_whitespace-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jo Vandeginste
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet-lint
|