puppetlabs / puppet-lint

Check that your Puppet manifests conform to the style guide

Home Page:https://puppetlabs.github.io/puppet-lint/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`puppet-lint` crashes if the first line contains only whitespace

nwoythal opened this issue · comments

Describe the Bug

Puppet lint will crash when attempting to fix the first line, if it contains only whitespace

Expected Behavior

This should be treated like a standard trailing_whitespace linter violation.

Steps to Reproduce

$ echo " \n# foo" > file.pp && puppet-lint --fix file.pp

Environment

  • Version 3.0.1
  • Platform Ubuntu 22.10

Additional Context


puppet-lint version: 3.0.1
ruby version: 3.0.4-p208
platform: x86_64-linux-gnu
file path: file.pp
file contents:


# foo

error:

NoMethodError: undefined method `next_token=' for nil:NilClass
/home/natewo/.local/share/gem/ruby/3.0.0/gems/puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb:33:in `fix'
/home/natewo/.local/share/gem/ruby/3.0.0/gems/puppet-lint-3.0.1/lib/puppet-lint/checkplugin.rb:42:in `block in fix_problems'
/home/natewo/.local/share/gem/ruby/3.0.0/gems/puppet-lint-3.0.1/lib/puppet-lint/checkplugin.rb:38:in `each'
/home/natewo/.local/share/gem/ruby/3.0.0/gems/puppet-lint-3.0.1/lib/puppet-lint/checkplugin.rb:38:in `fix_problems'
/home/natewo/.local/share/gem/ruby/3.0.0/gems/puppet-lint-3.0.1/lib/puppet-lint/checks.rb:67:in `block in run'
/home/natewo/.local/share/gem/ruby/3.0.0/gems/puppet-lint-3.0.1/lib/puppet-lint/checks.rb:65:in `each'
/home/natewo/.local/share/gem/ruby/3.0.0/gems/puppet-lint-3.0.1/lib/puppet-lint/checks.rb:65:in `run'
/home/natewo/.local/share/gem/ruby/3.0.0/gems/puppet-lint-3.0.1/lib/puppet-lint.rb:220:in `run'
/home/natewo/.local/share/gem/ruby/3.0.0/gems/puppet-lint-3.0.1/lib/puppet-lint/bin.rb:83:in `block in run'
/home/natewo/.local/share/gem/ruby/3.0.0/gems/puppet-lint-3.0.1/lib/puppet-lint/bin.rb:79:in `each'
/home/natewo/.local/share/gem/ruby/3.0.0/gems/puppet-lint-3.0.1/lib/puppet-lint/bin.rb:79:in `run'
/home/natewo/.local/share/gem/ruby/3.0.0/gems/puppet-lint-3.0.1/bin/puppet-lint:7:in `<top (required)>'
/home/natewo/.local/bin/puppet-lint:25:in `load'
/home/natewo/.local/bin/puppet-lint:25:in `<main>'

/home/natewo/.local/share/gem/ruby/3.0.0/gems/puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb:33:in `fix'

That's this line:

What it tries to do is set the next token in a "linked list" but on the first element that doesn't work. Interestingly there is a case if the whitespace is the last, but not the first.

I've opened #82 but this doesn't have tests yet so it's a draft.

Thanks! This fix seems to work for me locally as well.