puppet-lint-params_not_optional_with_undef-check
A puppet-lint plugin to check for parameters without Optional as type but undef as value.
Installing
From the command line
$ gem install puppet-lint-params_not_optional_with_undef-checkIn a Gemfile
gem 'puppet-lint-params_not_optional_with_undef-check', require: falseChecks
Parameter assigned to the empty string
According the the Vox Pupuli best practices, a class parameter with the string
datatype should default to undef and not '', if it's optional. The
recommendations are documented at voxpupuli.org.
What you have done
class foo (
String $bar = undef,
) {
# logic
}What you should have done
class foo (
Optional[String[1]] $bar = undef,
) {
# logic
}or:
class foo (
String[1] $bar = 'value',
) {
# logic
}Disabling the check
To disable this check, you can add --no-params_not_optional_with_undef-check to your puppet-lint command line.
$ puppet-lint --no-empty_string_assignment-check path/to/file.ppAlternatively, if you’re calling puppet-lint via the Rake task, you should insert the following line to your Rakefile.
PuppetLint.configuration.send('params_not_optional_with_undef')You can also disable it inline:
class foo (
String $baz = '', # lint:ignore:params_empty_string_assignment
) {
# awesome logic here
}Transfer Notice
This plugin was originally authored by Tim 'bastelfreak' Meusel. The maintainer preferred that Vox Pupuli take ownership of the module for future improvement and maintenance.
License
This gem is licensed under the MIT license.
Release information
To make a new release, please do:
- update the version in the gemspec file
- Install gems with
bundle install --with release --path .vendor - generate the changelog with
bundle exec rake changelog - Check if the new version matches the closed issues/PRs in the changelog
- Create a PR with it
- After it got merged, push a tag. GitHub actions will do the actual release to rubygems and GitHub Packages