Skip to content

Commit 2fd501a

Browse files
authored
Merge pull request #93 from puppetlabs/CONT-666-skip_classref_types
(CONT-666) Skip classref types
2 parents 8a6442d + df978a2 commit 2fd501a

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

lib/puppet-lint/data.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@ def title_tokens
155155
end
156156
end
157157

158+
# Internal: Determine if the given token contains a CLASSREF in
159+
# the token chain..
160+
#
161+
# Returns a Boolean.
162+
def classref?(token)
163+
current_token = token
164+
while (current_token = current_token.prev_code_token)
165+
return true if current_token.type == :CLASSREF
166+
return false if current_token.type == :NAME
167+
end
168+
end
169+
158170
# Internal: Calculate the positions of all resource declarations within the
159171
# tokenised manifest. These positions only point to the content of the
160172
# resource declarations, they do not include resource types or titles.
@@ -170,6 +182,7 @@ def resource_indexes
170182
result = []
171183
tokens.select { |t| t.type == :COLON }.each do |colon_token|
172184
next unless colon_token.next_code_token && colon_token.next_code_token.type != :LBRACE
185+
next if classref?(colon_token)
173186

174187
rel_start_idx = tokens[marker..-1].index(colon_token)
175188
break if rel_start_idx.nil?

spec/unit/puppet-lint/data_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,42 @@
3333
}
3434
end
3535
end
36+
37+
context 'when given a defaults declaration' do
38+
let(:manifest) { "Service { 'foo': }" }
39+
40+
it 'returns an empty array' do
41+
expect(data.resource_indexes).to eq([])
42+
end
43+
end
44+
45+
context 'when given a set of resource declarations' do
46+
let(:manifest) { <<-MANIFEST }
47+
service {
48+
'foo':
49+
ensure => running,
50+
}
51+
52+
service {
53+
'bar':
54+
ensure => running;
55+
'foobar':
56+
ensure => stopped;
57+
}
58+
59+
service { ['first', 'second']:
60+
ensure => running,
61+
}
62+
63+
service { 'third':
64+
ensure => running,
65+
}
66+
MANIFEST
67+
68+
it 'returns an array of resource indexes' do
69+
expect(data.resource_indexes.length).to eq(5)
70+
end
71+
end
3672
end
3773

3874
describe '.insert' do

0 commit comments

Comments
 (0)