No release in over a year
A puppet-lint plugin to check that Optional class/defined type parameters don't default to anything other than `undef`.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 3, < 5
 Project Readme

puppet-lint-optional_default-check

License Test Release RubyGem Version RubyGem Downloads Donated by Alexander Fisher

A puppet-lint plugin to check that Optional parameters don't default to something other than undef.

Table of contents

  • Installing
    • From the command line
    • In a Gemfile
  • Checks
  • Copyright
  • Transfer notice
  • License
  • Release Informaion

Installing

From the command line

$ gem install puppet-lint-optional_default-check

In a Gemfile

gem 'puppet-lint-optional_default-check', :require => false

Checks

Optional parameter defaults to something other than undef

An Optional parameter in Puppet is one where undef is an allowed value.

It is normally a mistake to set the default of an Optional parameter to something other than undef. This is because it's not possible to 'pass' undef as the value to use for a parameter when declaring a class or defined type. When you try to set a parameter to undef, Puppet actually uses the class's default value for that parameter, not undef itself.

(The caveat is that it is possible to use hiera to override a non undef default back to undef, but in practice, doing this is quite rare.)

A defined type with an mandatory (no default), Optional parameter will raise a warning.

The plugin will not raise a warning if a class Optional parameter doesn't have a default. Mandatory parameters can have defaults set in hiera, and several modules do use ~ for this.

What you have done

class foo (
  Optional[Integer] $port = 8080,
){
}

What you should have done

class foo (
  Integer $port = 8080,
){
}

or

class foo (
  Optional[Integer] $port = undef,
){
}

Copyright

Copyright 2021 Alexander Fisher

Transfer Notice

This plugin was originally authored by Alexander Fisher. The maintainer preferred that Vox Pupuli take ownership of the module for future improvement and maintenance. Existing pull requests and issues were transferred, please fork and continue to contribute here instead of on Alex's fork.

License

This gem is licensed under the MIT license.

Release information

To make a new release, please do:

  • Update the version in the puppet-lint-optional_default-check.gemspec file
  • Install gems with bundle install --with release --path .vendor
  • generate the changelog with bundle exec rake changelog
  • Create a PR with it
  • After it got merged, push a tag. A github workflow will do the actual release