puppet-lint-unquoted_string-check 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/puppet-lint/plugins/check_unquoted_string_in_case.rb +58 -102
- data/spec/puppet-lint/plugins/check_unquoted_string_in_case/check_unquoted_string_in_case_spec.rb +119 -6
- data/spec/puppet-lint/plugins/check_unquoted_string_in_case/check_unquoted_string_in_selector_spec.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0f287edbcd2db83abe8c1764f5982f402c91a09
|
4
|
+
data.tar.gz: ad677f9fee5fb6ce5d0879f20e9b63a281f569ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b5768b1bab4cbfc8a4ca9653996ccabe8e76313a4c7224e4763026d286896125cb12b00b5ae5b0193109b983868dc14eb3b9912b51cabbb445fd80b05427b44
|
7
|
+
data.tar.gz: 6747989bffe6e7873e6084f2748d54c3c16a7c548a307648da9ce7aad91bc81363f68acca89dcd4b703b3f80eb7f55fd85e7d6ce060fb29a942ea875d2e0f91c
|
@@ -1,131 +1,87 @@
|
|
1
1
|
require 'pp'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
if depth == 0
|
18
|
-
case_indexes << {:start => token_idx, :end => idx}
|
19
|
-
break
|
20
|
-
end
|
3
|
+
def type_indexes(type)
|
4
|
+
type_indexes = []
|
5
|
+
tokens.each_index do |token_idx|
|
6
|
+
if tokens[token_idx].type == type
|
7
|
+
depth = 0
|
8
|
+
tokens[(token_idx + 1)..-1].each_index do |case_token_idx|
|
9
|
+
idx = case_token_idx + token_idx + 1
|
10
|
+
if tokens[idx].type == :LBRACE
|
11
|
+
depth += 1
|
12
|
+
elsif tokens[idx].type == :RBRACE
|
13
|
+
depth -= 1
|
14
|
+
if depth == 0
|
15
|
+
type_indexes << {:start => token_idx, :end => idx}
|
16
|
+
break
|
21
17
|
end
|
22
18
|
end
|
23
19
|
end
|
24
20
|
end
|
21
|
+
end
|
22
|
+
type_indexes
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def fix(problem)
|
40
|
-
case_indexes = []
|
41
|
-
|
42
|
-
tokens.each_index do |token_idx|
|
43
|
-
if tokens[token_idx].type == :CASE
|
44
|
-
depth = 0
|
45
|
-
tokens[(token_idx + 1)..-1].each_index do |case_token_idx|
|
46
|
-
idx = case_token_idx + token_idx + 1
|
47
|
-
if tokens[idx].type == :LBRACE
|
48
|
-
depth += 1
|
49
|
-
elsif tokens[idx].type == :RBRACE
|
50
|
-
depth -= 1
|
51
|
-
if depth == 0
|
52
|
-
case_indexes << {:start => token_idx, :end => idx}
|
53
|
-
break
|
54
|
-
end
|
55
|
-
end
|
25
|
+
def tokens_to_fix(type_tokens, sep_type)
|
26
|
+
tokens_to_fix = []
|
27
|
+
type_tokens.index do |r|
|
28
|
+
if r.type == sep_type
|
29
|
+
s = r.prev_token
|
30
|
+
while s.type != :NEWLINE
|
31
|
+
if s.type == :NAME || s.type == :CLASSREF
|
32
|
+
tokens_to_fix << s
|
56
33
|
end
|
34
|
+
s = s.prev_token
|
57
35
|
end
|
58
36
|
end
|
37
|
+
end
|
38
|
+
tokens_to_fix
|
39
|
+
end
|
59
40
|
|
60
|
-
|
61
|
-
|
41
|
+
def act_on_tokens(type, sep_type, &block)
|
42
|
+
type_indexes(type).each do |kase|
|
43
|
+
case_tokens = tokens[kase[:start]..kase[:end]]
|
62
44
|
|
63
|
-
|
45
|
+
tokens_to_fix(case_tokens, sep_type).each do |r|
|
46
|
+
block.call(r)
|
64
47
|
end
|
65
48
|
end
|
66
49
|
end
|
67
50
|
|
68
|
-
PuppetLint.new_check(:
|
51
|
+
PuppetLint.new_check(:unquoted_string_in_case) do
|
69
52
|
|
70
53
|
def check
|
71
|
-
|
54
|
+
act_on_tokens(:CASE, :COLON) do |r|
|
55
|
+
notify :warning, {
|
56
|
+
:message => 'unquoted string in case',
|
57
|
+
:line => r.line,
|
58
|
+
:column => r.column,
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
72
62
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
tokens[(token_idx + 1)..-1].each_index do |case_token_idx|
|
77
|
-
idx = case_token_idx + token_idx + 1
|
78
|
-
if tokens[idx].type == :LBRACE
|
79
|
-
depth += 1
|
80
|
-
elsif tokens[idx].type == :RBRACE
|
81
|
-
depth -= 1
|
82
|
-
if depth == 0
|
83
|
-
qmark_indexes << {:start => token_idx, :end => idx}
|
84
|
-
break
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
63
|
+
def fix(problem)
|
64
|
+
act_on_tokens(:CASE, :COLON) do |r|
|
65
|
+
r.type = :SSTRING
|
89
66
|
end
|
67
|
+
end
|
68
|
+
end
|
90
69
|
|
91
|
-
|
92
|
-
qmark_tokens = tokens[kase[:start]..kase[:end]]
|
70
|
+
PuppetLint.new_check(:unquoted_string_in_selector) do
|
93
71
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
72
|
+
def check
|
73
|
+
act_on_tokens(:QMARK, :FARROW) do |r|
|
74
|
+
notify :warning, {
|
75
|
+
:message => 'unquoted string in selector',
|
76
|
+
:line => r.line,
|
77
|
+
:column => r.column,
|
78
|
+
}
|
101
79
|
end
|
102
80
|
end
|
103
81
|
|
104
82
|
def fix(problem)
|
105
|
-
|
106
|
-
|
107
|
-
tokens.each_index do |token_idx|
|
108
|
-
if tokens[token_idx].type == :QMARK
|
109
|
-
depth = 0
|
110
|
-
tokens[(token_idx + 1)..-1].each_index do |case_token_idx|
|
111
|
-
idx = case_token_idx + token_idx + 1
|
112
|
-
if tokens[idx].type == :LBRACE
|
113
|
-
depth += 1
|
114
|
-
elsif tokens[idx].type == :RBRACE
|
115
|
-
depth -= 1
|
116
|
-
if depth == 0
|
117
|
-
qmark_indexes << {:start => token_idx, :end => idx}
|
118
|
-
break
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
qmark_indexes.each do |kase|
|
126
|
-
qmark_tokens = tokens[kase[:start]..kase[:end]]
|
127
|
-
|
128
|
-
qmark_tokens.index { |r| r.type = :SSTRING if r.type == :NAME || r.type == :CLASSREF }
|
83
|
+
act_on_tokens(:QMARK, :FARROW) do |r|
|
84
|
+
r.type = :SSTRING
|
129
85
|
end
|
130
86
|
end
|
131
87
|
end
|
data/spec/puppet-lint/plugins/check_unquoted_string_in_case/check_unquoted_string_in_case_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'unquoted_string_in_case' do
|
4
|
-
let(:msg) { '
|
4
|
+
let(:msg) { 'unquoted string in case' }
|
5
5
|
|
6
6
|
context 'with fix disabled' do
|
7
7
|
context 'quoted case' do
|
@@ -11,6 +11,9 @@ describe 'unquoted_string_in_case' do
|
|
11
11
|
'Solaris': {
|
12
12
|
$rootgroup = 'wheel'
|
13
13
|
}
|
14
|
+
'RedHat','Debian': {
|
15
|
+
$rootgroup = 'wheel'
|
16
|
+
}
|
14
17
|
/(Darwin|FreeBSD)/: {
|
15
18
|
$rootgroup = 'wheel'
|
16
19
|
}
|
@@ -80,6 +83,18 @@ describe 'unquoted_string_in_case' do
|
|
80
83
|
solaris: {
|
81
84
|
$rootgroup = 'wheel'
|
82
85
|
}
|
86
|
+
redhat,debian: {
|
87
|
+
include ::foo
|
88
|
+
}
|
89
|
+
redhat, debian: {
|
90
|
+
Foo { bar => 'baz' }
|
91
|
+
}
|
92
|
+
'redhat',debian: {
|
93
|
+
$rootgroup = wheel
|
94
|
+
}
|
95
|
+
redhat,'debian': {
|
96
|
+
$rootgroup = 'wheel'
|
97
|
+
}
|
83
98
|
/(Darwin|FreeBSD)/: {
|
84
99
|
$rootgroup = 'wheel'
|
85
100
|
}
|
@@ -91,7 +106,17 @@ describe 'unquoted_string_in_case' do
|
|
91
106
|
end
|
92
107
|
|
93
108
|
it 'should create a warning' do
|
94
|
-
expect(problems).to
|
109
|
+
expect(problems).to have(7).problems
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should create a warning' do
|
113
|
+
expect(problems).to contain_warning(msg).on_line(2).in_column(11)
|
114
|
+
expect(problems).to contain_warning(msg).on_line(5).in_column(11)
|
115
|
+
expect(problems).to contain_warning(msg).on_line(5).in_column(18)
|
116
|
+
expect(problems).to contain_warning(msg).on_line(8).in_column(11)
|
117
|
+
expect(problems).to contain_warning(msg).on_line(8).in_column(19)
|
118
|
+
expect(problems).to contain_warning(msg).on_line(11).in_column(20)
|
119
|
+
expect(problems).to contain_warning(msg).on_line(14).in_column(11)
|
95
120
|
end
|
96
121
|
end
|
97
122
|
|
@@ -113,7 +138,7 @@ describe 'unquoted_string_in_case' do
|
|
113
138
|
end
|
114
139
|
|
115
140
|
it 'should create a warning' do
|
116
|
-
expect(problems).to contain_warning(msg).on_line(
|
141
|
+
expect(problems).to contain_warning(msg).on_line(2).in_column(11)
|
117
142
|
end
|
118
143
|
end
|
119
144
|
end
|
@@ -134,6 +159,9 @@ describe 'unquoted_string_in_case' do
|
|
134
159
|
'Solaris': {
|
135
160
|
$rootgroup = 'wheel'
|
136
161
|
}
|
162
|
+
'RedHat','Debian': {
|
163
|
+
$rootgroup = 'wheel'
|
164
|
+
}
|
137
165
|
/(Darwin|FreeBSD)/: {
|
138
166
|
$rootgroup = 'wheel'
|
139
167
|
}
|
@@ -153,6 +181,61 @@ describe 'unquoted_string_in_case' do
|
|
153
181
|
end
|
154
182
|
end
|
155
183
|
|
184
|
+
context 'quoted case containing :NAME' do
|
185
|
+
let(:code) do
|
186
|
+
<<-EOS
|
187
|
+
case $osfamily {
|
188
|
+
'Solaris': {
|
189
|
+
include ::foo
|
190
|
+
}
|
191
|
+
/(Darwin|FreeBSD)/: {
|
192
|
+
include bar
|
193
|
+
}
|
194
|
+
default: {
|
195
|
+
$rootgroup = 'root'
|
196
|
+
}
|
197
|
+
}
|
198
|
+
EOS
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should not detect any problems' do
|
202
|
+
expect(problems).to have(0).problems
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should not modify the manifest' do
|
206
|
+
expect(manifest).to eq(code)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context 'quoted case containing :CLASSREF' do
|
211
|
+
let(:code) do
|
212
|
+
<<-EOS
|
213
|
+
case $osfamily {
|
214
|
+
'Solaris': {
|
215
|
+
Foo {
|
216
|
+
bar => 'baz',
|
217
|
+
}
|
218
|
+
}
|
219
|
+
/(Darwin|FreeBSD)/: {
|
220
|
+
$rootgroup = 'wheel'
|
221
|
+
include bar
|
222
|
+
}
|
223
|
+
default: {
|
224
|
+
$rootgroup = 'root'
|
225
|
+
}
|
226
|
+
}
|
227
|
+
EOS
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'should not detect any problems' do
|
231
|
+
expect(problems).to have(0).problems
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'should not modify the manifest' do
|
235
|
+
expect(manifest).to eq(code)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
156
239
|
context ':NAME in case' do
|
157
240
|
let(:code) do
|
158
241
|
<<-EOS
|
@@ -160,6 +243,18 @@ describe 'unquoted_string_in_case' do
|
|
160
243
|
solaris: {
|
161
244
|
$rootgroup = 'wheel'
|
162
245
|
}
|
246
|
+
redhat,debian: {
|
247
|
+
include ::foo
|
248
|
+
}
|
249
|
+
redhat, debian: {
|
250
|
+
Foo { bar => 'baz' }
|
251
|
+
}
|
252
|
+
'redhat',debian: {
|
253
|
+
$rootgroup = wheel
|
254
|
+
}
|
255
|
+
redhat,'debian': {
|
256
|
+
$rootgroup = 'wheel'
|
257
|
+
}
|
163
258
|
/(Darwin|FreeBSD)/: {
|
164
259
|
$rootgroup = 'wheel'
|
165
260
|
}
|
@@ -171,11 +266,17 @@ describe 'unquoted_string_in_case' do
|
|
171
266
|
end
|
172
267
|
|
173
268
|
it 'should only detect a single problem' do
|
174
|
-
expect(problems).to have(
|
269
|
+
expect(problems).to have(7).problem
|
175
270
|
end
|
176
271
|
|
177
272
|
it 'should fix the problem' do
|
178
|
-
expect(problems).to contain_fixed(msg).on_line(
|
273
|
+
expect(problems).to contain_fixed(msg).on_line(2).in_column(11)
|
274
|
+
expect(problems).to contain_fixed(msg).on_line(5).in_column(11)
|
275
|
+
expect(problems).to contain_fixed(msg).on_line(5).in_column(18)
|
276
|
+
expect(problems).to contain_fixed(msg).on_line(8).in_column(11)
|
277
|
+
expect(problems).to contain_fixed(msg).on_line(8).in_column(19)
|
278
|
+
expect(problems).to contain_fixed(msg).on_line(11).in_column(20)
|
279
|
+
expect(problems).to contain_fixed(msg).on_line(14).in_column(11)
|
179
280
|
end
|
180
281
|
|
181
282
|
it 'should quote the case statement' do
|
@@ -185,6 +286,18 @@ describe 'unquoted_string_in_case' do
|
|
185
286
|
'solaris': {
|
186
287
|
$rootgroup = 'wheel'
|
187
288
|
}
|
289
|
+
'redhat','debian': {
|
290
|
+
include ::foo
|
291
|
+
}
|
292
|
+
'redhat', 'debian': {
|
293
|
+
Foo { bar => 'baz' }
|
294
|
+
}
|
295
|
+
'redhat','debian': {
|
296
|
+
$rootgroup = wheel
|
297
|
+
}
|
298
|
+
'redhat','debian': {
|
299
|
+
$rootgroup = 'wheel'
|
300
|
+
}
|
188
301
|
/(Darwin|FreeBSD)/: {
|
189
302
|
$rootgroup = 'wheel'
|
190
303
|
}
|
@@ -219,7 +332,7 @@ describe 'unquoted_string_in_case' do
|
|
219
332
|
end
|
220
333
|
|
221
334
|
it 'should fix the problem' do
|
222
|
-
expect(problems).to contain_fixed(msg).on_line(
|
335
|
+
expect(problems).to contain_fixed(msg).on_line(2).in_column(11)
|
223
336
|
end
|
224
337
|
|
225
338
|
it 'should quote the case statement' do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'unquoted_string_in_selector' do
|
4
|
-
let(:msg) { '
|
4
|
+
let(:msg) { 'unquoted string in selector' }
|
5
5
|
|
6
6
|
context 'with fix disabled' do
|
7
7
|
context 'quoted case' do
|
@@ -32,7 +32,7 @@ describe 'unquoted_string_in_selector' do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'should create a warning' do
|
35
|
-
expect(problems).to contain_warning(msg).on_line(
|
35
|
+
expect(problems).to contain_warning(msg).on_line(2).in_column(11)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -48,7 +48,7 @@ describe 'unquoted_string_in_selector' do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'should create a warning' do
|
51
|
-
expect(problems).to contain_warning(msg).on_line(
|
51
|
+
expect(problems).to contain_warning(msg).on_line(2).in_column(11)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -98,7 +98,7 @@ describe 'unquoted_string_in_selector' do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'should fix the problem' do
|
101
|
-
expect(problems).to contain_fixed(msg).on_line(
|
101
|
+
expect(problems).to contain_fixed(msg).on_line(2).in_column(11)
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'should quote the case statement' do
|
@@ -130,7 +130,7 @@ describe 'unquoted_string_in_selector' do
|
|
130
130
|
end
|
131
131
|
|
132
132
|
it 'should fix the problem' do
|
133
|
-
expect(problems).to contain_fixed(msg).on_line(
|
133
|
+
expect(problems).to contain_fixed(msg).on_line(2).in_column(11)
|
134
134
|
end
|
135
135
|
|
136
136
|
it 'should quote the case statement' do
|