The goal of this project is to implement as many of the recommended Puppet
style guidelines from the Puppet Labs style
guide as practical. It is not meant to validate syntax. Please use puppet parser validate
for that.
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.
- An exception has been made for resource titles that consist of only a variable standing by itself.
- 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 or use symbolic file modes.
- 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.
WARNING: right-to-left (<-) relationship on line X
While right to left relationships are perfectly valid, it's highly recommended that you don't use them as most people think and read from left to right and this can lead to confusion.
Bad:
Service['httpd'] <- Package['httpd']
Good:
Package['httpd'] -> Service['httpd']
ERROR: mymodule::myclass not in autoload module layout on line X
Puppet attempts to autoload only the required manifests for the resources and
classes specified in your manifests. In order to do this, the autoloader
expects your manifests to be laid out on disk in a particular format. For
example, when you use mymodule::myclass
in your manifests, Puppet will
attempt to read <modulepath>/mymodule/manifests/myclass.pp
. The only
exception to this is when you reference mymodule
itself (without any
subclass/subtype) in which case it will read
<modulepath>/mymodule/manifests/init.pp
.
WARNING: optional parameter listed before required parameter on line X
In parameterised class and defined type definitions, parameters that are required should be listed before optional parameters (those with default values).
Bad:
class foo($bar='baz', $gronk) {
Good:
class foo($gronk, $bar='baz') {
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
You can disable any of the checks when running the puppet-lint
command by
adding a --no-<check name>-check
flag to the command. For example, if you
wanted to skip the 80 character check, you would run
puppet-lint --no-80chars-check /path/to/my/manifest.pp
puppet-lint will also check for a .puppet-lint.rc
file in the current
directory and your home directory and read in flags from there, so if you
wanted to always skip the hard tab character check, you could create
~/.puppet-lint.rc
containing
--no-hard_tabs-check
For a list of all the flags just type:
puppet-lint --help
You can also disable checks when running puppet-lint through the supplied Rake
task. Simply add the following line after the require
statement in your
Rakefile
.
PuppetLint.configuration.send("disable_<check name>")
So, to disable the 80 character check, you would add:
PuppetLint.configuration.send("disable_80chars")
The Rake task also supports ignoring certain paths from being linted:
PuppetLint.configuration.ignore_paths = ["vendor/**/*.pp"]
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.
Many thanks to the following people for contributing to puppet-lint
- James Turnbull (@kartar)
- Jan Vansteenkiste (@vStone)
- Julian Simpson (@simpsonjulian)
- S. Zachariah Sprackett (@zsprackett)
As well as the many people who have reported the issues they've had!
Copyright (c) 2011 Tim Sharpe
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.