Skip to content

Commit

Permalink
Recognize the unquoted legacy facts hash syntax, too
Browse files Browse the repository at this point in the history
  • Loading branch information
chutzimir committed Apr 26, 2023
1 parent 3373b46 commit 9deeffa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,9 @@ def check
tokens.select { |x| LEGACY_FACTS_VAR_TYPES.include?(x.type) }.each do |token|
fact_name = ''

# This matches legacy facts defined in the fact hash that use the top scope
# fact assignment.
if token.value.match(%r{::facts\['(.*)'\]})
fact_name = token.value.match(%r{::facts\['(.*)'\]})[1]

# This matches legacy facts defined in the fact hash.
elsif token.value.match(%r{facts\['(.*)'\]})
fact_name = token.value.match(%r{facts\['(.*)'\]})[1]
if (match = (token.value.match(%r{(::)?facts\['(.*)'\]}) || token.value.match(%r{(::)?facts\[(.*)\]})))
fact_name = match[2]

# This matches using legacy facts in a the new structured fact. For
# example this would match 'uuid' in $facts['uuid'] so it can be converted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
let(:code) { '$::facts[osfamily]' }

it 'detects a single problem' do
expect(problems).to have(0).problem
expect(problems).to have(1).problem
end
end
end
Expand Down

0 comments on commit 9deeffa

Please sign in to comment.