Skip to content

Commit

Permalink
support facts added by symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
h0tw1r3 committed Jan 29, 2024
1 parent de8d879 commit 1b54aed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/puppet-lint/plugins/check_ghostbuster_facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def check
return if m.nil?

File.foreach(path) do |line|
if line.match?(/Facter.add\(["']([^"']+)["']\)/)
fact_name = line.match(/Facter.add\(["']([^"']+)["']\)/).captures[0]
if line =~ /Facter.add\(["':](?<fact>[^"'\)]+)["']?\)/
fact_name = Regexp.last_match(:fact)

found = false

Expand Down
8 changes: 8 additions & 0 deletions spec/fixtures/modules/foo/lib/facter/asym.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# Fact is a symbol
Facter.add(:asym) do
setcode do
'asym'
end
end
12 changes: 12 additions & 0 deletions spec/puppet-lint/plugins/ghostbuster_facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,17 @@
expect(problems.size).to eq(0)
end
end

context 'when added fact is a symbol and unused' do
let(:path) { './spec/fixtures/modules/foo/lib/facter/asym.rb' }

it 'detects one problem' do
expect(problems.size).to eq(1)
end

it 'creates a warning' do
expect(problems).to contain_warning('Fact asym seems unused')
end
end
end
end

0 comments on commit 1b54aed

Please sign in to comment.