puppet-lint-manifest_whitespace-check 0.1.0 → 0.1.2
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/README.md +2 -2
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_inherits_single_space.rb +10 -10
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb +10 -10
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_opening_curly_brace.rb +9 -9
- data/spec/puppet-lint/plugins/manifest_whitespace_class_header_spec.rb +130 -2
- data/spec/puppet-lint/plugins/manifest_whitespace_class_inherits_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6c95fdd92713473387e0cb780ba993b73aac14c1b8a31ac3605cb211cb34413
|
4
|
+
data.tar.gz: 51b93e74f8b2ce71082873f4023efabc673fd8a6144710341695efdc80c102cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1940d7236fab0350b6cf217c41a88228f50de795f8e68ca3b3d0da03289578fc83ffc4708c86d37ffd71f9c8b0b254be75121c6c311e43aef7d4acfc89950170
|
7
|
+
data.tar.gz: e5cb33fa8ee74bb757fcab7cb333090b3e9770e909274ce313a51e5e1a382c60799893235f8a40d31fac1b21cf9c39b6ba4479765f75bd92e0a2563dc9e47bf9
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ This plugin provides a number of new checks to `puppet-lint`.
|
|
21
21
|
|
22
22
|
### manifest_whitespace_class_opening_curly_brace
|
23
23
|
|
24
|
-
> There should be a single space before the opening curly
|
24
|
+
> There should be a single space before the opening curly brace of a class body.
|
25
25
|
|
26
26
|
Good examples:
|
27
27
|
|
@@ -113,7 +113,7 @@ class myclass (
|
|
113
113
|
|
114
114
|
### manifest_whitespace_class_name_single_space_after
|
115
115
|
|
116
|
-
> There should be a single space between the class or resource name and the first
|
116
|
+
> There should be a single space between the class or resource name and the first brace.
|
117
117
|
|
118
118
|
Good examples:
|
119
119
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
PuppetLint.new_check(:manifest_whitespace_inherits_name_single_space_before) do
|
4
4
|
def check
|
5
5
|
tokens.select { |token| token.type == :INHERITS }.each do |inherits_token|
|
6
|
-
name_token = inherits_token.next_token_of(
|
6
|
+
name_token = inherits_token.next_token_of(%i[NAME FUNCTION_NAME])
|
7
7
|
next unless name_token
|
8
8
|
|
9
9
|
next_token = inherits_token.next_token
|
@@ -30,17 +30,17 @@ end
|
|
30
30
|
PuppetLint.new_check(:manifest_whitespace_inherits_name_single_space_after) do
|
31
31
|
def check
|
32
32
|
tokens.select { |token| token.type == :INHERITS }.each do |inherits_token|
|
33
|
-
name_token = inherits_token.next_token_of(
|
33
|
+
name_token = inherits_token.next_token_of(%i[NAME FUNCTION_NAME])
|
34
34
|
next unless name_token
|
35
35
|
|
36
36
|
next_token = name_token.next_token
|
37
|
-
|
38
|
-
next unless tokens.index(name_token) != tokens.index(
|
37
|
+
brace_token = name_token.next_token_of(%i[LPAREN LBRACE])
|
38
|
+
next unless tokens.index(name_token) != tokens.index(brace_token) - 2 ||
|
39
39
|
!is_single_space(next_token)
|
40
40
|
|
41
41
|
notify(
|
42
42
|
:error,
|
43
|
-
message: 'there should be a single space between the class or resource name and the first
|
43
|
+
message: 'there should be a single space between the class or resource name and the first brace',
|
44
44
|
line: next_token.line,
|
45
45
|
column: next_token.column,
|
46
46
|
token: next_token,
|
@@ -50,14 +50,14 @@ PuppetLint.new_check(:manifest_whitespace_inherits_name_single_space_after) do
|
|
50
50
|
|
51
51
|
def fix(problem)
|
52
52
|
token = problem[:token]
|
53
|
-
|
53
|
+
brace_token = token.prev_token.next_token_of(%i[LPAREN LBRACE])
|
54
54
|
|
55
|
-
if token ==
|
56
|
-
add_token(tokens.index(
|
55
|
+
if token == brace_token
|
56
|
+
add_token(tokens.index(brace_token), new_single_space)
|
57
57
|
return
|
58
58
|
end
|
59
59
|
|
60
|
-
while token !=
|
60
|
+
while token != brace_token
|
61
61
|
unless %i[WHITESPACE INDENT NEWLINE].include?(token.type)
|
62
62
|
raise PuppetLint::NoFix
|
63
63
|
end
|
@@ -66,6 +66,6 @@ PuppetLint.new_check(:manifest_whitespace_inherits_name_single_space_after) do
|
|
66
66
|
token = token.next_token
|
67
67
|
end
|
68
68
|
|
69
|
-
add_token(tokens.index(
|
69
|
+
add_token(tokens.index(brace_token), new_single_space)
|
70
70
|
end
|
71
71
|
end
|
@@ -4,7 +4,7 @@ PuppetLint.new_check(:manifest_whitespace_class_name_single_space_before) do
|
|
4
4
|
def check
|
5
5
|
(class_indexes + defined_type_indexes).each do |class_idx|
|
6
6
|
class_token = class_idx[:tokens].first
|
7
|
-
name_token = class_token.next_token_of(
|
7
|
+
name_token = class_token.next_token_of(%i[NAME FUNCTION_NAME])
|
8
8
|
next unless name_token
|
9
9
|
|
10
10
|
next_token = class_token.next_token
|
@@ -32,17 +32,17 @@ PuppetLint.new_check(:manifest_whitespace_class_name_single_space_after) do
|
|
32
32
|
def check
|
33
33
|
(class_indexes + defined_type_indexes).each do |class_idx|
|
34
34
|
class_token = class_idx[:tokens].first
|
35
|
-
name_token = class_token.next_token_of(
|
35
|
+
name_token = class_token.next_token_of(%i[NAME FUNCTION_NAME])
|
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
|
+
brace_token = name_token.next_token_of(%i[LPAREN LBRACE])
|
40
|
+
next unless tokens.index(name_token) != tokens.index(brace_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 first
|
45
|
+
message: 'there should be a single space between the class or resource name and the first brace',
|
46
46
|
line: next_token.line,
|
47
47
|
column: next_token.column,
|
48
48
|
token: next_token,
|
@@ -52,14 +52,14 @@ PuppetLint.new_check(:manifest_whitespace_class_name_single_space_after) do
|
|
52
52
|
|
53
53
|
def fix(problem)
|
54
54
|
token = problem[:token]
|
55
|
-
|
55
|
+
brace_token = token.prev_token.next_token_of(%i[LPAREN LBRACE])
|
56
56
|
|
57
|
-
if token ==
|
58
|
-
add_token(tokens.index(
|
57
|
+
if token == brace_token
|
58
|
+
add_token(tokens.index(brace_token), new_single_space)
|
59
59
|
return
|
60
60
|
end
|
61
61
|
|
62
|
-
while token !=
|
62
|
+
while token != brace_token
|
63
63
|
unless %i[WHITESPACE INDENT NEWLINE].include?(token.type)
|
64
64
|
raise PuppetLint::NoFix
|
65
65
|
end
|
@@ -68,6 +68,6 @@ PuppetLint.new_check(:manifest_whitespace_class_name_single_space_after) do
|
|
68
68
|
token = token.next_token
|
69
69
|
end
|
70
70
|
|
71
|
-
add_token(tokens.index(
|
71
|
+
add_token(tokens.index(brace_token), new_single_space)
|
72
72
|
end
|
73
73
|
end
|
@@ -4,27 +4,27 @@ PuppetLint.new_check(:manifest_whitespace_class_opening_curly_brace) do
|
|
4
4
|
def check
|
5
5
|
(class_indexes + defined_type_indexes).each do |class_idx|
|
6
6
|
class_token = class_idx[:tokens].first
|
7
|
-
|
8
|
-
prev_token =
|
9
|
-
prev_code_token =
|
7
|
+
brace_token = class_token.next_token_of(:LBRACE)
|
8
|
+
prev_token = brace_token.prev_token
|
9
|
+
prev_code_token = brace_token.prev_token_of(%i[RPAREN NAME FUNCTION_NAME])
|
10
10
|
|
11
11
|
next unless prev_code_token
|
12
|
-
next unless tokens.index(prev_code_token) != tokens.index(
|
12
|
+
next unless tokens.index(prev_code_token) != tokens.index(brace_token) - 2 ||
|
13
13
|
!is_single_space(prev_token)
|
14
14
|
|
15
15
|
notify(
|
16
16
|
:error,
|
17
|
-
message: 'there should be a single space before the opening curly
|
18
|
-
line:
|
19
|
-
column:
|
20
|
-
token:
|
17
|
+
message: 'there should be a single space before the opening curly brace of a class body',
|
18
|
+
line: brace_token.line,
|
19
|
+
column: brace_token.column,
|
20
|
+
token: brace_token,
|
21
21
|
)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
def fix(problem)
|
26
26
|
token = problem[:token]
|
27
|
-
prev_code_token = token.prev_token_of(%i[RPAREN NAME]).next_token
|
27
|
+
prev_code_token = token.prev_token_of(%i[RPAREN NAME FUNCTION_NAME]).next_token
|
28
28
|
|
29
29
|
while token != prev_code_token
|
30
30
|
unless %i[WHITESPACE INDENT NEWLINE].include?(prev_code_token.type)
|
@@ -69,7 +69,135 @@ describe 'manifest_whitespace_class_name_single_space_before' do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
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 first
|
72
|
+
let(:single_space_msg) { 'there should be a single space between the class or resource name and the first brace' }
|
73
|
+
|
74
|
+
context 'with parameters and no spaces' do
|
75
|
+
let(:code) do
|
76
|
+
<<~EOF
|
77
|
+
# example
|
78
|
+
#
|
79
|
+
# Main class, includes all other classes.
|
80
|
+
#
|
81
|
+
|
82
|
+
class myclass(
|
83
|
+
$param1,
|
84
|
+
) {
|
85
|
+
class { 'example2':
|
86
|
+
param1 => 'value1',
|
87
|
+
}
|
88
|
+
}
|
89
|
+
EOF
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'with fix disabled' do
|
93
|
+
it 'should detect a single problem' do
|
94
|
+
expect(problems).to have(1).problem
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should create a error' do
|
98
|
+
expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'with fix enabled' do
|
103
|
+
before do
|
104
|
+
PuppetLint.configuration.fix = true
|
105
|
+
end
|
106
|
+
|
107
|
+
after do
|
108
|
+
PuppetLint.configuration.fix = false
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should detect a single problem' do
|
112
|
+
expect(problems).to have(1).problem
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should fix the manifest' do
|
116
|
+
expect(problems).to contain_fixed(single_space_msg)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should fix the newline' do
|
120
|
+
expect(manifest).to eq(
|
121
|
+
<<~EOF,
|
122
|
+
# example
|
123
|
+
#
|
124
|
+
# Main class, includes all other classes.
|
125
|
+
#
|
126
|
+
|
127
|
+
class myclass (
|
128
|
+
$param1,
|
129
|
+
) {
|
130
|
+
class { 'example2':
|
131
|
+
param1 => 'value1',
|
132
|
+
}
|
133
|
+
}
|
134
|
+
EOF
|
135
|
+
)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'with scope and no spaces' do
|
141
|
+
let(:code) do
|
142
|
+
<<~EOF
|
143
|
+
# example
|
144
|
+
#
|
145
|
+
# Main class, includes all other classes.
|
146
|
+
#
|
147
|
+
|
148
|
+
class mymodule::example{
|
149
|
+
class { 'example2':
|
150
|
+
param1 => 'value1',
|
151
|
+
}
|
152
|
+
}
|
153
|
+
EOF
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'with fix disabled' do
|
157
|
+
it 'should detect a single problem' do
|
158
|
+
expect(problems).to have(1).problem
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should create a error' do
|
162
|
+
expect(problems).to contain_error(single_space_msg).on_line(6).in_column(24)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context 'with fix enabled' do
|
167
|
+
before do
|
168
|
+
PuppetLint.configuration.fix = true
|
169
|
+
end
|
170
|
+
|
171
|
+
after do
|
172
|
+
PuppetLint.configuration.fix = false
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should detect a single problem' do
|
176
|
+
expect(problems).to have(1).problem
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'should fix the manifest' do
|
180
|
+
expect(problems).to contain_fixed(single_space_msg)
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should fix the newline' do
|
184
|
+
expect(manifest).to eq(
|
185
|
+
<<~EOF,
|
186
|
+
# example
|
187
|
+
#
|
188
|
+
# Main class, includes all other classes.
|
189
|
+
#
|
190
|
+
|
191
|
+
class mymodule::example {
|
192
|
+
class { 'example2':
|
193
|
+
param1 => 'value1',
|
194
|
+
}
|
195
|
+
}
|
196
|
+
EOF
|
197
|
+
)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
73
201
|
|
74
202
|
context 'with no spaces' do
|
75
203
|
let(:code) do
|
@@ -308,7 +436,7 @@ describe 'manifest_whitespace_class_name_single_space_after' do
|
|
308
436
|
end
|
309
437
|
|
310
438
|
describe 'manifest_whitespace_class_opening_curly_brace' do
|
311
|
-
let(:opening_curly_brace_same_line_msg) { 'there should be a single space before the opening curly
|
439
|
+
let(:opening_curly_brace_same_line_msg) { 'there should be a single space before the opening curly brace of a class body' }
|
312
440
|
|
313
441
|
context 'with no spaces' do
|
314
442
|
let(:code) do
|
@@ -69,7 +69,7 @@ describe 'manifest_whitespace_inherits_name_single_space_before' do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
describe 'manifest_whitespace_inherits_name_single_space_after' do
|
72
|
-
let(:single_space_msg) { 'there should be a single space between the class or resource name and the first
|
72
|
+
let(:single_space_msg) { 'there should be a single space between the class or resource name and the first brace' }
|
73
73
|
|
74
74
|
context 'with no spaces' do
|
75
75
|
let(:code) do
|