The goal of this project is to implement as many of the recommended Puppet style guidelines from the Puppet Labs style guide as practical.
gem install puppet-lint
You can test a single manifest file by running
puppet-lint <path to file>
If you want to test your entire Puppet manifest directory, you can add
require 'puppet-lint/tasks/puppet-lint'
to your Rakefile and then run
rake lint
At the moment, the following tests have been implemented:
- Must use two-space soft tabs.
- Must not use literal tab characters.
- Must not contain trailing white space.
- Should not exceed an 80 character line width
- An exception has been made for
source => 'puppet://...'
lines as splitting these over multiple lines decreases the readability of the manifests.
- An exception has been made for
- Should align arrows (
=>
) within blocks of attributes.
- All strings that do not contain variables should be enclosed in single
quotes.
- An exception has been made for double quoted strings containing \n or \t.
- All strings that contain variables must be enclosed in double quotes.
- All variables should be enclosed in braces when interpolated in a string.
- Variables standing by themselves should not be quoted.
- All resource titles should be quoted.
- If a resource declaration includes an
ensure
attribute, it should be the first attribute specified. - Symbolic links should be declared by using an ensure value of
link
and explicitly specifying a value for thetarget
attribute. - File modes should be represented as a 4 digit string enclosed in single quotes.
- You should not intermingle conditionals inside resource declarations (i.e. selectors inside resources).
- Case statements should have a default case.
- Relationship declarations with the chaining syntax should only be used in the 'left to right' direction.
- Classes should not be defined inside a class.
- Defines should not be defined inside a class.
- Classes should not inherit between namespaces.
- Required parameters in class & defined type definitions should be listed before optional parameters.
- When using top-scope variables, including facts, Puppet modules should explicitly specify the empty namespace.
If you find a bug in puppet-lint or its results, please create an issue in the repo issues tracker. Bonus points will be awarded if you also include a patch that fixes the issue.