rodjek / puppet-lint

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

Lint failure on reduce function #869

Closed eliaoggian closed 5 years ago

eliaoggian commented 5 years ago

As suggestet by the pdk, I open this issue for the following error.

puppet-lint version: 2.3.6 ruby version: 2.5.3-p105 platform: x86_64-linux file path: manifests/users.pp file contents:

# Classe per gestire login per utenti sui server
class profile::users($users = lookup('users', Data, 'hash', false )){

  if ($users != false) {

    $filtered = $users.reduce({}) | $memo, $entry | {
      if $users[$entry[0]][groups] != undef {
        $memo + {
          $entry[0] => $users[$entry[0]] + { groups => $users[$entry[0]][groups].filter | $group | { $group in $facts['linux_groups'] } }
        }
      } else {
    $memo + { $entry[0] => $users[$entry[0]] }
  }
    }

    create_resources(user, $filtered, { 'managehome' => true, 'membership' => 'inclusive', 'shell' => '/bin/bash'})

  }
}

# Classe per gestire login per utenti sui server Geco
class profile::users::geco($users = lookup('users_geco', Data, 'hash', false )){

  if ($users != false) {

    $filtered = $users.reduce({}) | $memo, $entry | {
      if $users[$entry[0]][groups] != undef {
        $memo + {
          $entry[0] => $users[$entry[0]] + { groups => $users[$entry[0]][groups].filter | $group | { $group in $facts['linux_groups'] } }
        }
      } else {
        $memo + { $entry[0] => $users[$entry[0]] }
      }
    }

    create_resources(user, $filtered, { 'managehome' => true, 'membership' => 'inclusive', 'shell' => '/bin/bash'})

  }
}

error:

NoMethodError: undefined method `prev_token' for nil:NilClass
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:196:in `find_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:156:in `prev_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:191:in `find_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:156:in `prev_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:191:in `find_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:156:in `prev_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:189:in `find_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:156:in `prev_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:189:in `find_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:156:in `prev_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:189:in `find_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:156:in `prev_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:191:in `find_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:156:in `prev_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:189:in `find_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:156:in `prev_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:189:in `find_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:156:in `prev_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:189:in `find_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:156:in `prev_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:189:in `find_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:156:in `prev_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:189:in `find_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/lexer/token.rb:156:in `prev_token_of'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/plugins/check_classes/parameter_order.rb:44:in `required_parameter?'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/plugins/check_classes/parameter_order.rb:25:in `block (2 levels) in check'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/plugins/check_classes/parameter_order.rb:13:in `each'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/plugins/check_classes/parameter_order.rb:13:in `each_with_index'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/plugins/check_classes/parameter_order.rb:13:in `block in check'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/plugins/check_classes/parameter_order.rb:8:in `each'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/plugins/check_classes/parameter_order.rb:8:in `check'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/checkplugin.rb:21:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/checks.rb:61:in `block in run'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/checks.rb:58:in `each'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/checks.rb:58:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint.rb:205:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/bin.rb:66:in `block in run'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/bin.rb:62:in `each'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/lib/puppet-lint/bin.rb:62:in `run'
/opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/puppet-lint-2.3.6/bin/puppet-lint:7:in `<top (required)>'
/home/eoc09018/Desktop/control/site/profile/bin/puppet-lint:29:in `load'
/home/eoc09018/Desktop/control/site/profile/bin/puppet-lint:29:in `<main>'
usev6 commented 5 years ago

The internal error seems to be fixed with 8a9091a998. On HEAD (dc9da8aac1) I only get a warning from the autoloader_layout check for the second class (given that I named the file correctly for the first class).

This looks closable to me.

rodjek commented 5 years ago

Confirmed fixed