puppet-lint 0.4.0.pre1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,25 +1,37 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'variable_contains_dash' do
|
4
|
-
|
4
|
+
let(:msg) { 'variable contains a dash' }
|
5
|
+
|
6
|
+
context 'a variable containing a dash' do
|
5
7
|
let(:code) { '$foo-bar' }
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
13
16
|
end
|
14
17
|
|
15
|
-
|
18
|
+
context 'variable containing a dash' do
|
16
19
|
let(:code) { '" $foo-bar"' }
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
24
36
|
end
|
25
37
|
end
|
@@ -1,20 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe '2sp_soft_tabs' do
|
4
|
-
|
4
|
+
let(:msg) { 'two-space soft tabs not used' }
|
5
|
+
|
6
|
+
context 'when a line is indented by 3 spaces' do
|
5
7
|
let(:code) { "
|
6
8
|
file { 'foo':
|
7
9
|
foo => bar,
|
8
10
|
}"
|
9
11
|
}
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
}
|
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
|
19
20
|
end
|
20
21
|
end
|
@@ -2,37 +2,53 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe '80chars' do
|
5
|
-
|
5
|
+
let(:msg) { 'line has more than 80 characters' }
|
6
|
+
|
7
|
+
context 'file resource with a source line > 80c' do
|
6
8
|
let(:code) { "
|
7
9
|
file {
|
8
10
|
source => 'puppet:///modules/certificates/etc/ssl/private/wildcard.example.com.crt',
|
9
11
|
}"
|
10
12
|
}
|
11
13
|
|
12
|
-
|
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
|
13
29
|
end
|
14
30
|
|
15
|
-
|
31
|
+
context 'length of lines with UTF-8 characters' do
|
16
32
|
let(:code) { "
|
17
33
|
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
18
34
|
# ┃ Configuration ┃
|
19
35
|
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
|
20
36
|
}
|
21
|
-
|
22
|
-
|
23
|
-
|
37
|
+
|
38
|
+
it 'should not detect any problems' do
|
39
|
+
expect(problems).to have(0).problems
|
40
|
+
end
|
24
41
|
end
|
25
42
|
|
26
|
-
|
43
|
+
context '81 character line' do
|
27
44
|
let(:code) { 'a' * 81 }
|
28
45
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
}
|
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
|
37
53
|
end
|
38
54
|
end
|
@@ -1,304 +1,244 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'arrow_alignment' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
15
23
|
|
16
|
-
|
17
|
-
|
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
|
18
39
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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 ? {
|
23
59
|
present => directory,
|
24
60
|
absent => undef,
|
25
61
|
},
|
26
|
-
|
27
|
-
}"
|
28
|
-
}
|
29
|
-
|
30
|
-
its(:problems) { should be_empty }
|
31
|
-
end
|
32
|
-
|
33
|
-
describe 'selector inside a resource' do
|
34
|
-
let(:code) { "
|
35
|
-
ensure => $ensure ? {
|
36
|
-
present => directory,
|
37
|
-
absent => undef,
|
38
|
-
},
|
39
|
-
owner => 'foo4',
|
40
|
-
group => 'foo4',
|
41
|
-
mode => '0755'," }
|
42
|
-
|
43
|
-
its(:problems) { should be_empty }
|
44
|
-
end
|
45
|
-
|
46
|
-
describe 'selector inside a hash inside a resource' do
|
47
|
-
let(:code) { "
|
48
|
-
server => {
|
49
|
-
ensure => ensure => $ensure ? {
|
50
|
-
present => directory,
|
51
|
-
absent => undef,
|
62
|
+
ip => '192.168.1.1'
|
52
63
|
},
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
group => 'foo4',
|
57
|
-
mode => '0755'," }
|
64
|
+
owner => 'foo4',
|
65
|
+
group => 'foo4',
|
66
|
+
mode => '0755'," }
|
58
67
|
|
59
|
-
|
60
|
-
|
68
|
+
it 'should not detect any problems' do
|
69
|
+
expect(problems).to have(0).problems
|
70
|
+
end
|
71
|
+
end
|
61
72
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
+
}
|
83
95
|
}
|
84
96
|
}
|
85
97
|
}
|
86
|
-
}
|
87
|
-
}
|
88
|
-
}
|
98
|
+
}"
|
99
|
+
}
|
89
100
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
describe 'single resource with a misaligned =>' do
|
94
|
-
let(:code) { "
|
95
|
-
file { '/tmp/foo':
|
96
|
-
foo => 1,
|
97
|
-
bar => 2,
|
98
|
-
gronk => 3,
|
99
|
-
baz => 4,
|
100
|
-
meh => 5,
|
101
|
-
}"
|
102
|
-
}
|
103
|
-
|
104
|
-
its(:problems) do
|
105
|
-
should have_problem({
|
106
|
-
:kind => :warning,
|
107
|
-
:message => 'indentation of => is not properly aligned',
|
108
|
-
:linenumber => 3,
|
109
|
-
:column => 13,
|
110
|
-
})
|
111
|
-
should have_problem({
|
112
|
-
:kind => :warning,
|
113
|
-
:message => 'indentation of => is not properly aligned',
|
114
|
-
:linenumber => 4,
|
115
|
-
:column => 13,
|
116
|
-
})
|
117
|
-
should have_problem({
|
118
|
-
:kind => :warning,
|
119
|
-
:message => 'indentation of => is not properly aligned',
|
120
|
-
:linenumber => 6,
|
121
|
-
:column => 14,
|
122
|
-
})
|
123
|
-
should have_problem({
|
124
|
-
:kind => :warning,
|
125
|
-
:message => 'indentation of => is not properly aligned',
|
126
|
-
:linenumber => 7,
|
127
|
-
:column => 13,
|
128
|
-
})
|
101
|
+
it 'should not detect any problems' do
|
102
|
+
expect(problems).to have(0).problems
|
103
|
+
end
|
129
104
|
end
|
130
|
-
end
|
131
105
|
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
135
127
|
end
|
136
128
|
|
137
|
-
|
138
|
-
|
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
|
139
151
|
end
|
140
152
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
:message => 'indentation of => is not properly aligned',
|
161
|
-
:linenumber => 4,
|
162
|
-
:column => 13,
|
163
|
-
})
|
164
|
-
should have_problem({
|
165
|
-
:kind => :fixed,
|
166
|
-
:message => 'indentation of => is not properly aligned',
|
167
|
-
:linenumber => 6,
|
168
|
-
:column => 14,
|
169
|
-
})
|
170
|
-
should have_problem({
|
171
|
-
:kind => :fixed,
|
172
|
-
:message => 'indentation of => is not properly aligned',
|
173
|
-
:linenumber => 7,
|
174
|
-
:column => 13,
|
175
|
-
})
|
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
|
176
172
|
end
|
177
173
|
|
178
|
-
|
179
|
-
|
180
|
-
foo
|
181
|
-
bar
|
182
|
-
|
183
|
-
baz => 4,
|
184
|
-
meh => 5,
|
185
|
-
}"
|
186
|
-
}
|
187
|
-
end
|
174
|
+
context 'multiple single line resources' do
|
175
|
+
let(:code) { "
|
176
|
+
file { 'foo': ensure => file }
|
177
|
+
package { 'bar': ensure => present }"
|
178
|
+
}
|
188
179
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
foo => 1,
|
193
|
-
bar => $baz ? {
|
194
|
-
gronk => 2,
|
195
|
-
meh => 3,
|
196
|
-
},
|
197
|
-
meep => 4,
|
198
|
-
bah => 5,
|
199
|
-
}"
|
200
|
-
}
|
201
|
-
|
202
|
-
its(:problems) do
|
203
|
-
should have_problem({
|
204
|
-
:kind => :warning,
|
205
|
-
:message => 'indentation of => is not properly aligned',
|
206
|
-
:linenumber => 3,
|
207
|
-
:column => 13,
|
208
|
-
})
|
209
|
-
should have_problem({
|
210
|
-
:kind => :warning,
|
211
|
-
:message => 'indentation of => is not properly aligned',
|
212
|
-
:linenumber => 6,
|
213
|
-
:column => 15,
|
214
|
-
})
|
215
|
-
should have_problem({
|
216
|
-
:kind => :warning,
|
217
|
-
:message => 'indentation of => is not properly aligned',
|
218
|
-
:linenumber => 9,
|
219
|
-
:column => 13,
|
220
|
-
})
|
180
|
+
it 'should not detect any problems' do
|
181
|
+
expect(problems).to have(0).problems
|
182
|
+
end
|
221
183
|
end
|
222
|
-
end
|
223
184
|
|
224
|
-
|
225
|
-
|
226
|
-
|
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
|
227
196
|
end
|
228
197
|
|
229
|
-
|
230
|
-
|
231
|
-
|
198
|
+
context 'single line resource spread out on multiple lines' do
|
199
|
+
let(:code) {"
|
200
|
+
file {
|
201
|
+
'foo': ensure => present,
|
202
|
+
}"
|
203
|
+
}
|
232
204
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
bar => $baz ? {
|
237
|
-
gronk => 2,
|
238
|
-
meh => 3,
|
239
|
-
},
|
240
|
-
meep => 4,
|
241
|
-
bah => 5,
|
242
|
-
}"
|
243
|
-
}
|
244
|
-
|
245
|
-
its(:problems) do
|
246
|
-
should have_problem({
|
247
|
-
:kind => :fixed,
|
248
|
-
:message => 'indentation of => is not properly aligned',
|
249
|
-
:linenumber => 3,
|
250
|
-
:column => 13,
|
251
|
-
})
|
252
|
-
should have_problem({
|
253
|
-
:kind => :fixed,
|
254
|
-
:message => 'indentation of => is not properly aligned',
|
255
|
-
:linenumber => 6,
|
256
|
-
:column => 15,
|
257
|
-
})
|
258
|
-
should have_problem({
|
259
|
-
:kind => :fixed,
|
260
|
-
:message => 'indentation of => is not properly aligned',
|
261
|
-
:linenumber => 9,
|
262
|
-
:column => 13,
|
263
|
-
})
|
205
|
+
it 'should not detect any problems' do
|
206
|
+
expect(problems).to have(0).problems
|
207
|
+
end
|
264
208
|
end
|
265
209
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
},
|
273
|
-
meep => 4,
|
274
|
-
bah => 5,
|
275
|
-
}"
|
276
|
-
}
|
277
|
-
end
|
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
|
+
}
|
278
216
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
should
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
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
|
298
238
|
end
|
299
239
|
end
|
300
240
|
|
301
|
-
|
241
|
+
context 'with fix enabled' do
|
302
242
|
before do
|
303
243
|
PuppetLint.configuration.fix = true
|
304
244
|
end
|
@@ -307,65 +247,143 @@ describe 'arrow_alignment' do
|
|
307
247
|
PuppetLint.configuration.fix = false
|
308
248
|
end
|
309
249
|
|
310
|
-
|
311
|
-
|
312
|
-
'/tmp/foo':
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
meh =>
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
250
|
+
context 'single resource with a misaligned =>' do
|
251
|
+
let(:code) { "
|
252
|
+
file { '/tmp/foo':
|
253
|
+
foo => 1,
|
254
|
+
bar => 2,
|
255
|
+
gronk => 3,
|
256
|
+
baz => 4,
|
257
|
+
meh => 5,
|
258
|
+
}"
|
259
|
+
}
|
260
|
+
let(:fixed) { "
|
261
|
+
file { '/tmp/foo':
|
262
|
+
foo => 1,
|
263
|
+
bar => 2,
|
264
|
+
gronk => 3,
|
265
|
+
baz => 4,
|
266
|
+
meh => 5,
|
267
|
+
}"
|
268
|
+
}
|
269
|
+
|
270
|
+
it 'should detect four problems' do
|
271
|
+
expect(problems).to have(4).problems
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'should fix the manifest' do
|
275
|
+
expect(problems).to contain_fixed(msg).on_line(3).in_column(15)
|
276
|
+
expect(problems).to contain_fixed(msg).on_line(4).in_column(15)
|
277
|
+
expect(problems).to contain_fixed(msg).on_line(6).in_column(16)
|
278
|
+
expect(problems).to contain_fixed(msg).on_line(7).in_column(15)
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'should align the arrows' do
|
282
|
+
expect(manifest).to eq(fixed)
|
283
|
+
end
|
328
284
|
end
|
329
285
|
|
330
|
-
|
331
|
-
|
332
|
-
'/tmp/foo':
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
286
|
+
context 'complex resource with a misaligned =>' do
|
287
|
+
let(:code) { "
|
288
|
+
file { '/tmp/foo':
|
289
|
+
foo => 1,
|
290
|
+
bar => $baz ? {
|
291
|
+
gronk => 2,
|
292
|
+
meh => 3,
|
293
|
+
},
|
294
|
+
meep => 4,
|
295
|
+
bah => 5,
|
296
|
+
}"
|
297
|
+
}
|
298
|
+
let(:fixed) { "
|
299
|
+
file { '/tmp/foo':
|
300
|
+
foo => 1,
|
301
|
+
bar => $baz ? {
|
302
|
+
gronk => 2,
|
303
|
+
meh => 3,
|
304
|
+
},
|
305
|
+
meep => 4,
|
306
|
+
bah => 5,
|
307
|
+
}"
|
308
|
+
}
|
309
|
+
|
310
|
+
it 'should detect three problems' do
|
311
|
+
expect(problems).to have(3).problems
|
312
|
+
end
|
313
|
+
|
314
|
+
it 'should fix the manifest' do
|
315
|
+
expect(problems).to contain_fixed(msg).on_line(3).in_column(15)
|
316
|
+
expect(problems).to contain_fixed(msg).on_line(6).in_column(17)
|
317
|
+
expect(problems).to contain_fixed(msg).on_line(9).in_column(15)
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'should align the arrows' do
|
321
|
+
expect(manifest).to eq(fixed)
|
322
|
+
end
|
323
|
+
end
|
361
324
|
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
325
|
+
context 'multi-resource with a misaligned =>' do
|
326
|
+
let(:code) { "
|
327
|
+
file {
|
328
|
+
'/tmp/foo': ;
|
329
|
+
'/tmp/bar':
|
330
|
+
foo => 'bar';
|
331
|
+
'/tmp/baz':
|
332
|
+
gronk => 'bah',
|
333
|
+
meh => 'no'
|
334
|
+
}"
|
335
|
+
}
|
336
|
+
let(:fixed) { "
|
337
|
+
file {
|
338
|
+
'/tmp/foo': ;
|
339
|
+
'/tmp/bar':
|
340
|
+
foo => 'bar';
|
341
|
+
'/tmp/baz':
|
342
|
+
gronk => 'bah',
|
343
|
+
meh => 'no'
|
344
|
+
}"
|
345
|
+
}
|
346
|
+
|
347
|
+
it 'should only detect a single problem' do
|
348
|
+
expect(problems).to have(1).problem
|
349
|
+
end
|
350
|
+
|
351
|
+
it 'should fix the manifest' do
|
352
|
+
expect(problems).to contain_fixed(msg).on_line(8).in_column(17)
|
353
|
+
end
|
354
|
+
|
355
|
+
it 'should align the arrows' do
|
356
|
+
expect(manifest).to eq(fixed)
|
357
|
+
end
|
358
|
+
end
|
368
359
|
|
369
|
-
|
360
|
+
context 'resource with aligned => too far out' do
|
361
|
+
let(:code) { "
|
362
|
+
file { '/tmp/foo':
|
363
|
+
ensure => file,
|
364
|
+
mode => '0444',
|
365
|
+
}"
|
366
|
+
}
|
367
|
+
|
368
|
+
let(:fixed) { "
|
369
|
+
file { '/tmp/foo':
|
370
|
+
ensure => file,
|
371
|
+
mode => '0444',
|
372
|
+
}"
|
373
|
+
}
|
374
|
+
|
375
|
+
it 'should detect 2 problems' do
|
376
|
+
expect(problems).to have(2).problems
|
377
|
+
end
|
378
|
+
|
379
|
+
it 'should create 2 warnings' do
|
380
|
+
expect(problems).to contain_fixed(msg).on_line(3).in_column(19)
|
381
|
+
expect(problems).to contain_fixed(msg).on_line(4).in_column(19)
|
382
|
+
end
|
383
|
+
|
384
|
+
it 'should realign the arrows with the minimum whitespace' do
|
385
|
+
expect(manifest).to eq(fixed)
|
386
|
+
end
|
387
|
+
end
|
370
388
|
end
|
371
389
|
end
|