puppet-lint 0.4.0.pre1 → 1.0.0
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/.travis.yml +3 -4
- data/Gemfile +2 -5
- data/README.md +2 -149
- data/Rakefile +0 -5
- data/lib/puppet-lint.rb +74 -20
- data/lib/puppet-lint/bin.rb +20 -85
- data/lib/puppet-lint/checkplugin.rb +158 -12
- data/lib/puppet-lint/checks.rb +39 -222
- data/lib/puppet-lint/configuration.rb +12 -31
- data/lib/puppet-lint/data.rb +329 -0
- data/lib/puppet-lint/lexer.rb +37 -30
- data/lib/puppet-lint/lexer/token.rb +14 -16
- data/lib/puppet-lint/monkeypatches/string_prepend.rb +6 -0
- data/lib/puppet-lint/optparser.rb +105 -0
- data/lib/puppet-lint/plugins.rb +28 -9
- data/lib/puppet-lint/plugins/check_classes.rb +162 -238
- data/lib/puppet-lint/plugins/check_comments.rb +40 -25
- data/lib/puppet-lint/plugins/check_conditionals.rb +16 -20
- data/lib/puppet-lint/plugins/check_documentation.rb +14 -20
- data/lib/puppet-lint/plugins/check_nodes.rb +23 -0
- data/lib/puppet-lint/plugins/check_resources.rb +127 -141
- data/lib/puppet-lint/plugins/check_strings.rb +133 -107
- data/lib/puppet-lint/plugins/check_variables.rb +11 -11
- data/lib/puppet-lint/plugins/check_whitespace.rb +86 -92
- data/lib/puppet-lint/tasks/puppet-lint.rb +17 -1
- data/lib/puppet-lint/version.rb +1 -1
- data/puppet-lint.gemspec +4 -2
- data/spec/fixtures/test/manifests/ignore.pp +1 -0
- data/spec/fixtures/test/manifests/ignore_reason.pp +1 -0
- data/spec/puppet-lint/bin_spec.rb +104 -84
- data/spec/puppet-lint/configuration_spec.rb +19 -19
- data/spec/puppet-lint/ignore_overrides_spec.rb +97 -0
- data/spec/puppet-lint/lexer/token_spec.rb +9 -9
- data/spec/puppet-lint/lexer_spec.rb +352 -325
- data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +77 -23
- data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +14 -12
- data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +18 -14
- data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +30 -30
- data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +31 -26
- data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +34 -28
- data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +14 -12
- data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +74 -30
- data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +27 -20
- data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +78 -13
- data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +17 -12
- data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +13 -10
- data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +21 -16
- data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +69 -0
- data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +42 -38
- data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +22 -10
- data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +81 -18
- data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +69 -112
- data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +27 -20
- data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +177 -171
- data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +165 -88
- data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +97 -22
- data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +25 -0
- data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +97 -111
- data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +10 -9
- data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +53 -53
- data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +26 -14
- data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +10 -9
- data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +31 -15
- data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +340 -322
- data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +30 -23
- data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +42 -41
- data/spec/puppet-lint_spec.rb +3 -3
- data/spec/spec_helper.rb +109 -116
- metadata +109 -50
- data/spec/puppet-lint/plugins/check_classes/class_parameter_defaults_spec.rb +0 -60
@@ -1,20 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'unquoted_file_mode' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
let(:msg) { 'unquoted file mode' }
|
5
|
+
|
6
|
+
context 'with fix disabled' do
|
7
|
+
context '4 digit unquoted file mode' do
|
8
|
+
let(:code) { "file { 'foo': mode => 0777 }" }
|
9
|
+
|
10
|
+
it 'should only detect a single problem' do
|
11
|
+
expect(problems).to have(1).problem
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should create a warning' do
|
15
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(23)
|
16
|
+
end
|
14
17
|
end
|
15
18
|
end
|
16
19
|
|
17
|
-
|
20
|
+
context 'with fix enabled' do
|
18
21
|
before do
|
19
22
|
PuppetLint.configuration.fix = true
|
20
23
|
end
|
@@ -23,16 +26,20 @@ describe 'unquoted_file_mode' do
|
|
23
26
|
PuppetLint.configuration.fix = false
|
24
27
|
end
|
25
28
|
|
26
|
-
|
29
|
+
context '4 digit unquoted file mode w/fix' do
|
30
|
+
let(:code) { "file { 'foo': mode => 0777 }" }
|
31
|
+
|
32
|
+
it 'should only detect a single problem' do
|
33
|
+
expect(problems).to have(1).problem
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should fix the manifest' do
|
37
|
+
expect(problems).to contain_fixed(msg).on_line(1).in_column(23)
|
38
|
+
end
|
27
39
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
:message => "unquoted file mode",
|
32
|
-
:linenumber => 1,
|
33
|
-
:column => 23,
|
34
|
-
)
|
40
|
+
it 'should single quote the file mode' do
|
41
|
+
expect(manifest).to eq("file { 'foo': mode => '0777' }")
|
42
|
+
end
|
35
43
|
end
|
36
|
-
its(:manifest) { should == "file { 'foo': mode => '0777' }" }
|
37
44
|
end
|
38
45
|
end
|
@@ -1,132 +1,144 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'unquoted_resource_title' do
|
4
|
-
|
5
|
-
let(:code) { "file { 'foo': }" }
|
4
|
+
let(:msg) { 'unquoted resource title' }
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
describe 'unquoted resource title on single line resource' do
|
11
|
-
let(:code) { "file { foo: }" }
|
12
|
-
|
13
|
-
its(:problems) {
|
14
|
-
should only_have_problem(
|
15
|
-
:kind => :warning,
|
16
|
-
:message => "unquoted resource title",
|
17
|
-
:linenumber => 1,
|
18
|
-
:column => 8,
|
19
|
-
)
|
20
|
-
}
|
21
|
-
end
|
6
|
+
context 'with fix disabled' do
|
7
|
+
context 'quoted resource title on single line resource' do
|
8
|
+
let(:code) { "file { 'foo': }" }
|
22
9
|
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
it 'should not detect any problems' do
|
11
|
+
expect(problems).to have(0).problems
|
12
|
+
end
|
26
13
|
end
|
27
14
|
|
28
|
-
|
29
|
-
|
15
|
+
context 'unquoted resource title on single line resource' do
|
16
|
+
let(:code) { "file { foo: }" }
|
17
|
+
|
18
|
+
it 'should only detect a single problem' do
|
19
|
+
expect(problems).to have(1).problem
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should create a warning' do
|
23
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(8)
|
24
|
+
end
|
30
25
|
end
|
31
26
|
|
32
|
-
|
27
|
+
context 'quoted resource title on multi line resource' do
|
28
|
+
let(:code) { "
|
29
|
+
file { 'foo':
|
30
|
+
}"
|
31
|
+
}
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
:linenumber => 1,
|
39
|
-
:column => 8,
|
40
|
-
)
|
41
|
-
}
|
33
|
+
it 'should not detect any problems' do
|
34
|
+
expect(problems).to have(0).problems
|
35
|
+
end
|
36
|
+
end
|
42
37
|
|
43
|
-
|
44
|
-
|
38
|
+
context 'unquoted resource title on multi line resource' do
|
39
|
+
let(:code) { "
|
40
|
+
file { foo:
|
41
|
+
}"
|
42
|
+
}
|
45
43
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
}"
|
50
|
-
}
|
44
|
+
it 'should only detect a single problem' do
|
45
|
+
expect(problems).to have(1).problem
|
46
|
+
end
|
51
47
|
|
52
|
-
|
53
|
-
|
48
|
+
it 'should create a warning' do
|
49
|
+
expect(problems).to contain_warning(msg).on_line(2).in_column(16)
|
50
|
+
end
|
51
|
+
end
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
)
|
68
|
-
}
|
69
|
-
end
|
53
|
+
context 'condensed resources with quoted titles' do
|
54
|
+
let(:code) { "
|
55
|
+
file {
|
56
|
+
'foo': ;
|
57
|
+
'bar': ;
|
58
|
+
}"
|
59
|
+
}
|
60
|
+
|
61
|
+
it 'should not detect any problems' do
|
62
|
+
expect(problems).to have(0).problems
|
63
|
+
end
|
64
|
+
end
|
70
65
|
|
71
|
-
|
72
|
-
|
73
|
-
|
66
|
+
context 'condensed resources with an unquoted title' do
|
67
|
+
let(:code) { "
|
68
|
+
file {
|
69
|
+
'foo': ;
|
70
|
+
bar: ;
|
71
|
+
}"
|
72
|
+
}
|
73
|
+
|
74
|
+
it 'should only detect a single problem' do
|
75
|
+
expect(problems).to have(1).problem
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should create a warning' do
|
79
|
+
expect(problems).to contain_warning(msg).on_line(4).in_column(11)
|
80
|
+
end
|
74
81
|
end
|
75
82
|
|
76
|
-
|
77
|
-
|
83
|
+
context 'single line resource with an array of titles (all quoted)' do
|
84
|
+
let(:code) { "file { ['foo', 'bar']: }" }
|
85
|
+
|
86
|
+
it 'should not detect any problems' do
|
87
|
+
expect(problems).to have(0).problems
|
88
|
+
end
|
78
89
|
end
|
79
90
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
:column => 14,
|
91
|
-
)
|
92
|
-
}
|
93
|
-
|
94
|
-
its(:manifest) { should == "
|
95
|
-
file { 'foo':
|
96
|
-
}"
|
97
|
-
}
|
98
|
-
end
|
91
|
+
context 'resource inside a case statement' do
|
92
|
+
let(:code) { "
|
93
|
+
case $ensure {
|
94
|
+
'absent': {
|
95
|
+
file { \"some_file_${name}\":
|
96
|
+
ensure => absent,
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}"
|
100
|
+
}
|
99
101
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
'bar': ;
|
105
|
-
}"
|
106
|
-
}
|
102
|
+
it 'should not detect any problems' do
|
103
|
+
expect(problems).to have(0).problems
|
104
|
+
end
|
105
|
+
end
|
107
106
|
|
108
|
-
|
109
|
-
|
107
|
+
context 'issue #116' do
|
108
|
+
let(:code) { "
|
109
|
+
$config_file_init = $::operatingsystem ? {
|
110
|
+
/(?i:Debian|Ubuntu|Mint)/ => '/etc/default/foo',
|
111
|
+
default => '/etc/sysconfig/foo',
|
112
|
+
}"
|
113
|
+
}
|
114
|
+
|
115
|
+
it 'should not detect any problems' do
|
116
|
+
expect(problems).to have(0).problems
|
117
|
+
end
|
118
|
+
end
|
110
119
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
120
|
+
context 'case statement' do
|
121
|
+
let(:code) { %{
|
122
|
+
case $operatingsystem {
|
123
|
+
centos: {
|
124
|
+
$version = '1.2.3'
|
125
|
+
}
|
126
|
+
solaris: {
|
127
|
+
$version = '3.2.1'
|
128
|
+
}
|
129
|
+
default: {
|
130
|
+
fail("Module ${module_name} is not supported on ${operatingsystem}")
|
131
|
+
}
|
132
|
+
}}
|
133
|
+
}
|
134
|
+
|
135
|
+
it 'should not detect any problems' do
|
136
|
+
expect(problems).to have(0).problems
|
137
|
+
end
|
138
|
+
end
|
127
139
|
end
|
128
140
|
|
129
|
-
|
141
|
+
context 'with fix enabled' do
|
130
142
|
before do
|
131
143
|
PuppetLint.configuration.fix = true
|
132
144
|
end
|
@@ -135,76 +147,70 @@ describe 'unquoted_resource_title' do
|
|
135
147
|
PuppetLint.configuration.fix = false
|
136
148
|
end
|
137
149
|
|
138
|
-
|
139
|
-
file {
|
140
|
-
'foo': ;
|
141
|
-
bar: ;
|
142
|
-
}"
|
143
|
-
}
|
144
|
-
|
145
|
-
its(:problems) {
|
146
|
-
should only_have_problem(
|
147
|
-
:kind => :fixed,
|
148
|
-
:message => "unquoted resource title",
|
149
|
-
:linenumber => 4,
|
150
|
-
:column => 9,
|
151
|
-
)
|
152
|
-
}
|
153
|
-
|
154
|
-
its(:manifest) { should == "
|
155
|
-
file {
|
156
|
-
'foo': ;
|
157
|
-
'bar': ;
|
158
|
-
}"
|
159
|
-
}
|
160
|
-
end
|
161
|
-
|
162
|
-
describe 'single line resource with an array of titles (all quoted)' do
|
163
|
-
let(:code) { "file { ['foo', 'bar']: }" }
|
150
|
+
context 'unquoted resource title on single line resource' do
|
151
|
+
let(:code) { "file { foo: }" }
|
164
152
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
describe 'resource inside a case statement' do
|
169
|
-
let(:code) { "
|
170
|
-
case $ensure {
|
171
|
-
'absent': {
|
172
|
-
file { \"some_file_${name}\":
|
173
|
-
ensure => absent,
|
174
|
-
}
|
175
|
-
}
|
176
|
-
}"
|
177
|
-
}
|
153
|
+
it 'should only detect a single problem' do
|
154
|
+
expect(problems).to have(1).problem
|
155
|
+
end
|
178
156
|
|
179
|
-
|
180
|
-
|
157
|
+
it 'should fix the manifest' do
|
158
|
+
expect(problems).to contain_fixed(msg).on_line(1).in_column(8)
|
159
|
+
end
|
181
160
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
default => '/etc/sysconfig/foo',
|
187
|
-
}"
|
188
|
-
}
|
161
|
+
it 'should single quote the resource title' do
|
162
|
+
expect(manifest).to eq("file { 'foo': }")
|
163
|
+
end
|
164
|
+
end
|
189
165
|
|
190
|
-
|
191
|
-
|
166
|
+
context 'unquoted resource title on multi line resource' do
|
167
|
+
let(:code) { "
|
168
|
+
file { foo:
|
169
|
+
}"
|
170
|
+
}
|
171
|
+
let(:fixed) { "
|
172
|
+
file { 'foo':
|
173
|
+
}"
|
174
|
+
}
|
175
|
+
|
176
|
+
it 'should only detect a single problem' do
|
177
|
+
expect(problems).to have(1).problem
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'should fix the manifest' do
|
181
|
+
expect(problems).to contain_fixed(msg).on_line(2).in_column(16)
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should single quote the resource title' do
|
185
|
+
expect(manifest).to eq(fixed)
|
186
|
+
end
|
187
|
+
end
|
192
188
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
}
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
}
|
205
|
-
}
|
206
|
-
|
207
|
-
|
208
|
-
|
189
|
+
context 'condensed resources with an unquoted title' do
|
190
|
+
let(:code) { "
|
191
|
+
file {
|
192
|
+
'foo': ;
|
193
|
+
bar: ;
|
194
|
+
}"
|
195
|
+
}
|
196
|
+
let(:fixed) { "
|
197
|
+
file {
|
198
|
+
'foo': ;
|
199
|
+
'bar': ;
|
200
|
+
}"
|
201
|
+
}
|
202
|
+
|
203
|
+
it 'should only detect a single problem' do
|
204
|
+
expect(problems).to have(1).problem
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'should fix the manifest' do
|
208
|
+
expect(problems).to contain_fixed(msg).on_line(4).in_column(11)
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'should single quote the resource title' do
|
212
|
+
expect(manifest).to eq(fixed)
|
213
|
+
end
|
214
|
+
end
|
209
215
|
end
|
210
216
|
end
|
@@ -1,43 +1,141 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'double_quoted_strings' do
|
4
|
-
|
5
|
-
let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" }
|
4
|
+
let(:msg) { 'double quoted string containing no variables' }
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
context 'with fix disabled' do
|
7
|
+
context 'double quoted string containing a variable inside single quotes' do
|
8
|
+
let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" }
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
it 'should not detect any problems' do
|
11
|
+
expect(problems).to have(0).problems
|
12
|
+
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
context 'multiple strings in a line' do
|
16
|
+
let(:code) { "\"aoeu\" '${foo}'" }
|
17
|
+
|
18
|
+
it 'should only detect a single problem' do
|
19
|
+
expect(problems).to have(1).problem
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should create a warning' do
|
23
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(1)
|
24
|
+
end
|
17
25
|
end
|
18
26
|
|
19
|
-
|
27
|
+
context 'double quoted string nested in a single quoted string' do
|
28
|
+
let(:code) { "'grep \"status=sent\" /var/log/mail.log'" }
|
20
29
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
30
|
+
it 'should not detect any problems' do
|
31
|
+
expect(problems).to have(0).problems
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'double quoted string after a comment' do
|
36
|
+
let(:code) { "service { 'foo': } # \"bar\"" }
|
37
|
+
|
38
|
+
it 'should not detect any problems' do
|
39
|
+
expect(problems).to have(0).problems
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'double quoted string containing newline but no variables' do
|
44
|
+
let(:code) { %{"foo\n"} }
|
45
|
+
|
46
|
+
it 'should not detect any problems' do
|
47
|
+
expect(problems).to have(0).problems
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'double quoted string with backslash for continuation' do
|
52
|
+
let(:code) { %{
|
53
|
+
class puppet::master::maintenance (
|
54
|
+
) {
|
55
|
+
cron { 'puppet_master_reports_cleanup':
|
56
|
+
command => "/usr/bin/find /var/lib/puppet/reports -type f -mtime +15 \
|
57
|
+
-delete && /usr/bin/find /var/lib/puppet/reports -mindepth 1 \
|
58
|
+
-empty -type d -delete",
|
59
|
+
minute => '15',
|
60
|
+
hour => '5',
|
61
|
+
}
|
62
|
+
}
|
63
|
+
} }
|
64
|
+
|
65
|
+
it 'should not detect any problems' do
|
66
|
+
expect(problems).to have(0).problems
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'double quoted true' do
|
71
|
+
let(:code) { "class { 'foo': boolFlag => \"true\" }" }
|
72
|
+
|
73
|
+
it 'should only detect a single problem' do
|
74
|
+
expect(problems).to have(1).problem
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should create a warning' do
|
78
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(28)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'double quoted false' do
|
83
|
+
let(:code) { "class { 'foo': boolFlag => \"false\" }" }
|
84
|
+
|
85
|
+
it 'should only detect a single problem' do
|
86
|
+
expect(problems).to have(1).problem
|
87
|
+
end
|
26
88
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
89
|
+
it 'should create a warning' do
|
90
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(28)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'double quoted stings containing supported escape patterns' do
|
95
|
+
let(:code) {%{
|
96
|
+
$string1 = "this string contins \n newline"
|
97
|
+
$string2 = "this string contains \ttab"
|
98
|
+
$string3 = "this string contains \${escaped} var"
|
99
|
+
$string4 = "this string contains \\"escaped \\" double quotes"
|
100
|
+
$string5 = "this string contains \\'escaped \\' single quotes"
|
101
|
+
$string6 = "this string contains \r line return"
|
102
|
+
}}
|
103
|
+
|
104
|
+
it 'should not detect any problems' do
|
105
|
+
expect(problems).to have(0).problems
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'double quoted string with random escape should be rejected' do
|
110
|
+
let(:code) {%{ $ztring = "this string contains \l random esape" } }
|
111
|
+
|
112
|
+
it 'should only detect a single problem' do
|
113
|
+
expect(problems).to have(1).problem
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should create a warning' do
|
117
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(12)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'single quotes in a double quoted string' do
|
122
|
+
let(:code) { "\"this 'string' 'has' lots of 'quotes'\"" }
|
123
|
+
|
124
|
+
it 'should not detect any problems' do
|
125
|
+
expect(problems).to have(0).problems
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'double quoted string containing single quoted string' do
|
130
|
+
let(:code) { %[notify { "'foo'": }] }
|
131
|
+
|
132
|
+
it 'should not detect any problems' do
|
133
|
+
expect(problems).to have(0).problems
|
134
|
+
end
|
135
|
+
end
|
38
136
|
end
|
39
137
|
|
40
|
-
|
138
|
+
context 'with fix enabled' do
|
41
139
|
before do
|
42
140
|
PuppetLint.configuration.fix = true
|
43
141
|
end
|
@@ -46,77 +144,56 @@ describe 'double_quoted_strings' do
|
|
46
144
|
PuppetLint.configuration.fix = false
|
47
145
|
end
|
48
146
|
|
49
|
-
|
147
|
+
context 'double quoted string containing a variable inside single quotes' do
|
148
|
+
let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" }
|
50
149
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
:message => 'double quoted string containing no variables',
|
55
|
-
:linenumber => 1,
|
56
|
-
:column => 1,
|
57
|
-
})
|
58
|
-
}
|
59
|
-
its(:manifest) { should == "'aoeu' '${foo}'" }
|
60
|
-
end
|
150
|
+
it 'should not detect any problems' do
|
151
|
+
expect(problems).to have(0).problems
|
152
|
+
end
|
61
153
|
|
62
|
-
|
63
|
-
|
154
|
+
it 'should not modify the manifest' do
|
155
|
+
expect(manifest).to eq(code)
|
156
|
+
end
|
157
|
+
end
|
64
158
|
|
65
|
-
|
66
|
-
|
159
|
+
context 'double quoted string containing a lone dollar' do
|
160
|
+
let(:code) {"\"sed -i 's/^;*[[:space:]]*${name}[[:space:]]*=.*$/${name} = ${value}/g' file\"" }
|
67
161
|
|
68
|
-
|
69
|
-
|
162
|
+
it 'should not detect any problems' do
|
163
|
+
expect(problems).to have(0).problems
|
164
|
+
end
|
70
165
|
|
71
|
-
|
72
|
-
|
166
|
+
it 'should not modify the manifest' do
|
167
|
+
expect(manifest).to eq(code)
|
168
|
+
end
|
169
|
+
end
|
73
170
|
|
74
|
-
|
75
|
-
|
171
|
+
context 'multiple strings in a line' do
|
172
|
+
let(:code) { "\"aoeu\" '${foo}'" }
|
76
173
|
|
77
|
-
|
78
|
-
|
174
|
+
it 'should only detect a single problem' do
|
175
|
+
expect(problems).to have(1).problem
|
176
|
+
end
|
79
177
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
) {
|
84
|
-
cron { 'puppet_master_reports_cleanup':
|
85
|
-
command => "/usr/bin/find /var/lib/puppet/reports -type f -mtime +15 \
|
86
|
-
-delete && /usr/bin/find /var/lib/puppet/reports -mindepth 1 \
|
87
|
-
-empty -type d -delete",
|
88
|
-
minute => '15',
|
89
|
-
hour => '5',
|
90
|
-
}
|
91
|
-
}
|
92
|
-
} }
|
178
|
+
it 'should fix the manifest' do
|
179
|
+
expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
|
180
|
+
end
|
93
181
|
|
94
|
-
|
95
|
-
|
182
|
+
it 'should convert the double quoted string into single quotes' do
|
183
|
+
expect(manifest).to eq("'aoeu' '${foo}'")
|
184
|
+
end
|
185
|
+
end
|
96
186
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
:message => 'double quoted string containing no variables',
|
104
|
-
:linenumber => 1,
|
105
|
-
:column => 28,
|
106
|
-
})
|
107
|
-
}
|
108
|
-
end
|
187
|
+
context 'single quotes in a double quoted string' do
|
188
|
+
let(:code) { "\"this 'string' 'has' lots of 'quotes'\"" }
|
189
|
+
|
190
|
+
it 'should not detect any problems' do
|
191
|
+
expect(problems).to have(0).problems
|
192
|
+
end
|
109
193
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
should have_problem({
|
115
|
-
:kind => :warning,
|
116
|
-
:message => 'double quoted string containing no variables',
|
117
|
-
:linenumber => 1,
|
118
|
-
:column => 28,
|
119
|
-
})
|
120
|
-
}
|
194
|
+
it 'should not modify the manifest' do
|
195
|
+
expect(manifest).to eq(code)
|
196
|
+
end
|
197
|
+
end
|
121
198
|
end
|
122
199
|
end
|