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

Multiple heredocs with same token cause linter to fail #137

Open
bmagistro opened this issue Jul 26, 2023 · 1 comment
Open

Multiple heredocs with same token cause linter to fail #137

bmagistro opened this issue Jul 26, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@bmagistro
Copy link

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>'
@bmagistro bmagistro added the bug Something isn't working label Jul 26, 2023
@bmagistro
Copy link
Author

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.

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

No branches or pull requests

1 participant