puppetlabs / puppet-lint

Check that your Puppet manifests conform to the style guide
https://puppetlabs.github.io/puppet-lint/
MIT License
18 stars 12 forks source link

Notify problem #192

Closed marek130 closed 3 months ago

marek130 commented 4 months ago

Describe the Bug

When a manifest contains notify {"${notify}": } , the puppet lint is failing. The variable name notify should be ok because it is not keyword if I am correct.

Expected Behavior

Running validation with autofix correctly

Steps to Reproduce

Steps to reproduce the behavior: 1.write a manifest

  1. run pdk validate -a

puppet-lint version: 4.0.0 ruby version: 2.7.8-p225 platform: x86_64-linux file path: manifests/audit.pp file contents:

# @summary A short summary of the purpose of this class
#
# A description of what this class does
#
# @example
#   include logrotate::audit
class logrotate::audit (
  String $file_path = undef,
  # add this class definition to ../modules/profile/manifests/base/sles.pp
  # include logrotate:audit
) {
  include logrotate::sles
  include logrotate::rhel
  include logrotate::ubuntu

  if $facts['os']['name'] in ['SLES','Ubuntu','RedHat'] {
    $service_name = 'auditd.service'
    $notify       = Service[$service_name]
  } else {
    $notify = undef
  }

  notify {"${notify}": }

#  file { "${file_path}":
#    ensure   => 'present',
#    mode     => '0644',
#    group    => 'root',
#    owner    => 'root',
#    source   => 'puppet:///modules/logrotate/audit/audit',
#    require  => Package['logrotate'],
#  }

#  file_line { 'disable-auditd-logrotate':
#    ensure  => present,
#    path    => '/etc/audit/auditd.conf',
#    line    => 'max_log_file_action = ignore',
#    match   => '^max_log_file_action\ =',
#    notify   => $notify,
#  }
}

error:

NoMethodError: undefined method `-' for nil:NilClass
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-4.0.0/lib/puppet-lint/data.rb:67:in `insert'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-4.0.0/lib/puppet-lint/checkplugin.rb:62:in `add_token'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-manifest_whitespace-check-0.3.0/lib/puppet-lint/plugins/check_manifest_whitespace_opening_brace.rb:87:in `fix'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-4.0.0/lib/puppet-lint/checkplugin.rb:42:in `block in fix_problems'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-4.0.0/lib/puppet-lint/checkplugin.rb:38:in `each'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-4.0.0/lib/puppet-lint/checkplugin.rb:38:in `fix_problems'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-4.0.0/lib/puppet-lint/checks.rb:67:in `block in run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-4.0.0/lib/puppet-lint/checks.rb:65:in `each'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-4.0.0/lib/puppet-lint/checks.rb:65:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-4.0.0/lib/puppet-lint.rb:226:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-4.0.0/lib/puppet-lint/bin.rb:85:in `block in run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-4.0.0/lib/puppet-lint/bin.rb:80:in `each'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-4.0.0/lib/puppet-lint/bin.rb:80:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-4.0.0/bin/puppet-lint:7:in `<top (required)>'
/etc/puppetlabs/code/environments/s5muu6_cleanup/modules/logrotate/bin/puppet-lint:27:in `load'
/etc/puppetlabs/code/environments/s5muu6_cleanup/modules/logrotate/bin/puppet-lint:27:in `<main>'
ekohl commented 4 months ago

/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/puppet-lint-manifest_whitespace-check-0.3.0/lib/puppet-lint/plugins/check_manifest_whitespace_opening_brace.rb:87:in `fix'

I think this is actually in https://github.com/voxpupuli/puppet-lint-manifest_whitespace-check and in particular here: https://github.com/voxpupuli/puppet-lint-manifest_whitespace-check/blob/527d8690bd90d88bf4a9fb0f911b82a29e579813/lib/puppet-lint/plugins/check_manifest_whitespace_opening_brace.rb#L90

It wants to correct this part:

  notify {"${notify}": }

To:

  notify { "${notify}": }

Somehow that fails. It may very well be fixed with https://github.com/voxpupuli/puppet-lint-manifest_whitespace-check/commit/0697e65dcb032b95a38da839c9d166198ad5958e that's currently unreleased.

pmcmaw commented 3 months ago

Hey @marek130 it seems the fix as @ekohl has mentioned above has now been released. I am going to close this issue, however if you disagree, please accept my apology and feel free to reopen.

Thank you for flagging this issue to us, the team really appreciate your input.