A puppet-lint plugin to check that Optional
parameters don't default to something other than undef
.
$ gem install puppet-lint-optional_default-check
gem 'puppet-lint-optional_default-check', :require => false
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.
class foo (
Optional[Integer] $port = 8080,
){
}
class foo (
Integer $port = 8080,
){
}
or
class foo (
Optional[Integer] $port = undef,
){
}
Copyright 2021 Alexander Fisher
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.
This gem is licensed under the MIT license.
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