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

plugin does not ignore heredoc indentation #20

Open
bastelfreak opened this issue Jul 25, 2020 · 8 comments
Open

plugin does not ignore heredoc indentation #20

bastelfreak opened this issue Jul 25, 2020 · 8 comments

Comments

@bastelfreak
Copy link
Member

Hi,
in the voxpupuli/puppet-nginx module we've got the following code:

class { 'nginx':
  snippets_dir        => '/etc/nginx/snippets',
}

$snippet = @("SNIPPET"/L)
location @custom_451_error {
  return 451;
}
| SNIPPET

which produces the following error:

examples/snippet.pp:6:strict_indent:FIXED:indent should be 2 chars and is 1

I'm not sure if this is easily to fix, at the moment I simply disabled the plugin for those lines.

@jhoblitt
Copy link
Member

jhoblitt commented Aug 5, 2020

I've run into problems with heredocs as well with 2.0.7.

diff --git a/site/profile/manifests/ccs/autologin.pp b/site/profile/manifests/ccs/autologin.pp
index aae61cf8..d2a666a1 100644
--- a/site/profile/manifests/ccs/autologin.pp
+++ b/site/profile/manifests/ccs/autologin.pp
@@ -13,7 +13,7 @@ class profile::ccs::autologin (Boolean $enable = true) {
       path    => ['/usr/bin'],
       unless  => 'grep -q ^AutomaticLogin /etc/gdm/custom.conf',
       command => @("CMD"/L),
-        sed -i '/^\[daemon.*/a\\
+                sed -i '/^\[daemon.*/a\\
         AutomaticLogin=ccs\n\
         AutomaticLoginEnable=true' /etc/gdm/custom.conf
         | CMD
diff --git a/site/profile/manifests/ccs/daq4.pp b/site/profile/manifests/ccs/daq4.pp
index b42b9525..72c5fd39 100644
--- a/site/profile/manifests/ccs/daq4.pp
+++ b/site/profile/manifests/ccs/daq4.pp
@@ -16,7 +16,7 @@ class profile::ccs::daq4 ($instrument = 'comcam') {
   file { "${dir}/${daq4file}":
     ensure  => file,
     content => @(EOF),
-      export DAQ_HOME=/srv/nfs/lsst-daq/daq-sdk/current/
+                  export DAQ_HOME=/srv/nfs/lsst-daq/daq-sdk/current/
       export LD_LIBRARY_PATH=$DAQ_HOME/x86/lib:$LD_LIBRARY_PATH
       | EOF
     *       => $attributes,

@jhoblitt
Copy link
Member

jhoblitt commented Aug 5, 2020

Note that lint will continue to complain about the heredoc even after an "autofix".

@yakirgb
Copy link

yakirgb commented Jul 24, 2022

Facing same bug

@antenore
Copy link

antenore commented Jan 6, 2023

We are facing something similar.

    command => @("EOT"),
      echo "Hello"
      | EOT
[{
	"owner": "_generated_diagnostic_collection_name_#0",
	"code": "strict_indent",
	"severity": 4,
	"message": "indent should be 6 chars and is 0",
	"source": "Puppet",
	"startLineNumber": 237,
	"startColumn": 1,
	"endLineNumber": 237,
	"endColumn": 31
}]

If I remove the trailing comma, the indentation check passes, and obviously the comma check doesn't (that is normal), but to me, it's because this plugin doesn't properly handle the HEREDOC_OPEN and HEREDOC_POST tokens, setting everything to the same value, when it should handle the trailing comma and eventually other similar cases.

Unfortunately I'm unable to propose a patch at the moment as I should understand more deeply the code... I'm very sorry, but I hope this will help someone else.

For now, I'm disabling strict_indent using the puppet-lint comments (because vscode ignores the file .puppet-lint.rc :-\ )

# lint:ignore:strict_indent
command => @("EOT"),
  echo "Hello"
  | EOT
# lint:endignore

@davidsandilands
Copy link
Member

This generates an error for me

  $pg_basebackup = @("PGBASE")
    runuser -u pe-postgres -- \
      /opt/puppetlabs/server/bin/pg_basebackup \
        -D /opt/puppetlabs/server/data/postgresql/${psql_version}/data \
        -d "host=${source_host}
            user=pe-ha-replication
            sslmode=verify-full
            sslcert=/opt/puppetlabs/server/data/pg_certs/_local.cert.pem
            sslkey=/opt/puppetlabs/server/data/pg_certs/_local.private_key.pem
            sslrootcert=/etc/puppetlabs/puppet/ssl/certs/ca.pem"
    | - PGBASE

That I haven't been able to find a workaround for.

NoMethodError: undefined method `prev_token' for nil:NilClass
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-strict_indent-check-2.1.0/lib/puppet-lint/plugins/check_strict_indent.rb:137:in `block in check'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-strict_indent-check-2.1.0/lib/puppet-lint/plugins/check_strict_indent.rb:49:in `each'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-strict_indent-check-2.1.0/lib/puppet-lint/plugins/check_strict_indent.rb:49:in `check'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/checkplugin.rb:21:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/checks.rb:61:in `block in run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/checks.rb:58:in `each'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/checks.rb:58:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint.rb:205:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/bin.rb:66:in `block in run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/bin.rb:62:in `each'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/lib/puppet-lint/bin.rb:62:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-2.5.2/bin/puppet-lint:7:in `<top (required)>'
/mnt/c/Users/David Sandilands/code/puppetlabs-peadm/bin/puppet-lint:29:in `load'
/mnt/c/Users/David Sandilands/code/puppetlabs-peadm/bin/puppet-lint:29:in `<main>'

@bassonj
Copy link

bassonj commented Jun 30, 2023

I think in the example given the end marker needs to be intended
like this

$snippet = @("SNIPPET"/L)
  location @custom_451_error {
    return 451;
  }
  | SNIPPET

reference: https://www.puppet.com/docs/puppet/6/lang_data_string.html#lang_data_string_heredocs-example

gerlingsm added a commit to gerlingsm/puppet-lint-strict_indent-check that referenced this issue May 13, 2024
In some cases, the HEREDOC_OPEN is not followed directly by the content of the HEREDOC, but first by a COMMA

voxpupuli#20 (comment)
@bzed
Copy link

bzed commented Sep 12, 2024

Its really sad to see that this bug is 4 years old now and still not fixed.

@bastelfreak
Copy link
Member Author

@bzed can you provide a patch for this?

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

No branches or pull requests

8 participants