puppet-lint 0.1.13 → 0.2.0.pre1
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.
- data/.gitignore +5 -0
- data/README.md +19 -5
- data/bin/puppet-lint +2 -0
- data/lib/puppet-lint.rb +2 -11
- data/lib/puppet-lint/configuration.rb +4 -0
- data/lib/puppet-lint/lexer.rb +244 -0
- data/lib/puppet-lint/plugin.rb +125 -54
- data/lib/puppet-lint/plugins/check_classes.rb +135 -49
- data/lib/puppet-lint/plugins/check_conditionals.rb +34 -23
- data/lib/puppet-lint/plugins/check_resources.rb +114 -28
- data/lib/puppet-lint/plugins/check_strings.rb +67 -79
- data/lib/puppet-lint/plugins/check_variables.rb +13 -18
- data/lib/puppet-lint/plugins/check_whitespace.rb +70 -40
- data/lib/puppet-lint/tasks/puppet-lint.rb +11 -3
- data/lib/puppet-lint/version.rb +3 -0
- data/puppet-lint.gemspec +8 -29
- data/spec/puppet-lint/check_classes_spec.rb +72 -23
- data/spec/puppet-lint/check_conditionals_spec.rb +19 -3
- data/spec/puppet-lint/check_resources_spec.rb +9 -16
- data/spec/puppet-lint/check_strings_spec.rb +94 -7
- data/spec/puppet-lint/check_variables_spec.rb +20 -10
- data/spec/puppet-lint/check_whitespace_spec.rb +13 -0
- data/spec/spec_helper.rb +15 -10
- metadata +30 -17
@@ -3,25 +3,30 @@ require 'spec_helper'
|
|
3
3
|
describe PuppetLint::Plugins::CheckClasses do
|
4
4
|
subject do
|
5
5
|
klass = described_class.new
|
6
|
-
|
6
|
+
fileinfo = {}
|
7
|
+
fileinfo[:fullpath] = defined?(fullpath).nil? ? '' : fullpath
|
8
|
+
klass.run(fileinfo, code)
|
7
9
|
klass
|
8
10
|
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
let(:code) { "Class[foo] -> Class[bar]" }
|
12
|
+
describe 'chain 2 resources left to right' do
|
13
|
+
let(:code) { "Class[foo] -> Class[bar]" }
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
its(:problems) { should be_empty }
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
describe 'chain 2 resources right to left' do
|
19
|
+
let(:code) { "Class[foo] <- Class[bar]" }
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
its(:problems) {
|
22
|
+
should have_problem({
|
23
|
+
:kind => :warning,
|
24
|
+
:message => "right-to-left (<-) relationship",
|
25
|
+
:linenumber => 1,
|
26
|
+
:column => 12,
|
27
|
+
})
|
28
|
+
should_not have_problem :kind => :error
|
29
|
+
}
|
25
30
|
end
|
26
31
|
|
27
32
|
describe 'class on its own' do
|
@@ -39,7 +44,12 @@ describe PuppetLint::Plugins::CheckClasses do
|
|
39
44
|
}
|
40
45
|
|
41
46
|
its(:problems) {
|
42
|
-
should have_problem
|
47
|
+
should have_problem({
|
48
|
+
:kind => :warning,
|
49
|
+
:message => "class defined inside a class",
|
50
|
+
:linenumber => 3,
|
51
|
+
:column => 9,
|
52
|
+
})
|
43
53
|
should_not have_problem :kind => :error
|
44
54
|
}
|
45
55
|
end
|
@@ -53,7 +63,12 @@ describe PuppetLint::Plugins::CheckClasses do
|
|
53
63
|
}
|
54
64
|
|
55
65
|
its(:problems) {
|
56
|
-
should have_problem
|
66
|
+
should have_problem({
|
67
|
+
:kind => :warning,
|
68
|
+
:message => "define defined inside a class",
|
69
|
+
:linenumber => 3,
|
70
|
+
:column => 9,
|
71
|
+
})
|
57
72
|
should_not have_problem :kind => :error
|
58
73
|
}
|
59
74
|
end
|
@@ -68,7 +83,12 @@ describe PuppetLint::Plugins::CheckClasses do
|
|
68
83
|
let(:code) { "class foo::bar inherits baz { }" }
|
69
84
|
|
70
85
|
its(:problems) {
|
71
|
-
should have_problem
|
86
|
+
should have_problem({
|
87
|
+
:kind => :warning,
|
88
|
+
:message => "class inherits across namespaces",
|
89
|
+
:linenumber => 1,
|
90
|
+
:column => 25,
|
91
|
+
})
|
72
92
|
should_not have_problem :kind => :error
|
73
93
|
}
|
74
94
|
end
|
@@ -83,7 +103,12 @@ describe PuppetLint::Plugins::CheckClasses do
|
|
83
103
|
let(:code) { "class foo($bar='baz', $gronk) { }" }
|
84
104
|
|
85
105
|
its(:problems) {
|
86
|
-
should have_problem
|
106
|
+
should have_problem({
|
107
|
+
:kind => :warning,
|
108
|
+
:message => "optional parameter listed before required parameter",
|
109
|
+
:linenumber => 1,
|
110
|
+
:column => 23,
|
111
|
+
})
|
87
112
|
should_not have_problem :kind => :error
|
88
113
|
}
|
89
114
|
end
|
@@ -98,7 +123,12 @@ describe PuppetLint::Plugins::CheckClasses do
|
|
98
123
|
let(:code) { "define foo($bar='baz', $gronk) { }" }
|
99
124
|
|
100
125
|
its(:problems) {
|
101
|
-
should have_problem
|
126
|
+
should have_problem({
|
127
|
+
:kind => :warning,
|
128
|
+
:message => "optional parameter listed before required parameter",
|
129
|
+
:linenumber => 1,
|
130
|
+
:column => 24,
|
131
|
+
})
|
102
132
|
should_not have_problem :kind => :error
|
103
133
|
}
|
104
134
|
end
|
@@ -111,7 +141,12 @@ describe PuppetLint::Plugins::CheckClasses do
|
|
111
141
|
}
|
112
142
|
|
113
143
|
its(:problems) {
|
114
|
-
should have_problem
|
144
|
+
should have_problem({
|
145
|
+
:kind => :warning,
|
146
|
+
:message => "top-scope variable being used without an explicit namespace",
|
147
|
+
:linenumber => 3,
|
148
|
+
:column => 16,
|
149
|
+
})
|
115
150
|
should_not have_problem :kind => :error
|
116
151
|
}
|
117
152
|
end
|
@@ -155,7 +190,12 @@ describe PuppetLint::Plugins::CheckClasses do
|
|
155
190
|
}
|
156
191
|
|
157
192
|
its(:problems) {
|
158
|
-
should have_problem
|
193
|
+
should have_problem({
|
194
|
+
:kind => :warning,
|
195
|
+
:message => "top-scope variable being used without an explicit namespace",
|
196
|
+
:linenumber => 3,
|
197
|
+
:column => 16,
|
198
|
+
})
|
159
199
|
should_not have_problem :kind => :error
|
160
200
|
}
|
161
201
|
end
|
@@ -223,7 +263,12 @@ describe PuppetLint::Plugins::CheckClasses do
|
|
223
263
|
}
|
224
264
|
|
225
265
|
its(:problems) {
|
226
|
-
should have_problem
|
266
|
+
should have_problem({
|
267
|
+
:kind => :warning,
|
268
|
+
:message => "optional parameter listed before required parameter",
|
269
|
+
:linenumber => 2,
|
270
|
+
:column => 32,
|
271
|
+
})
|
227
272
|
should_not have_problem :kind => :error
|
228
273
|
}
|
229
274
|
end
|
@@ -254,7 +299,12 @@ describe PuppetLint::Plugins::CheckClasses do
|
|
254
299
|
let(:fullpath) { '/etc/puppet/modules/foo/manifests/init.pp' }
|
255
300
|
|
256
301
|
its(:problems) {
|
257
|
-
should only_have_problem
|
302
|
+
should only_have_problem({
|
303
|
+
:kind => :error,
|
304
|
+
:message => "foo::bar not in autoload module layout",
|
305
|
+
:linenumber => 1,
|
306
|
+
:column => 7,
|
307
|
+
})
|
258
308
|
}
|
259
309
|
end
|
260
310
|
|
@@ -269,6 +319,5 @@ describe PuppetLint::Plugins::CheckClasses do
|
|
269
319
|
}
|
270
320
|
let(:fullpath) { '/etc/puppet/modules/bar/manifests/init.pp' }
|
271
321
|
its(:problems) { should be_empty }
|
272
|
-
|
273
322
|
end
|
274
323
|
end
|
@@ -3,7 +3,9 @@ require 'spec_helper'
|
|
3
3
|
describe PuppetLint::Plugins::CheckConditionals do
|
4
4
|
subject do
|
5
5
|
klass = described_class.new
|
6
|
-
|
6
|
+
fileinfo = {}
|
7
|
+
fileinfo[:fullpath] = defined?(fullpath).nil? ? '' : fullpath
|
8
|
+
klass.run(fileinfo, code)
|
7
9
|
klass
|
8
10
|
end
|
9
11
|
|
@@ -17,7 +19,14 @@ describe PuppetLint::Plugins::CheckConditionals do
|
|
17
19
|
}"
|
18
20
|
}
|
19
21
|
|
20
|
-
its(:problems)
|
22
|
+
its(:problems) do
|
23
|
+
should only_have_problem({
|
24
|
+
:kind => :warning,
|
25
|
+
:message => 'selector inside resource block',
|
26
|
+
:linenumber => 3,
|
27
|
+
:column => 16,
|
28
|
+
})
|
29
|
+
end
|
21
30
|
end
|
22
31
|
|
23
32
|
describe 'resource with a variable as a attr value' do
|
@@ -49,6 +58,13 @@ describe PuppetLint::Plugins::CheckConditionals do
|
|
49
58
|
}"
|
50
59
|
}
|
51
60
|
|
52
|
-
its(:problems)
|
61
|
+
its(:problems) do
|
62
|
+
should only_have_problem({
|
63
|
+
:kind => :warning,
|
64
|
+
:message => 'case statement without a default case',
|
65
|
+
:linenumber => 2,
|
66
|
+
:column => 7,
|
67
|
+
})
|
68
|
+
end
|
53
69
|
end
|
54
70
|
end
|
@@ -8,11 +8,10 @@ describe PuppetLint::Plugins::CheckResources do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '3 digit file mode' do
|
11
|
-
let(:code) { "file { 'foo': mode => 777 }" }
|
11
|
+
let(:code) { "file { 'foo': mode => '777' }" }
|
12
12
|
|
13
13
|
its(:problems) {
|
14
|
-
should
|
15
|
-
should_not have_problem :kind => :error
|
14
|
+
should only_have_problem :kind => :warning, :message => "mode should be represented as a 4 digit octal value or symbolic mode", :linenumber => 1
|
16
15
|
}
|
17
16
|
end
|
18
17
|
|
@@ -26,8 +25,7 @@ describe PuppetLint::Plugins::CheckResources do
|
|
26
25
|
let(:code) { "file { 'foo': mode => 0777 }" }
|
27
26
|
|
28
27
|
its(:problems) {
|
29
|
-
should
|
30
|
-
should_not have_problem :kind => :error
|
28
|
+
should only_have_problem :kind => :warning, :message => "unquoted file mode"
|
31
29
|
}
|
32
30
|
end
|
33
31
|
|
@@ -68,8 +66,7 @@ describe PuppetLint::Plugins::CheckResources do
|
|
68
66
|
}
|
69
67
|
|
70
68
|
its(:problems) {
|
71
|
-
should
|
72
|
-
should_not have_problem :kind => :error
|
69
|
+
should only_have_problem :kind => :warning, :message => "ensure found on line but it's not the first attribute", :linenumber => 4
|
73
70
|
}
|
74
71
|
end
|
75
72
|
|
@@ -94,8 +91,7 @@ describe PuppetLint::Plugins::CheckResources do
|
|
94
91
|
let(:code) { "file { foo: }" }
|
95
92
|
|
96
93
|
its(:problems) {
|
97
|
-
should
|
98
|
-
should_not have_problem :kind => :error
|
94
|
+
should only_have_problem :kind => :warning, :message => "unquoted resource title", :linenumber => 1
|
99
95
|
}
|
100
96
|
end
|
101
97
|
|
@@ -115,8 +111,7 @@ describe PuppetLint::Plugins::CheckResources do
|
|
115
111
|
}
|
116
112
|
|
117
113
|
its(:problems) {
|
118
|
-
should
|
119
|
-
should_not have_problem :kind => :error
|
114
|
+
should only_have_problem :kind => :warning, :message => "unquoted resource title", :linenumber => 2
|
120
115
|
}
|
121
116
|
end
|
122
117
|
|
@@ -140,8 +135,7 @@ describe PuppetLint::Plugins::CheckResources do
|
|
140
135
|
}
|
141
136
|
|
142
137
|
its(:problems) {
|
143
|
-
should
|
144
|
-
should_not have_problem :kind => :error
|
138
|
+
should only_have_problem :kind => :warning, :message => "unquoted resource title", :linenumber => 4
|
145
139
|
}
|
146
140
|
end
|
147
141
|
|
@@ -162,7 +156,7 @@ describe PuppetLint::Plugins::CheckResources do
|
|
162
156
|
}"
|
163
157
|
}
|
164
158
|
|
165
|
-
its(:problems) { should
|
159
|
+
its(:problems) { should == [] }
|
166
160
|
end
|
167
161
|
|
168
162
|
describe 'file resource creating a symlink with seperate target attr' do
|
@@ -184,8 +178,7 @@ describe PuppetLint::Plugins::CheckResources do
|
|
184
178
|
}
|
185
179
|
|
186
180
|
its(:problems) {
|
187
|
-
should
|
188
|
-
should_not have_problem :kind => :error
|
181
|
+
should only_have_problem :kind => :warning, :message => "symlink target specified in ensure attr", :linenumber => 3
|
189
182
|
}
|
190
183
|
end
|
191
184
|
end
|
@@ -3,7 +3,9 @@ require 'spec_helper'
|
|
3
3
|
describe PuppetLint::Plugins::CheckStrings do
|
4
4
|
subject do
|
5
5
|
klass = described_class.new
|
6
|
-
|
6
|
+
fileinfo = {}
|
7
|
+
fileinfo[:fullpath] = defined?(fullpath).nil? ? '' : fullpath
|
8
|
+
klass.run(fileinfo, code)
|
7
9
|
klass
|
8
10
|
end
|
9
11
|
|
@@ -17,8 +19,18 @@ describe PuppetLint::Plugins::CheckStrings do
|
|
17
19
|
let(:code) { "\"aoeu\" '${foo}'" }
|
18
20
|
|
19
21
|
its(:problems) {
|
20
|
-
should have_problem
|
21
|
-
|
22
|
+
should have_problem({
|
23
|
+
:kind => :warning,
|
24
|
+
:message => 'double quoted string containing no variables',
|
25
|
+
:linenumber => 1,
|
26
|
+
:column => 1,
|
27
|
+
})
|
28
|
+
should have_problem({
|
29
|
+
:kind => :error,
|
30
|
+
:message => 'single quoted string containing a variable found',
|
31
|
+
:linenumber => 1,
|
32
|
+
:column => 8,
|
33
|
+
})
|
22
34
|
}
|
23
35
|
end
|
24
36
|
|
@@ -26,7 +38,12 @@ describe PuppetLint::Plugins::CheckStrings do
|
|
26
38
|
let(:code) { '"${foo}"' }
|
27
39
|
|
28
40
|
its(:problems) {
|
29
|
-
should only_have_problem
|
41
|
+
should only_have_problem({
|
42
|
+
:kind => :warning,
|
43
|
+
:message => 'string containing only a variable',
|
44
|
+
:linenumber => 1,
|
45
|
+
:column => 3,
|
46
|
+
})
|
30
47
|
}
|
31
48
|
end
|
32
49
|
|
@@ -34,11 +51,29 @@ describe PuppetLint::Plugins::CheckStrings do
|
|
34
51
|
let(:code) { '" $gronk"' }
|
35
52
|
|
36
53
|
its(:problems) {
|
37
|
-
should only_have_problem
|
54
|
+
should only_have_problem({
|
55
|
+
:kind => :warning,
|
56
|
+
:message => 'variable not enclosed in {}',
|
57
|
+
:linenumber => 1,
|
58
|
+
:column => 3,
|
59
|
+
})
|
38
60
|
}
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'variable not enclosed in {} after many tokens' do
|
64
|
+
let(:code) { ("'groovy'\n" * 20) + '" $gronk"' }
|
39
65
|
|
66
|
+
its(:problems) {
|
67
|
+
should only_have_problem({
|
68
|
+
:kind => :warning,
|
69
|
+
:message => 'variable not enclosed in {}',
|
70
|
+
:linenumber => 21,
|
71
|
+
:column => 3,
|
72
|
+
})
|
73
|
+
}
|
40
74
|
end
|
41
75
|
|
76
|
+
|
42
77
|
describe 'double quoted string nested in a single quoted string' do
|
43
78
|
let(:code) { "'grep \"status=sent\" /var/log/mail.log'" }
|
44
79
|
|
@@ -60,12 +95,64 @@ describe PuppetLint::Plugins::CheckStrings do
|
|
60
95
|
describe 'quoted false' do
|
61
96
|
let(:code) { "class { 'foo': boolFlag => 'false' }" }
|
62
97
|
|
63
|
-
its(:problems) {
|
98
|
+
its(:problems) {
|
99
|
+
should only_have_problem({
|
100
|
+
:kind => :warning,
|
101
|
+
:message => 'quoted boolean value found',
|
102
|
+
:linenumber => 1,
|
103
|
+
:column => 28,
|
104
|
+
})
|
105
|
+
}
|
64
106
|
end
|
65
107
|
|
66
108
|
describe 'quoted true' do
|
67
109
|
let(:code) { "class { 'foo': boolFlag => 'true' }" }
|
68
110
|
|
69
|
-
its(:problems) {
|
111
|
+
its(:problems) {
|
112
|
+
should only_have_problem({
|
113
|
+
:kind => :warning,
|
114
|
+
:message => 'quoted boolean value found',
|
115
|
+
:linenumber => 1,
|
116
|
+
:column => 28,
|
117
|
+
})
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
describe 'double quoted true' do
|
122
|
+
let(:code) { "class { 'foo': boolFlag => \"true\" }" }
|
123
|
+
|
124
|
+
its(:problems) {
|
125
|
+
should have_problem({
|
126
|
+
:kind => :warning,
|
127
|
+
:message => 'quoted boolean value found',
|
128
|
+
:linenumber => 1,
|
129
|
+
:column => 28,
|
130
|
+
})
|
131
|
+
should have_problem({
|
132
|
+
:kind => :warning,
|
133
|
+
:message => 'double quoted string containing no variables',
|
134
|
+
:linenumber => 1,
|
135
|
+
:column => 28,
|
136
|
+
})
|
137
|
+
}
|
138
|
+
end
|
139
|
+
|
140
|
+
describe 'double quoted false' do
|
141
|
+
let(:code) { "class { 'foo': boolFlag => \"false\" }" }
|
142
|
+
|
143
|
+
its(:problems) {
|
144
|
+
should have_problem({
|
145
|
+
:kind => :warning,
|
146
|
+
:message => 'quoted boolean value found',
|
147
|
+
:linenumber => 1,
|
148
|
+
:column => 28,
|
149
|
+
})
|
150
|
+
should have_problem({
|
151
|
+
:kind => :warning,
|
152
|
+
:message => 'double quoted string containing no variables',
|
153
|
+
:linenumber => 1,
|
154
|
+
:column => 28,
|
155
|
+
})
|
156
|
+
}
|
70
157
|
end
|
71
158
|
end
|
@@ -3,21 +3,31 @@ require 'spec_helper'
|
|
3
3
|
describe PuppetLint::Plugins::CheckVariables do
|
4
4
|
subject do
|
5
5
|
klass = described_class.new
|
6
|
-
|
6
|
+
fileinfo = {}
|
7
|
+
fileinfo[:fullpath] = defined?(fullpath).nil? ? '' : fullpath
|
8
|
+
klass.run(fileinfo, code)
|
7
9
|
klass
|
8
10
|
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
let(:code) { "$foo-bar" }
|
12
|
+
describe 'a variable containing a dash' do
|
13
|
+
let(:code) { '$foo-bar' }
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
its(:problems) { should have_problem({
|
16
|
+
:kind => :warning,
|
17
|
+
:message => 'variable contains a dash',
|
18
|
+
:linenumber => 1,
|
19
|
+
:column => 1,
|
20
|
+
}) }
|
21
|
+
end
|
16
22
|
|
17
|
-
|
18
|
-
|
23
|
+
describe 'variable containing a dash' do
|
24
|
+
let(:code) { '" $foo-bar"' }
|
19
25
|
|
20
|
-
|
21
|
-
|
26
|
+
its(:problems) { should have_problem({
|
27
|
+
:kind => :warning,
|
28
|
+
:message => 'variable contains a dash',
|
29
|
+
:linenumber => 1,
|
30
|
+
:column => 3,
|
31
|
+
}) }
|
22
32
|
end
|
23
33
|
end
|