Skip to content

Commit 467f6a9

Browse files
committed
Suggest how to fix the unquoted legacy facts, too
1 parent 43fc623 commit 467f6a9

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,13 @@ def check
115115
tokens.select { |x| LEGACY_FACTS_VAR_TYPES.include?(x.type) }.each do |token|
116116
fact_name = ''
117117

118-
# This matches legacy facts defined in the fact hash that use the top scope
119-
# fact assignment.
120-
if token.value.match(%r{::facts\['(.*)'\]})
121-
fact_name = token.value.match(%r{::facts\['(.*)'\]})[1]
122-
123118
# This matches legacy facts defined in the fact hash.
124-
elsif token.value.match(%r{facts\['(.*)'\]})
125-
fact_name = token.value.match(%r{facts\['(.*)'\]})[1]
119+
if match = token.value.match(%r{(::)?facts\['(.*)'\]})
120+
fact_name = match[2]
121+
122+
# Same match, but using the unquoted syntax
123+
elsif match = token.value.match(%r{(::)?facts\[(.*)\]})
124+
fact_name = match[2]
126125

127126
# This matches using legacy facts in a the new structured fact. For
128127
# example this would match 'uuid' in $facts['uuid'] so it can be converted

spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
let(:code) { "$::facts[osfamily]" }
127127

128128
it 'detects a single problem' do
129-
expect(problems).to have(0).problem
129+
expect(problems).to have(1).problem
130130
end
131131
end
132132

0 commit comments

Comments
 (0)