puppet-lint-halyard 1.1.0.1
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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +10 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +210 -0
- data/Rakefile +14 -0
- data/bin/puppet-lint +7 -0
- data/lib/puppet-lint.rb +214 -0
- data/lib/puppet-lint/bin.rb +79 -0
- data/lib/puppet-lint/checkplugin.rb +176 -0
- data/lib/puppet-lint/checks.rb +91 -0
- data/lib/puppet-lint/configuration.rb +153 -0
- data/lib/puppet-lint/data.rb +521 -0
- data/lib/puppet-lint/lexer.rb +373 -0
- data/lib/puppet-lint/lexer/token.rb +101 -0
- data/lib/puppet-lint/monkeypatches.rb +2 -0
- data/lib/puppet-lint/monkeypatches/string_percent.rb +52 -0
- data/lib/puppet-lint/monkeypatches/string_prepend.rb +13 -0
- data/lib/puppet-lint/optparser.rb +118 -0
- data/lib/puppet-lint/plugins.rb +74 -0
- data/lib/puppet-lint/plugins/check_classes.rb +285 -0
- data/lib/puppet-lint/plugins/check_comments.rb +55 -0
- data/lib/puppet-lint/plugins/check_conditionals.rb +65 -0
- data/lib/puppet-lint/plugins/check_documentation.rb +31 -0
- data/lib/puppet-lint/plugins/check_nodes.rb +29 -0
- data/lib/puppet-lint/plugins/check_resources.rb +194 -0
- data/lib/puppet-lint/plugins/check_strings.rb +174 -0
- data/lib/puppet-lint/plugins/check_variables.rb +19 -0
- data/lib/puppet-lint/plugins/check_whitespace.rb +170 -0
- data/lib/puppet-lint/tasks/puppet-lint.rb +91 -0
- data/lib/puppet-lint/version.rb +3 -0
- data/puppet-lint.gemspec +24 -0
- data/spec/fixtures/test/manifests/fail.pp +2 -0
- data/spec/fixtures/test/manifests/ignore.pp +1 -0
- data/spec/fixtures/test/manifests/ignore_multiple_block.pp +6 -0
- data/spec/fixtures/test/manifests/ignore_multiple_line.pp +2 -0
- data/spec/fixtures/test/manifests/ignore_reason.pp +1 -0
- data/spec/fixtures/test/manifests/init.pp +3 -0
- data/spec/fixtures/test/manifests/malformed.pp +1 -0
- data/spec/fixtures/test/manifests/url_interpolation.pp +12 -0
- data/spec/fixtures/test/manifests/warning.pp +2 -0
- data/spec/puppet-lint/bin_spec.rb +326 -0
- data/spec/puppet-lint/configuration_spec.rb +56 -0
- data/spec/puppet-lint/ignore_overrides_spec.rb +109 -0
- data/spec/puppet-lint/lexer/token_spec.rb +18 -0
- data/spec/puppet-lint/lexer_spec.rb +783 -0
- data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +105 -0
- data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +35 -0
- data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +33 -0
- data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +45 -0
- data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +76 -0
- data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +73 -0
- data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +25 -0
- data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +196 -0
- data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +45 -0
- data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +84 -0
- data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +98 -0
- data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +36 -0
- data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +52 -0
- data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +146 -0
- data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +100 -0
- data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +55 -0
- data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +89 -0
- data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +113 -0
- data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +45 -0
- data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +216 -0
- data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +199 -0
- data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +114 -0
- data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +62 -0
- data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +129 -0
- data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +17 -0
- data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +73 -0
- data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +37 -0
- data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +21 -0
- data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +54 -0
- data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +524 -0
- data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +45 -0
- data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +101 -0
- data/spec/puppet-lint_spec.rb +20 -0
- data/spec/spec_helper.rb +129 -0
- metadata +229 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'single_quote_string_with_variables' do
|
4
|
+
let(:msg) { 'single quoted string containing a variable found' }
|
5
|
+
|
6
|
+
context 'multiple strings in a line' do
|
7
|
+
let(:code) { "\"aoeu\" '${foo}'" }
|
8
|
+
|
9
|
+
it 'should only detect a single problem' do
|
10
|
+
expect(problems).to have(1).problem
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should create an error' do
|
14
|
+
expect(problems).to contain_error(msg).on_line(1).in_column(8)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'variables_not_enclosed' do
|
4
|
+
let(:msg) { 'variable not enclosed in {}' }
|
5
|
+
|
6
|
+
context 'with fix disabled' do
|
7
|
+
context 'variable not enclosed in {}' do
|
8
|
+
let(:code) { '" $gronk"' }
|
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(3)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'variable not enclosed in {} after many tokens' do
|
20
|
+
let(:code) { ("'groovy'\n" * 20) + '" $gronk"' }
|
21
|
+
|
22
|
+
it 'should only detect a single problem' do
|
23
|
+
expect(problems).to have(1).problem
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should create a warning' do
|
27
|
+
expect(problems).to contain_warning(msg).on_line(21).in_column(3)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with fix enabled' do
|
33
|
+
before do
|
34
|
+
PuppetLint.configuration.fix = true
|
35
|
+
end
|
36
|
+
|
37
|
+
after do
|
38
|
+
PuppetLint.configuration.fix = false
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'variable not enclosed in {}' do
|
42
|
+
let(:code) { '" $gronk"' }
|
43
|
+
|
44
|
+
it 'should only detect a single problem' do
|
45
|
+
expect(problems).to have(1).problem
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should fix the manifest' do
|
49
|
+
expect(problems).to contain_fixed(msg).on_line(1).in_column(3)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should enclose the variable in braces' do
|
53
|
+
expect(manifest).to eq('" ${gronk}"')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'variable not enclosed in {} after many tokens' do
|
58
|
+
let(:code) { ("'groovy'\n" * 20) + '" $gronk"' }
|
59
|
+
|
60
|
+
it 'should only detect a single problem' do
|
61
|
+
expect(problems).to have(1).problem
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should fix the manifest' do
|
65
|
+
expect(problems).to contain_fixed(msg).on_line(21).in_column(3)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should enclose the variable in braces' do
|
69
|
+
expect(manifest).to eq(("'groovy'\n" * 20) + '" ${gronk}"')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'variable_contains_dash' do
|
4
|
+
let(:msg) { 'variable contains a dash' }
|
5
|
+
|
6
|
+
context 'a variable containing a dash' do
|
7
|
+
let(:code) { '$foo-bar' }
|
8
|
+
|
9
|
+
it 'should only detect a single problem' do
|
10
|
+
expect(problems).to have(1).problem
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should create a warning' do
|
14
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'variable containing a dash' do
|
19
|
+
let(:code) { '" $foo-bar"' }
|
20
|
+
|
21
|
+
it 'should only detect a single problem' do
|
22
|
+
expect(problems).to have(1).problem
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should create a warning' do
|
26
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(3)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'variable with an array reference containing a dash' do
|
31
|
+
let(:code) { "$foo[bar-baz]" }
|
32
|
+
|
33
|
+
it 'should not detect any problems' do
|
34
|
+
expect(problems).to be_empty
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '2sp_soft_tabs' do
|
4
|
+
let(:msg) { 'two-space soft tabs not used' }
|
5
|
+
|
6
|
+
context 'when a line is indented by 3 spaces' do
|
7
|
+
let(:code) { "
|
8
|
+
file { 'foo':
|
9
|
+
foo => bar,
|
10
|
+
}"
|
11
|
+
}
|
12
|
+
|
13
|
+
it 'should only detect a single problem' do
|
14
|
+
expect(problems).to have(1).problem
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should create an error' do
|
18
|
+
expect(problems).to contain_error(msg).on_line(3).in_column(1)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe '80chars' do
|
5
|
+
let(:msg) { 'line has more than 80 characters' }
|
6
|
+
|
7
|
+
context 'file resource with a source line > 80c' do
|
8
|
+
let(:code) { "
|
9
|
+
file {
|
10
|
+
source => 'puppet:///modules/certificates/etc/ssl/private/wildcard.example.com.crt',
|
11
|
+
}"
|
12
|
+
}
|
13
|
+
|
14
|
+
it 'should not detect any problems' do
|
15
|
+
expect(problems).to have(0).problems
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'file resource with a template line > 80c' do
|
20
|
+
let(:code) { "
|
21
|
+
file {
|
22
|
+
content => template('mymodule/this/is/a/truely/absurdly/long/path/that/should/make/you/feel/bad'),
|
23
|
+
}"
|
24
|
+
}
|
25
|
+
|
26
|
+
it 'should not detect any problems' do
|
27
|
+
expect(problems).to have(0).problems
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'length of lines with UTF-8 characters' do
|
32
|
+
let(:code) { "
|
33
|
+
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
34
|
+
# ┃ Configuration ┃
|
35
|
+
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
|
36
|
+
}
|
37
|
+
|
38
|
+
it 'should not detect any problems' do
|
39
|
+
expect(problems).to have(0).problems
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context '81 character line' do
|
44
|
+
let(:code) { 'a' * 81 }
|
45
|
+
|
46
|
+
it 'should only detect a single problem' do
|
47
|
+
expect(problems).to have(1).problem
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should create a warning' do
|
51
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(80)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,524 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'arrow_alignment' do
|
4
|
+
let(:msg) { 'indentation of => is not properly aligned' }
|
5
|
+
|
6
|
+
context 'with fix disabled' do
|
7
|
+
context 'selectors inside a resource' do
|
8
|
+
let(:code) { "
|
9
|
+
file { 'foo':
|
10
|
+
ensure => $ensure,
|
11
|
+
require => $ensure ? {
|
12
|
+
present => Class['tomcat::install'],
|
13
|
+
absent => undef;
|
14
|
+
},
|
15
|
+
foo => bar,
|
16
|
+
}"
|
17
|
+
}
|
18
|
+
|
19
|
+
it 'should not detect any problems' do
|
20
|
+
expect(problems).to have(0).problems
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'selectors in the middle of a resource' do
|
25
|
+
let(:code) { "
|
26
|
+
file { 'foo':
|
27
|
+
ensure => $ensure ? {
|
28
|
+
present => directory,
|
29
|
+
absent => undef,
|
30
|
+
},
|
31
|
+
owner => 'tomcat6',
|
32
|
+
}"
|
33
|
+
}
|
34
|
+
|
35
|
+
it 'should not detect any problems' do
|
36
|
+
expect(problems).to have(0).problems
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'selector inside a resource' do
|
41
|
+
let(:code) { "
|
42
|
+
ensure => $ensure ? {
|
43
|
+
present => directory,
|
44
|
+
absent => undef,
|
45
|
+
},
|
46
|
+
owner => 'foo4',
|
47
|
+
group => 'foo4',
|
48
|
+
mode => '0755'," }
|
49
|
+
|
50
|
+
it 'should not detect any problems' do
|
51
|
+
expect(problems).to have(0).problems
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'selector inside a hash inside a resource' do
|
56
|
+
let(:code) { "
|
57
|
+
server => {
|
58
|
+
ensure => ensure => $ensure ? {
|
59
|
+
present => directory,
|
60
|
+
absent => undef,
|
61
|
+
},
|
62
|
+
ip => '192.168.1.1'
|
63
|
+
},
|
64
|
+
owner => 'foo4',
|
65
|
+
group => 'foo4',
|
66
|
+
mode => '0755'," }
|
67
|
+
|
68
|
+
it 'should not detect any problems' do
|
69
|
+
expect(problems).to have(0).problems
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'nested hashes with correct indentation' do
|
74
|
+
let(:code) { "
|
75
|
+
class { 'lvs::base':
|
76
|
+
virtualeservers => {
|
77
|
+
'192.168.2.13' => {
|
78
|
+
vport => '11025',
|
79
|
+
service => 'smtp',
|
80
|
+
scheduler => 'wlc',
|
81
|
+
protocol => 'tcp',
|
82
|
+
checktype => 'external',
|
83
|
+
checkcommand => '/path/to/checkscript',
|
84
|
+
real_servers => {
|
85
|
+
'server01' => {
|
86
|
+
real_server => '192.168.2.14',
|
87
|
+
real_port => '25',
|
88
|
+
forwarding => 'masq',
|
89
|
+
},
|
90
|
+
'server02' => {
|
91
|
+
real_server => '192.168.2.15',
|
92
|
+
real_port => '25',
|
93
|
+
forwarding => 'masq',
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}"
|
99
|
+
}
|
100
|
+
|
101
|
+
it 'should not detect any problems' do
|
102
|
+
expect(problems).to have(0).problems
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'single resource with a misaligned =>' do
|
107
|
+
let(:code) { "
|
108
|
+
file { '/tmp/foo':
|
109
|
+
foo => 1,
|
110
|
+
bar => 2,
|
111
|
+
gronk => 3,
|
112
|
+
baz => 4,
|
113
|
+
meh => 5,
|
114
|
+
}"
|
115
|
+
}
|
116
|
+
|
117
|
+
it 'should detect four problems' do
|
118
|
+
expect(problems).to have(4).problems
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should create four warnings' do
|
122
|
+
expect(problems).to contain_warning(msg).on_line(3).in_column(15)
|
123
|
+
expect(problems).to contain_warning(msg).on_line(4).in_column(15)
|
124
|
+
expect(problems).to contain_warning(msg).on_line(6).in_column(16)
|
125
|
+
expect(problems).to contain_warning(msg).on_line(7).in_column(15)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'complex resource with a misaligned =>' do
|
130
|
+
let(:code) { "
|
131
|
+
file { '/tmp/foo':
|
132
|
+
foo => 1,
|
133
|
+
bar => $baz ? {
|
134
|
+
gronk => 2,
|
135
|
+
meh => 3,
|
136
|
+
},
|
137
|
+
meep => 4,
|
138
|
+
bah => 5,
|
139
|
+
}"
|
140
|
+
}
|
141
|
+
|
142
|
+
it 'should detect three problems' do
|
143
|
+
expect(problems).to have(3).problems
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should create three warnings' do
|
147
|
+
expect(problems).to contain_warning(msg).on_line(3).in_column(15)
|
148
|
+
expect(problems).to contain_warning(msg).on_line(6).in_column(17)
|
149
|
+
expect(problems).to contain_warning(msg).on_line(9).in_column(15)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'multi-resource with a misaligned =>' do
|
154
|
+
let(:code) { "
|
155
|
+
file {
|
156
|
+
'/tmp/foo': ;
|
157
|
+
'/tmp/bar':
|
158
|
+
foo => 'bar';
|
159
|
+
'/tmp/baz':
|
160
|
+
gronk => 'bah',
|
161
|
+
meh => 'no'
|
162
|
+
}"
|
163
|
+
}
|
164
|
+
|
165
|
+
it 'should only detect a single problem' do
|
166
|
+
expect(problems).to have(1).problem
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should create a warning' do
|
170
|
+
expect(problems).to contain_warning(msg).on_line(8).in_column(17)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'multiple single line resources' do
|
175
|
+
let(:code) { "
|
176
|
+
file { 'foo': ensure => file }
|
177
|
+
package { 'bar': ensure => present }"
|
178
|
+
}
|
179
|
+
|
180
|
+
it 'should not detect any problems' do
|
181
|
+
expect(problems).to have(0).problems
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'resource with unaligned => in commented line' do
|
186
|
+
let(:code) { "
|
187
|
+
file { 'foo':
|
188
|
+
ensure => directory,
|
189
|
+
# purge => true,
|
190
|
+
}"
|
191
|
+
}
|
192
|
+
|
193
|
+
it 'should not detect any problems' do
|
194
|
+
expect(problems).to have(0).problems
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'single line resource spread out on multiple lines' do
|
199
|
+
let(:code) {"
|
200
|
+
file {
|
201
|
+
'foo': ensure => present,
|
202
|
+
}"
|
203
|
+
}
|
204
|
+
|
205
|
+
it 'should not detect any problems' do
|
206
|
+
expect(problems).to have(0).problems
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context 'multiline resource with a single line of params' do
|
211
|
+
let(:code) { "
|
212
|
+
mymodule::do_thing { 'some thing':
|
213
|
+
whatever => { foo => 'bar', one => 'two' },
|
214
|
+
}"
|
215
|
+
}
|
216
|
+
|
217
|
+
it 'should not detect any problems' do
|
218
|
+
expect(problems).to have(0).problems
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'resource with aligned => too far out' do
|
223
|
+
let(:code) { "
|
224
|
+
file { '/tmp/foo':
|
225
|
+
ensure => file,
|
226
|
+
mode => '0444',
|
227
|
+
}"
|
228
|
+
}
|
229
|
+
|
230
|
+
it 'should detect 2 problems' do
|
231
|
+
expect(problems).to have(2).problems
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'should create 2 warnings' do
|
235
|
+
expect(problems).to contain_warning(msg).on_line(3).in_column(19)
|
236
|
+
expect(problems).to contain_warning(msg).on_line(4).in_column(19)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
context 'resource with multiple params where one is an empty hash' do
|
241
|
+
let(:code) { "
|
242
|
+
foo { 'foo':
|
243
|
+
a => true,
|
244
|
+
b => {
|
245
|
+
}
|
246
|
+
}
|
247
|
+
"}
|
248
|
+
|
249
|
+
it 'should not detect any problems' do
|
250
|
+
expect(problems).to have(0).problems
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
context 'multiline resource with multiple params on a line' do
|
255
|
+
let(:code) { "
|
256
|
+
user { 'test':
|
257
|
+
a => 'foo', bb => 'bar',
|
258
|
+
ccc => 'baz',
|
259
|
+
}
|
260
|
+
" }
|
261
|
+
|
262
|
+
it 'should detect 2 problems' do
|
263
|
+
expect(problems).to have(2).problems
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'should create 2 warnings' do
|
267
|
+
expect(problems).to contain_warning(msg).on_line(3).in_column(13)
|
268
|
+
expect(problems).to contain_warning(msg).on_line(3).in_column(26)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
context 'resource param containing a single-element same-line hash' do
|
273
|
+
let(:code) { "
|
274
|
+
foo { 'foo':
|
275
|
+
a => true,
|
276
|
+
b => { 'a' => 'b' }
|
277
|
+
}
|
278
|
+
"}
|
279
|
+
|
280
|
+
it 'should not detect any problems' do
|
281
|
+
expect(problems).to have(0).problems
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
context 'with fix enabled' do
|
288
|
+
before do
|
289
|
+
PuppetLint.configuration.fix = true
|
290
|
+
end
|
291
|
+
|
292
|
+
after do
|
293
|
+
PuppetLint.configuration.fix = false
|
294
|
+
end
|
295
|
+
|
296
|
+
context 'single resource with a misaligned =>' do
|
297
|
+
let(:code) { "
|
298
|
+
file { '/tmp/foo':
|
299
|
+
foo => 1,
|
300
|
+
bar => 2,
|
301
|
+
gronk => 3,
|
302
|
+
baz => 4,
|
303
|
+
meh => 5,
|
304
|
+
}"
|
305
|
+
}
|
306
|
+
let(:fixed) { "
|
307
|
+
file { '/tmp/foo':
|
308
|
+
foo => 1,
|
309
|
+
bar => 2,
|
310
|
+
gronk => 3,
|
311
|
+
baz => 4,
|
312
|
+
meh => 5,
|
313
|
+
}"
|
314
|
+
}
|
315
|
+
|
316
|
+
it 'should detect four problems' do
|
317
|
+
expect(problems).to have(4).problems
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'should fix the manifest' do
|
321
|
+
expect(problems).to contain_fixed(msg).on_line(3).in_column(15)
|
322
|
+
expect(problems).to contain_fixed(msg).on_line(4).in_column(15)
|
323
|
+
expect(problems).to contain_fixed(msg).on_line(6).in_column(16)
|
324
|
+
expect(problems).to contain_fixed(msg).on_line(7).in_column(15)
|
325
|
+
end
|
326
|
+
|
327
|
+
it 'should align the arrows' do
|
328
|
+
expect(manifest).to eq(fixed)
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
context 'complex resource with a misaligned =>' do
|
333
|
+
let(:code) { "
|
334
|
+
file { '/tmp/foo':
|
335
|
+
foo => 1,
|
336
|
+
bar => $baz ? {
|
337
|
+
gronk => 2,
|
338
|
+
meh => 3,
|
339
|
+
},
|
340
|
+
meep => 4,
|
341
|
+
bah => 5,
|
342
|
+
}"
|
343
|
+
}
|
344
|
+
let(:fixed) { "
|
345
|
+
file { '/tmp/foo':
|
346
|
+
foo => 1,
|
347
|
+
bar => $baz ? {
|
348
|
+
gronk => 2,
|
349
|
+
meh => 3,
|
350
|
+
},
|
351
|
+
meep => 4,
|
352
|
+
bah => 5,
|
353
|
+
}"
|
354
|
+
}
|
355
|
+
|
356
|
+
it 'should detect three problems' do
|
357
|
+
expect(problems).to have(3).problems
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'should fix the manifest' do
|
361
|
+
expect(problems).to contain_fixed(msg).on_line(3).in_column(15)
|
362
|
+
expect(problems).to contain_fixed(msg).on_line(6).in_column(17)
|
363
|
+
expect(problems).to contain_fixed(msg).on_line(9).in_column(15)
|
364
|
+
end
|
365
|
+
|
366
|
+
it 'should align the arrows' do
|
367
|
+
expect(manifest).to eq(fixed)
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
context 'multi-resource with a misaligned =>' do
|
372
|
+
let(:code) { "
|
373
|
+
file {
|
374
|
+
'/tmp/foo': ;
|
375
|
+
'/tmp/bar':
|
376
|
+
foo => 'bar';
|
377
|
+
'/tmp/baz':
|
378
|
+
gronk => 'bah',
|
379
|
+
meh => 'no'
|
380
|
+
}"
|
381
|
+
}
|
382
|
+
let(:fixed) { "
|
383
|
+
file {
|
384
|
+
'/tmp/foo': ;
|
385
|
+
'/tmp/bar':
|
386
|
+
foo => 'bar';
|
387
|
+
'/tmp/baz':
|
388
|
+
gronk => 'bah',
|
389
|
+
meh => 'no'
|
390
|
+
}"
|
391
|
+
}
|
392
|
+
|
393
|
+
it 'should only detect a single problem' do
|
394
|
+
expect(problems).to have(1).problem
|
395
|
+
end
|
396
|
+
|
397
|
+
it 'should fix the manifest' do
|
398
|
+
expect(problems).to contain_fixed(msg).on_line(8).in_column(17)
|
399
|
+
end
|
400
|
+
|
401
|
+
it 'should align the arrows' do
|
402
|
+
expect(manifest).to eq(fixed)
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
context 'resource with aligned => too far out' do
|
407
|
+
let(:code) { "
|
408
|
+
file { '/tmp/foo':
|
409
|
+
ensure => file,
|
410
|
+
mode => '0444',
|
411
|
+
}"
|
412
|
+
}
|
413
|
+
|
414
|
+
let(:fixed) { "
|
415
|
+
file { '/tmp/foo':
|
416
|
+
ensure => file,
|
417
|
+
mode => '0444',
|
418
|
+
}"
|
419
|
+
}
|
420
|
+
|
421
|
+
it 'should detect 2 problems' do
|
422
|
+
expect(problems).to have(2).problems
|
423
|
+
end
|
424
|
+
|
425
|
+
it 'should create 2 warnings' do
|
426
|
+
expect(problems).to contain_fixed(msg).on_line(3).in_column(19)
|
427
|
+
expect(problems).to contain_fixed(msg).on_line(4).in_column(19)
|
428
|
+
end
|
429
|
+
|
430
|
+
it 'should realign the arrows with the minimum whitespace' do
|
431
|
+
expect(manifest).to eq(fixed)
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
context 'resource with unaligned => and no whitespace between param and =>' do
|
436
|
+
let(:code) { "
|
437
|
+
user { 'test':
|
438
|
+
param1 => 'foo',
|
439
|
+
param2=> 'bar',
|
440
|
+
}
|
441
|
+
" }
|
442
|
+
|
443
|
+
let(:fixed) { "
|
444
|
+
user { 'test':
|
445
|
+
param1 => 'foo',
|
446
|
+
param2 => 'bar',
|
447
|
+
}
|
448
|
+
" }
|
449
|
+
|
450
|
+
it 'should detect 1 problem' do
|
451
|
+
expect(problems).to have(1).problem
|
452
|
+
end
|
453
|
+
|
454
|
+
it 'should fix the problem' do
|
455
|
+
expect(problems).to contain_fixed(msg).on_line(4).in_column(17)
|
456
|
+
end
|
457
|
+
|
458
|
+
it 'should add whitespace between the param and the arrow' do
|
459
|
+
expect(manifest).to eq(fixed)
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
context 'multiline resource with multiple params on a line' do
|
464
|
+
let(:code) { "
|
465
|
+
user { 'test':
|
466
|
+
a => 'foo', bb => 'bar',
|
467
|
+
ccc => 'baz',
|
468
|
+
}
|
469
|
+
" }
|
470
|
+
|
471
|
+
let(:fixed) { "
|
472
|
+
user { 'test':
|
473
|
+
a => 'foo',
|
474
|
+
bb => 'bar',
|
475
|
+
ccc => 'baz',
|
476
|
+
}
|
477
|
+
" }
|
478
|
+
|
479
|
+
it 'should detect 2 problems' do
|
480
|
+
expect(problems).to have(2).problems
|
481
|
+
end
|
482
|
+
|
483
|
+
it 'should fix 2 problems' do
|
484
|
+
expect(problems).to contain_fixed(msg).on_line(3).in_column(13)
|
485
|
+
expect(problems).to contain_fixed(msg).on_line(3).in_column(26)
|
486
|
+
end
|
487
|
+
|
488
|
+
it 'should move the extra param onto its own line and realign' do
|
489
|
+
expect(manifest).to eq(fixed)
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
context 'multiline resource with multiple params on a line, extra one longer' do
|
494
|
+
let(:code) { "
|
495
|
+
user { 'test':
|
496
|
+
a => 'foo', bbccc => 'bar',
|
497
|
+
ccc => 'baz',
|
498
|
+
}
|
499
|
+
" }
|
500
|
+
|
501
|
+
let(:fixed) { "
|
502
|
+
user { 'test':
|
503
|
+
a => 'foo',
|
504
|
+
bbccc => 'bar',
|
505
|
+
ccc => 'baz',
|
506
|
+
}
|
507
|
+
" }
|
508
|
+
|
509
|
+
it 'should detect 2 problems' do
|
510
|
+
expect(problems).to have(3).problems
|
511
|
+
end
|
512
|
+
|
513
|
+
it 'should fix 2 problems' do
|
514
|
+
expect(problems).to contain_fixed(msg).on_line(3).in_column(13)
|
515
|
+
expect(problems).to contain_fixed(msg).on_line(3).in_column(29)
|
516
|
+
expect(problems).to contain_fixed(msg).on_line(4).in_column(15)
|
517
|
+
end
|
518
|
+
|
519
|
+
it 'should move the extra param onto its own line and realign' do
|
520
|
+
expect(manifest).to eq(fixed)
|
521
|
+
end
|
522
|
+
end
|
523
|
+
end
|
524
|
+
end
|