puppetlabs / puppet-lint

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

pdk validate --auto-correct fails trying to fix indent #107

Open Ah-Puch opened 1 year ago

Ah-Puch commented 1 year ago

Describe the Bug

Trying to run " pdk validate --auto-correct --parallel" on the attached code will cause an error.

Expected Behavior

Should succeed and output corrected code with indent

Steps to Reproduce

Create the class (files needed attached at the end) pdk validate --auto-correct

Environment

Additional Context

demo@demo-u20-lts:~/puppet/demo_array_of_hashes$ cat data/common.yaml

demo_array_of_hashes::users:

demo@demo-u20-lts:~/puppet/demo_array_of_hashes$ more manifests/init.pp class demo_array_of_hashes () {

$users = lookup('demo_array_of_hashes::users') notice(inline_template(" <% @users.each do |user| -%> id=<%= user['id'] %> quota=<%= user['quota'] %> <% end -%> "))

}

demo@demo-u20-lts:~/puppet/demo_array_of_hashes$ pdk validate --auto-correct pdk (INFO): Using Ruby 2.7.7 pdk (INFO): Using Puppet 7.22.0 pdk (INFO): Running all available validators... pdk (INFO): Validator 'puppet-epp' skipped for '/home/demo/puppet/demo_array_of_hashes'. No files matching '["/*.epp"]' found to validate. pdk (INFO): Validator 'task-name' skipped for '/home/demo/puppet/demo_array_of_hashes'. No files matching '["tasks/*/"]' found to validate. pdk (INFO): Validator 'task-metadata-lint' skipped for '/home/demo/puppet/demo_array_of_hashes'. No files matching '["tasks/.json"]' found to validate. ┌ [✔] Running metadata validators ... ├── [✔] Checking metadata syntax (metadata.json tasks/.json). └── [✔] Checking module metadata style (metadata.json). ┌ [✖] Running puppet validators ... ├── [✔] Checking Puppet manifest syntax (/*.pp). └── [✖] Checking Puppet manifest style (*/.pp). [ Whoops! It looks like puppet-lint has encountered an error that it doesn't know how to handle. Please open an issue at https://github.com/rodjek/puppet-lint and paste the following output into the issue description.

puppet-lint version: 2.5.2 ruby version: 2.7.7-p221 platform: x86_64-linux file path: manifests/init.pp file contents:

class demo_array_of_hashes () {

  $users = lookup('demo_array_of_hashes::users')
  notice(inline_template("
  <% @users.each do |user| -%>
  id=<%= user['id'] %>
  quota=<%= user['quota'] %>
  <% end -%>
  "))

}

error:

NoMethodError: undefined method `type' for nil:NilClass
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-strict_indent-check-2.1.0/lib/puppet-lint/plugins/check_strict_indent.rb:163:in `fix'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/checkplugin.rb:42:in `block in fix_problems'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/checkplugin.rb:38:in `each'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/checkplugin.rb:38:in `fix_problems'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/checks.rb:67:in `block in run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/checks.rb:65:in `each'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/checks.rb:65:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint.rb:205:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/bin.rb:66:in `block in run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/bin.rb:62:in `each'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/bin.rb:62:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/bin/puppet-lint:7:in `<top (required)>'
/home/tj/puppet/demo_array_of_hashes/bin/puppet-lint:29:in `load'
/home/tj/puppet/demo_array_of_hashes/bin/puppet-lint:29:in `<main>'

┌ [✔] Running ruby validators ... └── [✔] Checking Ruby code style (/.rb). ┌ [✔] Running tasks validators ... ├── [✔] Checking task names (tasks//). └── [✔] Checking task metadata style (tasks/.json). ┌ [✔] Running yaml validators ... └── [✔] Checking YAML syntax (/*.yaml */.yml).

chelnak commented 1 year ago

Thanks for this. We will take a look and get back to you.