Skip to content

legacy_facts: Deal with variables ending in facts #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def check
fact_name = ''

# This matches legacy facts defined in the fact hash.
if (match = (token.value.match(%r{(::)?facts\['(.*)'\]}) || token.value.match(%r{(::)?facts\[(.*)\]})))
fact_name = match[2]
if (match = token.value.match(%r{^(?:::)?facts\[(?<quote>'?)(?<value>.+)\k<quote>\]$}))
fact_name = match[:value]

# 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 @@ -467,5 +467,13 @@
expect(manifest).to eq("\"${facts['os']['distro']['release']['specification']}\"")
end
end

context 'variable ending in the word fact' do
let(:code) { "$interface_facts['netmask']" }

it 'does not detect any problems' do
expect(problems).to have(0).problem
end
end
end
end