Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Puppet-lint 1.0.0 released

Puppet-lint 1.0.0 released

This item in japanese

Tim Sharpe has announced the release of Puppet lint 1.0.0, a tool to check that Puppet code conforms to the recommended Puppet style guidelines and find common syntax mistakes, which in this new version includes a plugin system and the capability of automatically fixing the errors amongst other new features and bug fixes.

Plugin system

The new plugin system allows the addition of custom checks that can be distributed as Ruby gems. The list of community plugins is small but could continue to grow, and a tutorial with an example plugin are available for those willing to create their own plugins.

The checks can be implemented in Ruby with a check method, and optionally a fix method to automatically apply the recommended syntax, as demonstrated in the example plugin. Puppet-lint also includes a testing API that can be used with RSpec to test the check and fix behavior.

Automatic fixing of errors

Failures reported by some of the checks can be automatically fixed, by using puppet-lint --fix, and this is possible for both core checks and checks implemented in plugins. To fix only problems for some specific checks, the new --only-checks parameter can be used with --fix, e.g. puppet-lint --fix --only-checks arrow_alignment manifests.

Some of the checks that allow automatic fixing include:

  • arrow_alignment: arrows (=>) within blocks of attributes should be aligned with the other arrows in that block.
  • file_mode: file modes should be represented in octal as 4 digits rather than 3, or symbolically e.g. u=rw,g=r.
  • ensure_not_symlink_target: symbolic links should use ensure => link and a value for the target attribute.
  • double_quoted_strings: all strings that do not contain variables should be enclosed in single quotes.
  • variables_not_enclosed: all variables should be enclosed in in braces ({}) when being interpolated in a string.

Two new checks are included in Puppet-lint core to address other style and syntax common mistakes:

  • unquoted_node_name: check for unquoted node names.
  • puppet_url_without_modules: check for fileserver URLs without the modules mountpoint.

Also, the class_parameter_defaults check has been removed, as it was based on a misreading of the style guide.

Control comments

Tests can now be disabled by using special comments in the code. Code between #lint:ignore:check_name and #lint:endignore will be ignored. For instance, to ignore the double_quoted_strings check:

class foo {
  $bar = 'bar'
  # lint:ignore:double_quoted_strings
  $baz = "baz"
  $gronk = "gronk"
  # lint:endignore

Single lines can be ignored by just appending the #lint:ignore:check_name comment:

$this_line_has_a_really_long_name_and_value = "[snip]" # lint:ignore:80chars

New command line parameters

Some new parameters are added to the command line besides --fix:

  • --relative: compare module layout relative to the module root, making autoloader_layout check ignore the top-most directory, useful when module folder is different than the module name, e.g. puppet-module.
  • --show-ignored: display which problems are being ignored.
  • -c/--config: specify a custom path to puppet-lint.rc, a script with command line options, by default read from /etc/puppet-lint.rc.
  • --with-context: print out the line of the manifest with a marker pointing to the exact location of the detected problem.

Puppet-lint can be installed as a Ruby gem, and used from the command line or typically as a Rake task in a Rakefile, where it can be customized too. The tool is used, amongst others, by Puppet Labs to test the Puppet Forge supported modules.

Rate this Article