GithubHelp home page GithubHelp logo

puppet-lint's Introduction

Puppet Lint


Note that as of release 2.5.0, this project is being maintained in the main puppetlabs namespace.


Build Status Inline docs

Puppet Lint tests Puppet code against the recommended Puppet language style guide. Puppet Lint validates only code style; it does not validate syntax. To test syntax, use Puppet's puppet parser validate command.

Compatibility warning

Puppet Lint version 2 is the last planned version with support for Puppet 3 and Ruby 1.8.7. The next major version of Puppet Lint will drop support for these versions.

Installation

Install the Puppet Lint gem by running:

gem install puppet-lint

Testing with Puppet Lint

To test manifests for correct Puppet style, run the puppet-lint command with the path to the files you want to test.

For example:

puppet-lint ~/modules/puppetlabs-java/manifests/init.pp
puppet-lint ~/modules/puppetlabs-mysql/manifests

Fix issues automatically

To instruct Lint to automatically fix any issues that it detects, use the --fix flag:

puppet-lint --fix /modules

Modify which checks to run

Puppet Lint options allow you to modify which checks to run. You can disable any of the checks temporarily or permanently, or you can limit testing to specific checks.

List all available checks

To list all available checks along with basic usage documentation, use the --list-checks option.

Run specific checks

To run only specific checks, use the --only-checks option, with a comma-separated list of arguments specifying which checks to make:

puppet-lint --only-checks trailing_whitespace,140chars modules/

To avoid enormous patch sets when using the --fix flag, use the --only-checks option to limit which checks Puppet Lint makes:

puppet-lint --only-checks trailing_whitespace --fix modules/

Disable Lint checks

You can disable specific Lint checks on the command line, disable them permanently with a configuration file, or disable them with control comments within your Puppet code.

Disable checks on the command line

To disable any of the checks when running the puppet-lint command, add a --no-<check_name>-check flag to the command. For example, to skip the 140-character check, run:

puppet-lint --no-140chars-check modules/

Disable checks within Puppet code

To disable checks from within your Puppet code itself, use control comments. Disable checks on either a per-line or per-block basis using #lint:ignore:<check_name>.

For example:

class foo {
  $bar = 'bar'

  # This ignores the double_quoted_strings check over multiple lines

  # lint:ignore:double_quoted_strings
  $baz = "baz"
  $gronk = "gronk"
  # lint:endignore

  # This ignores the 140chars check on a single line

  $this_line_has_a_really_long_name_and_value_that_is_much_longer_than_the_style_guide_recommends = "I mean, a really, really long line like you can't believe" # lint:ignore:140chars
}

Configuration file

Each time Puppet Lint starts up, it loads configuration from three files in order:

  1. /etc/puppet-lint.rc
  2. ~/.puppet-lint.rc
  3. .puppet-lint.rc

This means that a flag in the local .puppet-lint.rc will take precedence over a flag in the global /etc/puppet-lint.rc, for example. Flags specified on the command line take final precedence and override all config file options.

Any flag that can be specified on the command line can also be specified in the configuration file. For example, to always skip the hard tab character check, create ~/.puppet-lint.rc and include the line:

--no-hard_tabs-check

Or to specify a whitelist of allowed checks, include a line like:

--only-checks=trailing_whitespace,hard_tabs,duplicate_params,double_quoted_strings,unquoted_file_mode,only_variable_string,variables_not_enclosed,single_quote_string_with_variables,variable_contains_dash,ensure_not_symlink_target,unquoted_resource_title,relative_classname_inclusion,file_mode,resource_reference_without_title_capital,leading_zero,arrow_alignment,variable_is_lowercase,ensure_first_param,resource_reference_without_whitespace,file_ensure,trailing_comma,leading_zero

Please note that there is an important difference between reading options from the command line and reading options from a configuration file: In the former case the shell interprets one level of quotes. That does not happen in the latter case. So, it would make sense to quote some configuration values on the command line, like so:

$ puppet-lint --ignore-paths 'modules/stdlib/*' modules/

When reading from a configuration file those quotes would be passed on to the option parser -- probably not giving the expected result. Instead the line should read

--ignore-paths=modules/stdlib/*

Testing with Puppet Lint as a Rake task

To test your entire Puppet manifest directory, add require 'puppet-lint/tasks/puppet-lint' to your Rakefile and then run:

rake lint

To modify the default behaviour of the Rake task, modify the Puppet Lint configuration by defining the task yourself. For example:

PuppetLint::RakeTask.new :lint do |config|
  # Pattern of files to check, defaults to `**/*.pp`
  config.pattern = 'modules'

  # Pattern of files to ignore
  config.ignore_paths = ['modules/apt', 'modules/stdlib']

  # List of checks to disable
  config.disable_checks = ['documentation', '140chars']

  # Should puppet-lint prefix it's output with the file being checked,
  # defaults to true
  config.with_filename = false

  # Should the task fail if there were any warnings, defaults to false
  config.fail_on_warnings = true

  # Format string for puppet-lint's output (see the puppet-lint help output
  # for details
  config.log_format = '%{filename} - %{message}'

  # Print out the context for the problem, defaults to false
  config.with_context = true

  # Enable automatic fixing of problems, defaults to false
  config.fix = true

  # Show ignored problems in the output, defaults to false
  config.show_ignored = true

  # Compare module layout relative to the module root
  config.relative = true
end

Disable checks in the Lint Rake task

You can also disable checks when running Puppet Lint through the supplied Rake task by modifying your Rakefile.

  • To disable a check, add the following line after the require statement in your Rakefile:

    PuppetLint.configuration.send("disable_<check name>")

    For example, to disable the 140-character check, add:

    PuppetLint.configuration.send("disable_140chars")
  • To set the Lint Rake task to ignore certain paths:

    PuppetLint.configuration.ignore_paths = ["vendor/**/*.pp"]
  • To set a pattern of files that Lint should check:

    # Defaults to `**/*.pp`
    PuppetLint.configuration.pattern = "modules"

Testing with Puppet Lint as a GitHub Action

There is a GitHub Actions action available to get linter feedback in workflows:

Options

See puppet-lint --help for a full list of command line options and checks.

Checks

For a complete list of checks, and how to resolve errors on each check, see the Puppet Lint checks page.

Spacing, Indentation, and Whitespace

  • Must use two-space soft tabs.
  • Must not use literal tab characters.
  • Must not contain trailing white space.
  • Should not exceed an 140-character line width.
    • An exception has been made for source => 'puppet://...' lines as splitting these over multiple lines decreases the readability of the manifests.
  • Should align arrows (=>) within blocks of attributes.

Quoting

  • 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.

Capitalization

  • All variables should be in lowercase.

Resources

  • 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 the target attribute.
  • File modes should be represented as a 4-digit string enclosed in single quotes or use symbolic file modes.

Conditionals

  • You should not intermingle conditionals inside resource declarations (that is, selectors inside resources).
  • Case statements should have a default case.

Classes

  • 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.
  • Chaining operators should appear on the same line as the right hand operand.

Reporting bugs or incorrect results

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.

Thank you

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!

License

Copyright (c) 2011-2016 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.

puppet-lint's People

Contributors

alexjfisher avatar bastelfreak avatar binford2k avatar bmjen avatar davids avatar dbeckham avatar dcarley avatar ghoneycutt avatar hanazuki avatar jamtur01 avatar jcbollinger avatar jiuka avatar jonnangle avatar kpaulisse avatar lazyfrosch avatar mcanevet avatar nanliu avatar paulgeringer avatar raphink avatar richardc avatar rnelson0 avatar rodjek avatar rothsa avatar ryanuber avatar sathieu avatar timtim123456 avatar usev6 avatar vstone avatar wfarr avatar xraystyle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppet-lint's Issues

defaults for case statements and selectors

Case statements should have default cases. Additionally, the default case should fail the catalog compilation when the resulting behavior cannot be predicted on the majority of platforms the module will be used on. If you want the default case to be “do nothing,” include it as an explicit default: {} for clarity’s sake.

invalid quoted string warning on resource titles

the following manifest:

file{"/tmp/a":}
file{/tmp/a:}

would yield the following warnings:

WARNING: double quoted string containing no variables on line 1
WARNING: unquoted resource title on line 2

False alignment positives

Getting loads of them since (I think) a recent update.
Examples:

 177   File {
 178     owner   => root,
 179     group   => root,
 180   }

WARNING: => on line 179 isn't aligned with the previous line

 135     ensure => $ensure ? {
 136       present => directory,
 137       absent  => undef,
 138     },
 139     owner  => 'foo4',
 140     group  => 'foo4',
 141     mode   => '0755',

WARNING: => on line 140 isn't aligned with the previous line
WARNING: => on line 141 isn't aligned with the previous line

  80   file { '/foo/.bar':
  81     source  => 'puppet:///modules/foo/.bar',
  82     owner   => 'root',
  83     group   => 'foo4',
  84     require => Class['foo::install']
  85   }

WARNING: => on line 82 isn't aligned with the previous line
WARNING: => on line 83 isn't aligned with the previous line
WARNING: => on line 84 isn't aligned with the previous line

Tested using Lint 0.1.0, Puppet 2.7.3

WARNING: => on line 13 isn't aligned with the previous line

I have a hash in an hash, but now the puppet-lint gives me the following error back:
WARNING: => on line 13 isn't aligned with the previous line
WARNING: => on line 14 isn't aligned with the previous line

It doesn't give me an warrning about the other line. I would say that the style gide is correct of the code.

It is effective on the following code:

class {'lvs::base':
    virtualeservers => {
        '192.168.2.13' => {
            vport           => '11025',
            service         => 'smtp',
            scheduler       => 'wlc',
            protocol        => 'tcp',
            checktype       => 'external',
            checkcommand    => '/path/to/checkscript',
            real_servers    => {
                'server01'   => {
                        real_server => '192.168.2.14',
                        real_port   => '25',
                        forwarding  => 'masq'
                    },
                'server02'  => {
                    real_server => '192.168.2.15',
                    real_port   => '25',
                    forwarding  => 'masq'
                }
            }
        }
    }
}

Please add logic to the >80 chars check

Please add some kind of logic to the >80 chars check.
Occasionally it is OK to have >80 characters on a line.

For example:

source  => 'puppet:///modules/certificates/etc/ssl/private/wildcard.example.com.crt',

Totals 88 characters, although splitting it across multiple lines would likely make the readability worse, not improve it.

Empty variables break check_strings plugin

% cat test.pp
$test = ""
% puppet lint test.pp
/var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint/plugins/check_strings.rb:7:in `test': undefined method `start_with?' for nil:NilClass (NoMethodError)
    from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint/plugins/check_strings.rb:6:in `each'
    from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint/plugins/check_strings.rb:6:in `test'
    from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint/plugins/check_strings.rb:4:in `each_line'
    from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint/plugins/check_strings.rb:4:in `test'
    from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint/plugin.rb:36:in `run'
    from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint.rb:45:in `run'
    from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint.rb:44:in `each'
    from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint.rb:44:in `run'
    from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/puppet-lint:46
    from /var/lib/gems/1.8/bin/puppet-lint:19:in `load'
    from /var/lib/gems/1.8/bin/puppet-lint:19

However the following works as expected, no errors.

% cat test2.pp
$test = ''

relationship declarations

Relationship declarations with the chaining syntax should only be used in the “left to right” direction.

single quotes in a manifest causes an exception

I ran this on one of my manifests, and got this error:

/var/lib/gems/1.8/gems/puppet-lint-0.1.7/bin/../lib/puppet-lint/plugins/check_strings.rb:13:in slurpstring': wrong number of arguments (3 for 1) (ArgumentError) from /var/lib/gems/1.8/gems/puppet-lint-0.1.7/bin/../lib/puppet-lint/plugins/check_strings.rb:13:inconvert'
from /usr/lib/ruby/1.8/puppet/parser/lexer.rb:360:in munge_token' from /usr/lib/ruby/1.8/puppet/parser/lexer.rb:428:inscan'
from /usr/lib/ruby/1.8/puppet/parser/lexer.rb:257:in fullscan' from /var/lib/gems/1.8/gems/puppet-lint-0.1.7/bin/../lib/puppet-lint/plugins/check_classes.rb:5:intest'
from /var/lib/gems/1.8/gems/puppet-lint-0.1.7/bin/../lib/puppet-lint/plugin.rb:37:in run' from /var/lib/gems/1.8/gems/puppet-lint-0.1.7/bin/../lib/puppet-lint.rb:60:inrun'
from /var/lib/gems/1.8/gems/puppet-lint-0.1.7/bin/../lib/puppet-lint.rb:59:in each' from /var/lib/gems/1.8/gems/puppet-lint-0.1.7/bin/../lib/puppet-lint.rb:59:inrun'
from /var/lib/gems/1.8/gems/puppet-lint-0.1.7/bin/puppet-lint:52
from /var/lib/gems/1.8/bin/puppet-lint:19:in `load'
from /var/lib/gems/1.8/bin/puppet-lint:19

I tracked it down to this statement:
$nfs_master_host = $domain ? {$
'domain.external' => '1.1.1.1',$
'domain.internet' => '2.2.2.2',$
}$

When I switched the single quotes to double quotes ("), it fixed the problem.

namespacing variables

When using top-scope variables, including facts, Puppet modules should explicitly specify the empty namespace (i.e., $::operatingsystem, not $operatingsystem) to prevent accidental scoping issues.

"class defined inside a class" even when class is a resource (parameterized Class)

The parameterized class

class foo ($bar = 'default') {
  notify{"The value is: ${bar}": }
}

The main class

class bar {
  class { 'foo':
    bar => 'foobar'
  }
}

The main class will give the error:

WARNING: class defined inside a class on line 2

Altough this should be allowed according to the puppet docs at http://docs.puppetlabs.com/guides/parameterized_classes.html

EDIT: I haven't seen this behaviour when it comes to parameterized defines which are called upon within a class. Perhaps the same remedy can be of use here?

$name is detected as a top-scope variable

The snippet:

define foo::bar( $var ) {
  exec { "echo-test-${name}":
    unless "grep ${var} /tmp/foo_bar.txt"
    command "echo ${name} >> /tmp/foo_bar.txt"
  }
}

will give the errors:

WARNING: top-scope variable being used without an explicit namespace on line 2
WARNING: top-scope variable being used without an explicit namespace on line 4

which shouldn't as far as I understand. Probably a bug to the exceptional nature of the $name variable?

Regex capture variables

$1 to $n are incorrectly detected as top scope variables, should be in the local scope like $name.

Classes inside classes should be allowed when order matters

# cat init.pp

class modulename {
    class { 'modulename::params': }
    class { 'modulename::preinstall': }
    class { 'modulename::install': }
    class { 'modulename::config': }
    class { 'modulename::service': }

    Class['modulename::params'] ->
    Class['modulename::preinstall'] ->
    Class['modulename::install'] ->
    Class['modulename::config'] ->
    Class['modulename::service']
}

Nasty stacktrace when trying to run lint against a non existance file

% file test.pp
test.pp: ERROR: cannot open `test.pp' (No such file or directory)

% puppet lint test.pp
/var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint/plugins/check_strings.rb:4:in test': undefined methodeach_line' for nil:NilClass (NoMethodError)
from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint/plugin.rb:36:in run' from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint.rb:45:inrun'
from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint.rb:44:in each' from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/../lib/puppet-lint.rb:44:inrun'
from /var/lib/gems/1.8/gems/puppet-lint-0.0.2/bin/puppet-lint:46
from /var/lib/gems/1.8/bin/puppet-lint:19:in `load'
from /var/lib/gems/1.8/bin/puppet-lint:19

disable tests on arbitrary lines or over blocks of code

Sometimes it may be necessary to disable specific tests on a particular line or block of code.

A common example would be disabling the 80-character check on a comment containing a CVS-style keywords:
# $Id: /some/really/long/path/of/nested/subdirs/puppet/environment/modules/somemodule/manifests/init.pp#5 $

I would like this to be similar to what pylint (http://www.logilab.org/card/pylint_manual) can do - put a comment like # puppet-lint: disable=80chars-check or similar at the end of a line and it doesn't lint that line for that check. To disable a check for a block of lines, surround it with # puppet-lint: disable=whatever [...] # puppet-lint: enable=whatever

See #34 for some initial discussion.

"false" != false (ditto for true)

A boolean toggle that was not performing as expected because there are quotes around the word "false"

class { 'foo' : boolFlag => "false" } was coming up TRUE

To fix it, lose the quotes

class { 'foo' : boolFlag => false }

It all depends what is done with boolFlag in your parametrized class.
More specifically what doesn't work is:

if "false" {
}

Because a string when (internally) converted to a boolean is true.

This is tracked in the following bug:
http://projects.puppetlabs.com/issues/5648

Autoload module check doesn't seem to work

I'm getting this error when running puppet-lint:

andrew@ares:~/dev/git/puppet-modules/modules$ puppet-lint autofs/manifests/base.pp
ERROR: autofs::base not in autoload module layout on line 1

Here's the puppet file:

class autofs::base {
  $nfs_master_host = $::domain ? {
    'internal.domain1'  => 'x.x.x.x',
    'internal.domain2' => 'x.x.x.x',
  }

  package { 'autofs5':
    ensure => 'installed',
  }

  file { '/etc/auto.master':
    source => 'puppet:///modules/autofs/auto.master',
    notify => Service['autofs'],
    owner  => 'root',
    group  => 'root',
    mode   => '0644',
  }

  file { '/etc/auto.home':
    content => template('autofs/auto.home.erb'),
    notify  => Service['autofs'],
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
  }

  service { 'autofs':
    ensure    => 'running',
    enable    => true,
    hasstatus => true,
    require   => Package['autofs5'],
  }
}

And the file layouts:

andrew@ares:~/dev/git/puppet-modules/modules$ ls -R autofs/
autofs/:
files manifests templates

autofs/files:
auto.master

autofs/manifests:
base.pp init.pp

autofs/templates:
auto.home.erb

Everything looks good to me here, but I'm still getting the error (not only in this manifest, but in many others as well). For now I've just disabled the check, but I'd like to be using it.

Am I missing something simple here?

Thanks,
Andy

turn off particular tests? .puppet-lintrc?

Is it possible to turn off particular tests in puppet-lint? For example, one test is "Should not exceed an 80 character line width" but what if I wanted to disable this test altogether?

In perltidy I do something similar, using the option --noblanks-before-blocks in my .perltidyrc, per the documentation because I don't like the default behavior.

It would be great to have a .puppet-lintrc. Apologies if there already is one and I missed it.

String containing escape char (and no var) incorrectly flagged

Hello again,

Consider :

class t {
    $alpha = 'foo\n'
    $delta = "bar\n"               # line 3
}

Will result in :
WARNING: double quoted string containing no variables on line 3

I've never used the Puppet Lexer, so I'm totally in the dark as to whether it can be leveraged to deal with this or not; once I get a chance to look at it I'll submit a patch, but if you have a solution, then go for it. ;)

display order of class/define parameters

In parameterized class and defined resource type declarations, parameters that are required should be listed before optional parameters (i.e. parameters with defaults).

Shell commands with curly brackets (e.g. awk)

exec {
    "do something":
        command => "bunch of commands",
        onlyif  => "echo test | awk {'print $1'}";
}

Although this works perfectly in puppet 2.6/2.7... lint prints out the following:
WARNING: variable not enclosed in {} on line 114

doesn't work...at all

[root@shameless manifests]# puppet-lint --version
/usr/lib/ruby/gems/1.8/gems/puppet-lint-0.1.4/bin/../lib/puppet-lint/plugin.rb:43: warning: parenthesize argument(s) for future version
Puppet-lint 0.1.4

[root@shameless manifests]# ruby --version
ruby 1.8.6 (2010-09-02 patchlevel 420) [x86_64-linux]

[root@shameless manifests]# puppet-lint /tmp/init.pp
/usr/lib/ruby/gems/1.8/gems/puppet-lint-0.1.4/bin/../lib/puppet-lint/plugin.rb:43: warning: parenthesize argument(s) for future version
/usr/lib/ruby/gems/1.8/gems/puppet-lint-0.1.4/bin/../lib/puppet-lint/plugins/check_classes.rb:15:in index': wrong number of arguments (0 for 1) (ArgumentError) from /usr/lib/ruby/gems/1.8/gems/puppet-lint-0.1.4/bin/../lib/puppet-lint/plugins/check_classes.rb:15:intest'
from /usr/lib/ruby/gems/1.8/gems/puppet-lint-0.1.4/bin/../lib/puppet-lint/plugins/check_classes.rb:13:in each_index' from /usr/lib/ruby/gems/1.8/gems/puppet-lint-0.1.4/bin/../lib/puppet-lint/plugins/check_classes.rb:13:intest'
from /usr/lib/ruby/gems/1.8/gems/puppet-lint-0.1.4/bin/../lib/puppet-lint/plugin.rb:37:in run' from /usr/lib/ruby/gems/1.8/gems/puppet-lint-0.1.4/bin/../lib/puppet-lint.rb:52:inrun'
from /usr/lib/ruby/gems/1.8/gems/puppet-lint-0.1.4/bin/../lib/puppet-lint.rb:51:in each' from /usr/lib/ruby/gems/1.8/gems/puppet-lint-0.1.4/bin/../lib/puppet-lint.rb:51:inrun'
from /usr/lib/ruby/gems/1.8/gems/puppet-lint-0.1.4/bin/puppet-lint:47
from /usr/bin/puppet-lint:19:in `load'
from /usr/bin/puppet-lint:19

False positive in commented line

Given the following line in a manifest :
# This configures an "exec" plugin.
The following warning is produced :
WARNING: double quoted string containing no variables on line 3
I wonder if comments shouldn't be exempted from some (most?) of the syntax checks.

ssh_key can't be broken up by \

At least I haven't figured out how to yet. What I've found works is adding an exception into whitespace.rb.

  # SHOULD NOT exceed an 80 character line width
  unless line =~ /puppet:\/\// || line =~ /AAAAB3NzaC1/

AAAAB3NzaC1 should match either an RSA or DSA key.

Multiline string should not be checked for double quotes

When using multiline strings to fit the 80 char on a line limit, you have to enclose your line
in double quotes or Puppet does not accept it.

puppet-lint raises a warning if there are no variables in the string.

I think it should not because we don't have the choice.
Or maybe Puppet should accept single quoted multiline strings ?

Resource types containing only a variable

File {
notify => Service["$puppetmaster::webserver_service"],
}

puppet-lint init.pp

WARNING: string containing only a variable on line 9

When applying the above sample - without - quotes puppet dies with the following error:

err: Could not run Puppet configuration client: Could not find dependent Service[undef] for ...

double quote within single quote

On occasion (here in an exec statement) I may need double quotes within a string. These are flagged as incorrect as they do not contain a variable, even though they are within a double quoted string.

class badstring {
exec { 'grepmaillog':
command => 'grep "status=sent" /var/log/mail.log',
}
}

Facter variables are seen as unnamespaced top-level variables

Is this expected?

[jayed puppet]$ bin/rake test:lintmod[yum](---- just a rake task for puppet-lint on a particular module)
Evaluating ./modules/yum/manifests/init.pp
WARNING: top-scope variable being used without an explicit namespace on line 6

1: class yum::repos {
2: exec{'/usr/bin/yum clean all':
3: subscribe => File['/etc/yum.repos.d/epocrates-local.repo'],
4: }
5:
6: if $operatingsystemrelease =~ /^5/ {
7: package{['yum-fastestmirror', 'yum-metadata-parser', 'yum-updatesd',
8: 'yum-utils']:
9: ensure => installed,
10: }

Invalid top-scope variable warning in definitions.

We can not use namespaces inside definitions. This will only work for classes. There should be no warning inside a definition for using top-scope variables.

Example: deftest.pp

define deftest() {
    case $title {
        default: {}
    }
}

puppet-syntax = OK
puppet-lint = WARNING: top-scope variable being used without an explicit namespace on line 2

We are not able to use $deftest::title since that variable can not be found.

missing dependency on "puppet" gem

Hello, I discovered puppet-lint via my "perltidy workalike to tidy up Puppet manifests" post on the puppet-users list. There seems to be a missing dependency on the "puppet" gem:

[pdurbin@beamish ~]$ gem install puppet-lint
Fetching: puppet-lint-0.1.5.gem (100%)
Successfully installed puppet-lint-0.1.5
1 gem installed
Installing ri documentation for puppet-lint-0.1.5...
Installing RDoc documentation for puppet-lint-0.1.5...
[pdurbin@beamish ~]$ puppet-lint --version
/home/pdurbin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- puppet (LoadError)
        from /home/pdurbin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/pdurbin/.rvm/gems/ruby-1.9.2-p290/gems/puppet-lint-0.1.5/lib/puppet-lint/plugins/check_strings.rb:1:in `<top (required)>'
        from /home/pdurbin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/pdurbin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/pdurbin/.rvm/gems/ruby-1.9.2-p290/gems/puppet-lint-0.1.5/lib/puppet-lint/plugins.rb:8:in `<top (required)>'
        from /home/pdurbin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/pdurbin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/pdurbin/.rvm/gems/ruby-1.9.2-p290/gems/puppet-lint-0.1.5/lib/puppet-lint.rb:2:in `<top (required)>'
        from /home/pdurbin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/pdurbin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/pdurbin/.rvm/gems/ruby-1.9.2-p290/gems/puppet-lint-0.1.5/bin/puppet-lint:18:in `<top (required)>'
        from /home/pdurbin/.rvm/gems/ruby-1.9.2-p290/bin/puppet-lint:19:in `load'
        from /home/pdurbin/.rvm/gems/ruby-1.9.2-p290/bin/puppet-lint:19:in `<main>'
[pdurbin@beamish ~]$ gem install puppet
Fetching: facter-1.6.1.gem (100%)
Fetching: puppet-2.7.5.gem (100%)
Successfully installed facter-1.6.1
Successfully installed puppet-2.7.5
2 gems installed
Installing ri documentation for facter-1.6.1...
Installing ri documentation for puppet-2.7.5...
Installing RDoc documentation for facter-1.6.1...
Installing RDoc documentation for puppet-2.7.5...
[pdurbin@beamish ~]$ puppet-lint --version
Puppet-lint 0.1.5
[pdurbin@beamish ~]$ 

Perhaps this has to do with my RVM installation (I'm new to RVM), but I don't think so as other dependencies are usually pulled in.

class inheritance

Inheritance may be used within a module, but must not be used across module namespaces. Cross-module dependencies should be satisfied in a more portable way that doesn’t violate the concept of modularity, such as with include statements or relationship declarations.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.