puppetlabs / puppet-lint

Check that your Puppet manifests conform to the style guide
https://puppetlabs.github.io/puppet-lint/
MIT License
23 stars 13 forks source link

Missing exec in resources_index with shared block and require #146

Open anthonyryan1 opened 1 year ago

anthonyryan1 commented 1 year ago

Describe the Bug

I've been developing a new puppet-lint plugin and believe I found a bug in the generation of resource_indexes. Having two commands in the same exec block with a require causes only one of them to be linted.

Expected Behavior

There should be two exec resources with command and require, so that each can be linted properly, instead of only the first in the exec block.

Steps to Reproduce

test.pp

file {
  '/tmp/example.txt':
    content => 'example require file';
}

exec {
  'command1':
    command => '/usr/bin/true',
    require => File['/tmp/example.txt'];
  'command2':
    command => '/usr/bin/true',
    require => File['/tmp/example.txt'];
}

test-lint.rb

PuppetLint.new_check(:string_exec_command) do
  def check
    resource_indexes.each do |resource|
      print(resource[:param_tokens])
      print("\n")
    end
  end
end

puppet-lint --load test-lint.rb test.pp

puppet-lint --load test-lint.rb test.pp
[<Token :NAME (content) @3:5>]
[<Token :NAME (command) @8:5>, <Token :NAME (require) @9:5>]

Environment