puppetlabs / puppet-lint

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

puppet-lint stops validating when finding a blank line following a line with only spaces and a single quote #134

Open rnelson0 opened 1 year ago

rnelson0 commented 1 year ago

Running pdk validate -a against a controlrepo generates the following error. When this occurs, it stops and does not validate other files. Remove the blank line at the end resolves the error with this file, and it is validated properly. However, an issue is encountered on the next file that has that blank line issue as well, stopping again.

Thus I see two problems here:

error:

TypeError: no implicit conversion from nil to integer C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-trailing_comma-check-1.0.0/lib/puppet-lint/plugins/check_trailing_comma.rb:145:in insert' C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-trailing_comma-check-1.0.0/lib/puppet-lint/plugins/check_trailing_comma.rb:145:infix' C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checkplugin.rb:42:in block in fix_problems' C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checkplugin.rb:38:ineach' C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checkplugin.rb:38:in fix_problems' C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:67:inblock in run' C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:65:in each' C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:65:inrun' C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint.rb:224:in run' C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:84:inblock in run' C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:80:in each' C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:80:inrun' C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/bin/puppet-lint:7:in <top (required)>' C:/Users/username/git/controlrepo/bin/puppet-lint:27:inload' C:/Users/username/git/controlrepo/bin/puppet-lint:27:in `

'

rnelson0 commented 1 year ago

Complicating factors:

So it could be related to those plugins, or the upgrade to pdk3.0.0, or both.

rnelson0 commented 1 year ago

I can replicate this on a smaller file as well, definitely seems related to the single quote/empty following line


puppet-lint version: 3.4.0 ruby version: 3.2.2-p53 platform: x64-mingw32 file path: site/profile/manifests/windows/install_gmsa.pp file contents:

# Profile to add a Group Managed Service Account to a computer. This simply installs the MSA to the computer, you still have to specify
# it in a service.
class profile::windows::install_gmsa (
  String $service_account,
) {
  if (!defined(Windowsfeature['RSAT-AD-PowerShell'])) {
    windowsfeature { 'RSAT-AD-PowerShell':
      ensure => present,
    }
  }

  exec { 'install-gmsa-account':
    provider    => powershell,
    environment => ["gmsa_account=${service_account}"],
    logoutput   => false,
    onlyif      => '
      If (Test-ADServiceAccount -Identity $Env:gmsa_account)
      {
        Exit 1
      }
      Exit 0
    ',
    command     => '
      Try {
        Install-ADServiceAccount -Identity $Env:gmsa_account -ErrorAction Stop
      }
    '

  }
}

error:

TypeError: no implicit conversion from nil to integer
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-trailing_comma-check-1.0.0/lib/puppet-lint/plugins/check_trailing_comma.rb:145:in `insert'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-trailing_comma-check-1.0.0/lib/puppet-lint/plugins/check_trailing_comma.rb:145:in `fix'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checkplugin.rb:42:in `block in fix_problems'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checkplugin.rb:38:in `each'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checkplugin.rb:38:in `fix_problems'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:67:in `block in run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:65:in `each'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:65:in `run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint.rb:224:in `run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:84:in `block in run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:80:in `each'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:80:in `run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/bin/puppet-lint:7:in `<top (required)>'
C:/Users/username/git/controlrepo/bin/puppet-lint:27:in `load'
C:/Users/username/git/controlrepo/bin/puppet-lint:27:in `<main>'