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

Multiple heredocs with same token cause linter to fail

bmagistro opened this issue · comments

Describe the Bug

If a manifest file contains more than one heredoc with the same "token" the linter is unable to track and errors out.

Expected Behavior

Ideally the linter would be able to track each token pair in the heredocs. as a work around, the token can be changed in subsequent pairs.

Environment

  • puppet-lint version: 2.5.2
  • ruby version: 2.7.4-p191
  • platform: x86_64-linux
  • pdt docker (2023-03-07-1bca42e) w/ plugins (absolute_classname, file_ensure, manifest_whitespace, numericvariable, strict_indent)

Additional Context

command: puppet-lint --no-variable_scope-check --no-documentation-check --no-autoloader_layout-check --log-format "%{path}:%{line}:%{check}:%{KIND}:%{message}" ./manifests/

minimal file to reproduce

class profiles::mirror::share_rsync (
) {
  $script = @("EOF")
    #!/bin/bash
    # this is managed by puppet -- do not edit
    while [[ true ]]; do
        rsync -avz --delete --log-format="%i %f B:%l md5:%C" /a /b
        sleep 5
    done
    | EOF
  file { '/usr/local/bin/rsync.sh':
    ensure  => 'file',
    owner   => 'root',
    group   => 'root',
    mode    => '0755',
    content => $script,
  }

  $script_systemd = @("EOF")
    # this is managed by puppet -- do not edit
    WantedBy=multi-user.target
    | EOF 
  systemd::unit_file { 'mirror_rsync.service' :
    content   => $script_systemd,
    enable    => true,
    active    => true,
    require   => File['/usr/local/bin/rsync.sh'],
    subscribe => File['/usr/local/bin/rsync.sh'],
  }
}

workaround file

class profiles::mirror::share_rsync (
) {
  $script = @("EOF01")
    #!/bin/bash
    # this is managed by puppet -- do not edit
    while [[ true ]]; do
        rsync -avz --delete --log-format="%i %f B:%l md5:%C" /a /b
        sleep 5
    done
    | EOF01
  file { '/usr/local/bin/rsync.sh':
    ensure  => 'file',
    owner   => 'root',
    group   => 'root',
    mode    => '0755',
    content => $script,
  }

  $script_systemd = @("EOF02")
    # this is managed by puppet -- do not edit
    WantedBy=multi-user.target
    | EOF02
  systemd::unit_file { 'mirror_rsync.service' :
    content   => $script_systemd,
    enable    => true,
    active    => true,
    require   => File['/usr/local/bin/rsync.sh'],
    subscribe => File['/usr/local/bin/rsync.sh'],
  }
}

backtrace/error log

NoMethodError: undefined method `prev_token' for nil:NilClass
/usr/local/bundle/gems/puppet-lint-strict_indent-check-2.1.0/lib/puppet-lint/plugins/check_strict_indent.rb:137:in `block in check'
/usr/local/bundle/gems/puppet-lint-strict_indent-check-2.1.0/lib/puppet-lint/plugins/check_strict_indent.rb:49:in `each'
/usr/local/bundle/gems/puppet-lint-strict_indent-check-2.1.0/lib/puppet-lint/plugins/check_strict_indent.rb:49:in `check'
/usr/local/bundle/gems/puppet-lint-2.5.2/lib/puppet-lint/checkplugin.rb:21:in `run'
/usr/local/bundle/gems/puppet-lint-2.5.2/lib/puppet-lint/checks.rb:61:in `block in run'
/usr/local/bundle/gems/puppet-lint-2.5.2/lib/puppet-lint/checks.rb:58:in `each'
/usr/local/bundle/gems/puppet-lint-2.5.2/lib/puppet-lint/checks.rb:58:in `run'
/usr/local/bundle/gems/puppet-lint-2.5.2/lib/puppet-lint.rb:205:in `run'
/usr/local/bundle/gems/puppet-lint-2.5.2/lib/puppet-lint/bin.rb:66:in `block in run'
/usr/local/bundle/gems/puppet-lint-2.5.2/lib/puppet-lint/bin.rb:62:in `each'
/usr/local/bundle/gems/puppet-lint-2.5.2/lib/puppet-lint/bin.rb:62:in `run'
/usr/local/bundle/gems/puppet-lint-2.5.2/bin/puppet-lint:7:in `<top (required)>'
/usr/local/bundle/bin/puppet-lint:23:in `load'
/usr/local/bundle/bin/puppet-lint:23:in `<main>'

Digging further, this appears to result from trailing whitespace on the closing heredoc tag which was either missed/corrected when updating the tokens. If the closing token is EOF<space> but the opening is @("EOF") the above scenario should trigger.