Skip to content
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

puppet-lint crashes if the first line contains only whitespace #81

Closed
nwoythal opened this issue Feb 10, 2023 · 2 comments · Fixed by #86
Closed

puppet-lint crashes if the first line contains only whitespace #81

nwoythal opened this issue Feb 10, 2023 · 2 comments · Fixed by #86
Labels
bug Something isn't working community

Comments

@nwoythal
Copy link

nwoythal commented Feb 10, 2023

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>'
@ekohl
Copy link

ekohl commented Feb 10, 2023

/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.

@nwoythal
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community
Projects
None yet
3 participants