rodjek / puppet-lint

Check that your Puppet manifests conform to the style guide
MIT License
820 stars 204 forks source link

Match function breaks puppet-lint #645

Closed bryanjbelanger closed 7 years ago

bryanjbelanger commented 7 years ago

The following line of code will break puppet-lint.

$some_var = $other_var.match(/([\w\.]+(:\d+)?(\/\w+)?)(:(\w+))?/)

I am running ruby version 2.3.3.

I am running puppet-lint version 2.1.1.

This is the second time I am entering this issue. See #641

I just learned the escaped slash gets dropped on submission without blocking it as code. (Which I did this time)

That is why the parser wouldn't validate.

Bryan

rnelson0 commented 7 years ago

I can't replicate this:

[rnelson0@build03 puppet-lint:master]$ cat 645.pp
class foo {
  $some_var = $other_var.match(/([\w\.]+(:\d+)?(\/\w+)?)(:(\w+))?/)
}
[rnelson0@build03 puppet-lint:master]$ be puppet-lint 645.pp
ERROR: foo not in autoload module layout on line 1
WARNING: top-scope variable being used without an explicit namespace on line 2
WARNING: class not documented on line 1
[rnelson0@build03 puppet-lint:master]$ echo $?
1

Can you define "break" in this case and maybe add some output of what you're seeing? It could also be that the breakage only occurs when inside some other markers. Can you provide the whole file, or the smallest segment that you can verify replicates for you?

bryanjbelanger commented 7 years ago

Ok... here is the smallest snippet I got.

Sorry I didn't include it before. Just commenting out that line cause things to break in my full code.

Anyway...

class foo {
  # Make sure each run images is downloaded and latest
  $runs.each | $key, $value | {
    $arr_image_name = $value['image'].match(/([\w\.]+(:\d+)?(\/\w+)?)(:(\w+))?/)

    unless defined(Docker::Image[$arr_image_name[1]]) {
      ::docker::image { $arr_image_name[1]:
        ensure    => latest,
        image_tag => $arr_image_name[5],
        notify    => [
          Exec['/bin/systemctl stop docker-cadvisor']
        ],
      }
    }
  }
}
rnelson0 commented 7 years ago

It's not the match itself but the colons. Replace them with almost any other character and it works fine. I believe it's due to this code which assumes colons precede a resource declaration. It then tries to parse the following tokens as such and eventually hits a nil one, giving:

$ be puppet-lint 645.pp
bundler: failed to load command: puppet-lint (/home/rnelson0/git/puppet-lint/vendor/ruby/2.3.0/bin/puppet-lint)
NoMethodError: undefined method `each' for nil:NilClass
  /home/rnelson0/git/puppet-lint/lib/puppet-lint/plugins/check_whitespace.rb:181:in `block (2 levels) in check'
  /home/rnelson0/git/puppet-lint/lib/puppet-lint/plugins/check_whitespace.rb:144:in `each'
  /home/rnelson0/git/puppet-lint/lib/puppet-lint/plugins/check_whitespace.rb:144:in `each_with_index'
  /home/rnelson0/git/puppet-lint/lib/puppet-lint/plugins/check_whitespace.rb:144:in `block in check'
  /home/rnelson0/git/puppet-lint/lib/puppet-lint/plugins/check_whitespace.rb:127:in `each'
  /home/rnelson0/git/puppet-lint/lib/puppet-lint/plugins/check_whitespace.rb:127:in `check'
  /home/rnelson0/git/puppet-lint/lib/puppet-lint/checkplugin.rb:21:in `run'
  /home/rnelson0/git/puppet-lint/lib/puppet-lint/checks.rb:58:in `block in run'
  /home/rnelson0/git/puppet-lint/lib/puppet-lint/checks.rb:56:in `each'
  /home/rnelson0/git/puppet-lint/lib/puppet-lint/checks.rb:56:in `run'
  /home/rnelson0/git/puppet-lint/lib/puppet-lint.rb:191:in `run'
  /home/rnelson0/git/puppet-lint/lib/puppet-lint/bin.rb:59:in `block in run'
  /home/rnelson0/git/puppet-lint/lib/puppet-lint/bin.rb:56:in `each'
  /home/rnelson0/git/puppet-lint/lib/puppet-lint/bin.rb:56:in `run'
  /home/rnelson0/git/puppet-lint/bin/puppet-lint:7:in `<top (required)>'
  /home/rnelson0/git/puppet-lint/vendor/ruby/2.3.0/bin/puppet-lint:22:in `load'
  /home/rnelson0/git/puppet-lint/vendor/ruby/2.3.0/bin/puppet-lint:22:in `<top (required)>'