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

Trailing blank lines discarded in PuppetLinter::Data.manifest_lines #378

Closed
decafjoe opened this issue Jan 7, 2015 · 1 comment · Fixed by #384
Closed

Trailing blank lines discarded in PuppetLinter::Data.manifest_lines #378

decafjoe opened this issue Jan 7, 2015 · 1 comment · Fixed by #384

Comments

@decafjoe
Copy link

decafjoe commented Jan 7, 2015

In writing a check for whitespace style, I came across a bug where trailing blank lines were being discarded in manifest_lines, which causes an exception to be raised when puppet-lint tries to report issues with those lines.

TL;DR: In checks.rb on line 23, changing content.split("\n") to content.split("\n", -1) fixes this issue.

example.pp:

(Just an empty file with a newline.)

example.rb:

PuppetLint.new_check(:example) do
  def check
    notify :error, {
      :message => 'this blows up',
      :line    => 1,
      :column  => 0,
    }
  end
end
% puppet-lint --load example.rb --only-checks example --with-context example.pp
ERROR: this blows up on line 1
lib/ruby/1.9.1/gems/puppet-lint-1.1.0/lib/puppet-lint.rb:118:in `print_context': undefined method `index' for nil:NilClass (NoMethodError)
    from lib/ruby/1.9.1/gems/puppet-lint-1.1.0/lib/puppet-lint.rb:138:in `block in report'
    from lib/ruby/1.9.1/gems/puppet-lint-1.1.0/lib/puppet-lint.rb:130:in `each'
    from lib/ruby/1.9.1/gems/puppet-lint-1.1.0/lib/puppet-lint.rb:130:in `report'
    from lib/ruby/1.9.1/gems/puppet-lint-1.1.0/lib/puppet-lint.rb:178:in `print_problems'
    from lib/ruby/1.9.1/gems/puppet-lint-1.1.0/lib/puppet-lint/bin.rb:60:in `block in run'
    from lib/ruby/1.9.1/gems/puppet-lint-1.1.0/lib/puppet-lint/bin.rb:56:in `each'
    from lib/ruby/1.9.1/gems/puppet-lint-1.1.0/lib/puppet-lint/bin.rb:56:in `run'
    from lib/ruby/1.9.1/gems/puppet-lint-1.1.0/bin/puppet-lint:7:in `<top (required)>'
    from bin/puppet-lint:16:in `load'
    from bin/puppet-lint:16:in `<main>'

Adding puts PuppetLint::Data.manifest_lines.inspect on line 24 of checks.rb shows:

% puppet-lint --load example.rb --only-checks example --with-context example.pp
[]
ERROR: this blows up on line 1
lib/ruby/1.9.1/gems/puppet-lint-1.1.0/lib/puppet-lint.rb:118:in `print_context': undefined method `index' for nil:NilClass (NoMethodError)
<...same error...>

The root cause is Ruby's stripping trailing nulls (link is to 2.2.0 but behavior is the same in 1.9.1).

Changing content.split("\n") to content.split("\n", -1) in checks.rb gives the expected result:

% puppet-lint --load example.rb --only-checks example --with-context example.pp

ERROR: this blows up on line 1


^
@rodjek
Copy link
Owner

rodjek commented Jan 24, 2015

Thanks, fixed! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants