puppet-lint-resource_reference_syntax 1.0.14 → 1.1.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.
- checksums.yaml +5 -5
- data/lib/puppet-lint/plugins/resource_reference_with_unquoted_title.rb +39 -0
- data/lib/puppet-lint/plugins/resource_reference_without_title_capital.rb +0 -6
- data/spec/puppet-lint/plugins/resource_reference_with_unquoted_title_spec.rb +207 -0
- data/spec/puppet-lint/plugins/resource_reference_without_title_capital_spec.rb +0 -13
- metadata +15 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a46a1903b6d2e1c4f769806edb8969fd1aecfaa0be25a0fe8be7831a94fb634f
|
4
|
+
data.tar.gz: 7bd63f489f10957be998878845fb88be834390fe6f9947a040e3fffe78189ab5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5a10f947b16541ee913f1ad16a4ba2ffaa978c01228269c42b7a166b172b85911fd1f30752f41e87d67fea4da44637c5210974cae00def70ccdd6512d532d8f
|
7
|
+
data.tar.gz: 4b555f5fe5fb76d656dbad267d1756d53a19ae8dc07861a094f36c33542c687d2dcfa602ff38bc1d21a12ed44519dbfd16634c2d81d99ef0b986c72743e89f59
|
@@ -0,0 +1,39 @@
|
|
1
|
+
PuppetLint.new_check(:resource_reference_with_unquoted_title) do
|
2
|
+
def check
|
3
|
+
resource_indexes.each do |resource|
|
4
|
+
resource[:param_tokens].select { |param_token|
|
5
|
+
['require', 'subscribe', 'notify', 'before', 'consume', 'export'].include? param_token.value
|
6
|
+
}.each do |param_token|
|
7
|
+
value_token = param_token.next_code_token
|
8
|
+
check = value_token.next_token
|
9
|
+
until resource[:param_tokens].include? check or not resource[:tokens].include? check or check.nil?
|
10
|
+
case value_token.next_token.type
|
11
|
+
when :CLASSREF
|
12
|
+
begin
|
13
|
+
if value_token.next_token.next_token.type == :LBRACK
|
14
|
+
check_token = value_token.next_token.next_token.next_token
|
15
|
+
if check_token.type == :NAME
|
16
|
+
notify :error, {
|
17
|
+
:message => 'unquoted title in resource reference',
|
18
|
+
:line => check_token.line,
|
19
|
+
:column => check_token.column,
|
20
|
+
:token => check_token,
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
value_token = value_token.next_token
|
25
|
+
check = value_token.next_token
|
26
|
+
end
|
27
|
+
else
|
28
|
+
value_token = value_token.next_token
|
29
|
+
check = value_token.next_token
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def fix(problem)
|
37
|
+
problem[:token].type = :SSTRING
|
38
|
+
end
|
39
|
+
end
|
@@ -18,12 +18,6 @@ PuppetLint.new_check(:resource_reference_without_title_capital) do
|
|
18
18
|
:line => check_token.line,
|
19
19
|
:column => check_token.column
|
20
20
|
}
|
21
|
-
elsif check_token.type == :NAME
|
22
|
-
notify :error, {
|
23
|
-
:message => 'resource reference with title with missing quotes',
|
24
|
-
:line => check_token.line,
|
25
|
-
:column => check_token.column
|
26
|
-
}
|
27
21
|
end
|
28
22
|
end
|
29
23
|
value_token = value_token.next_token
|
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'resource_reference_with_unquoted_title' do
|
4
|
+
let(:msg) { 'unquoted title in resource reference' }
|
5
|
+
|
6
|
+
context 'with fix disabled' do
|
7
|
+
context 'quoted resource ref on single line resource' do
|
8
|
+
let(:code) { "file { 'foo': require => File['bar'] }" }
|
9
|
+
|
10
|
+
it 'should not detect any problems' do
|
11
|
+
expect(problems).to have(0).problems
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'unquoted resource ref on single line resource' do
|
16
|
+
let(:code) { "file { 'foo': require => File[bar] }" }
|
17
|
+
|
18
|
+
it 'should only detect a single problem' do
|
19
|
+
expect(problems).to have(1).problem
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should raise an error' do
|
23
|
+
expect(problems).to contain_error(msg).on_line(1).in_column(31)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
context 'quoted resource ref on multi line resource' do
|
29
|
+
let(:code) do
|
30
|
+
<<-END
|
31
|
+
file { 'foo':
|
32
|
+
require => File['bar'],
|
33
|
+
}
|
34
|
+
END
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should not detect any problems' do
|
38
|
+
expect(problems).to have(0).problems
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'unquoted resource ref on multi line resource' do
|
43
|
+
let(:code) do
|
44
|
+
<<-END
|
45
|
+
file { 'foo':
|
46
|
+
require => File[bar]
|
47
|
+
}
|
48
|
+
END
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should only detect a single problem' do
|
52
|
+
expect(problems).to have(1).problem
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should raise an error' do
|
56
|
+
expect(problems).to contain_error(msg).on_line(2).in_column(29)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'condensed resources with quoted refs' do
|
61
|
+
let(:code) do
|
62
|
+
<<-END
|
63
|
+
file {
|
64
|
+
'foo':
|
65
|
+
require => File['bar'];
|
66
|
+
'bar':
|
67
|
+
require => File['baz'];
|
68
|
+
}
|
69
|
+
END
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should not detect any problems' do
|
73
|
+
expect(problems).to have(0).problems
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'condensed resources with an unquoted ref' do
|
78
|
+
let(:code) do
|
79
|
+
<<-END
|
80
|
+
file {
|
81
|
+
'foo':
|
82
|
+
require => File[bar];
|
83
|
+
'bar':
|
84
|
+
require => File['baz'];
|
85
|
+
}
|
86
|
+
END
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should only detect a single problem' do
|
90
|
+
expect(problems).to have(1).problem
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should raise an error' do
|
94
|
+
expect(problems).to contain_error(msg).on_line(3).in_column(31)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'resource refs with interpolated variables' do
|
99
|
+
let(:code) do
|
100
|
+
<<-END
|
101
|
+
$file = 'bar'
|
102
|
+
|
103
|
+
file { 'foo':
|
104
|
+
require => File[$file]
|
105
|
+
}
|
106
|
+
END
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should not detect any problems' do
|
110
|
+
expect(problems).to have(0).problems
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'with fix enabled' do
|
117
|
+
before do
|
118
|
+
PuppetLint.configuration.fix = true
|
119
|
+
end
|
120
|
+
|
121
|
+
after do
|
122
|
+
PuppetLint.configuration.fix = false
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'unquoted resource ref on single line resource' do
|
126
|
+
let(:code) { "file { 'foo': require => File[bar] }" }
|
127
|
+
|
128
|
+
it 'should only detect a single problem' do
|
129
|
+
expect(problems).to have(1).problem
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should fix the manifest' do
|
133
|
+
expect(problems).to contain_fixed(msg).on_line(1).in_column(31)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should single quote the resource title' do
|
137
|
+
expect(manifest).to eq("file { 'foo': require => File['bar'] }")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'unquoted resource ref on multi line resource' do
|
142
|
+
let(:code) do
|
143
|
+
<<-END
|
144
|
+
file { 'foo':
|
145
|
+
require => File[bar]
|
146
|
+
}
|
147
|
+
END
|
148
|
+
end
|
149
|
+
|
150
|
+
let(:fixed) do
|
151
|
+
<<-END
|
152
|
+
file { 'foo':
|
153
|
+
require => File['bar']
|
154
|
+
}
|
155
|
+
END
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should only detect a single problem' do
|
159
|
+
expect(problems).to have(1).problem
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should fix the manifest' do
|
163
|
+
expect(problems).to contain_fixed(msg).on_line(2).in_column(29)
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should single quote the resource ref' do
|
167
|
+
expect(manifest).to eq(fixed)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'condensed resources with an unquoted ref' do
|
172
|
+
let(:code) do
|
173
|
+
<<-END
|
174
|
+
file {
|
175
|
+
'foo':
|
176
|
+
require => File[bar];
|
177
|
+
'bar':
|
178
|
+
require => File['baz'];
|
179
|
+
}
|
180
|
+
END
|
181
|
+
end
|
182
|
+
|
183
|
+
let(:fixed) do
|
184
|
+
<<-END
|
185
|
+
file {
|
186
|
+
'foo':
|
187
|
+
require => File['bar'];
|
188
|
+
'bar':
|
189
|
+
require => File['baz'];
|
190
|
+
}
|
191
|
+
END
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should only detect a single problem' do
|
195
|
+
expect(problems).to have(1).problem
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'should fix the manifest' do
|
199
|
+
expect(problems).to contain_fixed(msg).on_line(3).in_column(31)
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'should single quote the resource title' do
|
203
|
+
expect(manifest).to eq(fixed)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
@@ -99,19 +99,6 @@ describe 'resource_reference_without_title_capital' do
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
context 'resource reference with title without quotes' do
|
103
|
-
let(:msg) { 'resource reference with title with missing quotes' }
|
104
|
-
let(:code) { "file { 'foo': ensure => file, notify => Title[one],}" }
|
105
|
-
|
106
|
-
it 'should only detect a single problem' do
|
107
|
-
expect(problems).to have(1).problem
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should create an error' do
|
111
|
-
expect(problems).to contain_error(msg).on_line(1)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
102
|
context 'stay within the parameter context' do
|
116
103
|
let(:code) { "file { 'foo': ensure => file, notify => Title['One'],} $var = [ Exec[runsomething] ]" }
|
117
104
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-lint-resource_reference_syntax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Alfke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet-lint
|
@@ -76,32 +76,32 @@ dependencies:
|
|
76
76
|
name: rake
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - "
|
79
|
+
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- - "
|
86
|
+
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: simplecov
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- - "
|
93
|
+
- - ">="
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '0'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- - "
|
100
|
+
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
|
-
description:
|
104
|
-
|
103
|
+
description: " Extends puppet-lint to ensure that the reference syntax follows
|
104
|
+
Puppet 4 style\n"
|
105
105
|
email: ma@example42.com
|
106
106
|
executables: []
|
107
107
|
extensions: []
|
@@ -111,9 +111,11 @@ files:
|
|
111
111
|
- LICENSE
|
112
112
|
- README.md
|
113
113
|
- lib/puppet-lint/plugins/resource_reference_chain_without_whitespace.rb
|
114
|
+
- lib/puppet-lint/plugins/resource_reference_with_unquoted_title.rb
|
114
115
|
- lib/puppet-lint/plugins/resource_reference_without_title_capital.rb
|
115
116
|
- lib/puppet-lint/plugins/resource_reference_without_whitespace.rb
|
116
117
|
- spec/puppet-lint/plugins/resource_reference_chain_without_whitespace_spec.rb
|
118
|
+
- spec/puppet-lint/plugins/resource_reference_with_unquoted_title_spec.rb
|
117
119
|
- spec/puppet-lint/plugins/resource_reference_without_title_capital_spec.rb
|
118
120
|
- spec/puppet-lint/plugins/resource_reference_without_whitespace_spec.rb
|
119
121
|
- spec/spec_helper.rb
|
@@ -137,12 +139,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
139
|
version: '0'
|
138
140
|
requirements: []
|
139
141
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.7.7
|
141
143
|
signing_key:
|
142
144
|
specification_version: 4
|
143
145
|
summary: puppet-lint reference_syntax check
|
144
146
|
test_files:
|
145
|
-
- spec/puppet-lint/plugins/resource_reference_chain_without_whitespace_spec.rb
|
146
|
-
- spec/puppet-lint/plugins/resource_reference_without_title_capital_spec.rb
|
147
|
-
- spec/puppet-lint/plugins/resource_reference_without_whitespace_spec.rb
|
148
147
|
- spec/spec_helper.rb
|
148
|
+
- spec/puppet-lint/plugins/resource_reference_without_whitespace_spec.rb
|
149
|
+
- spec/puppet-lint/plugins/resource_reference_without_title_capital_spec.rb
|
150
|
+
- spec/puppet-lint/plugins/resource_reference_chain_without_whitespace_spec.rb
|
151
|
+
- spec/puppet-lint/plugins/resource_reference_with_unquoted_title_spec.rb
|