Skip to content

Commit

Permalink
bears.configfile: Add new bear - PuppetLintBear
Browse files Browse the repository at this point in the history
The PuppetLintBear runs the `puppet-lint` utility on files give by coala
and gives results based on this.

Closes #46
  • Loading branch information
AbdealiLoKo committed Sep 3, 2016
1 parent db8a2de commit ee34cdc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ gem "rubocop"
gem "sqlint"
gem 'scss_lint', require: false# require flag is necessary https://github.com/brigade/scss-lint#installation
gem "reek"
gem "puppet-lint"
26 changes: 26 additions & 0 deletions bears/configfiles/PuppetLintBear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from coalib.bearlib.abstractions.Linter import linter
from coalib.bears.requirements.GemRequirement import GemRequirement


@linter(executable='puppet-lint',
output_format='regex',
output_regex=r'(?P<line>\d+):(?P<column>\d+):'
r'(?P<severity>warning|error):(?P<message>.+)')
class PuppetLintBear:
'''
Check and correct puppet configuration files using ``puppet-lint``.
See <http://puppet-lint.com/> for details about the tool.
'''

LANGUAGES = {"Puppet"}
REQUIREMENTS = {GemRequirement('puppet-lint', '2')}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'[email protected]'}
LICENSE = 'AGPL-3.0'
CAN_FIX = {'Syntax'}

@staticmethod
def create_arguments(filename, file, config_file):
return ('--log-format', "%{line}:%{column}:%{kind}:%{message}",
filename)
17 changes: 17 additions & 0 deletions tests/configfiles/PuppetLintBearTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from bears.configfiles.PuppetLintBear import PuppetLintBear
from tests.LocalBearTestHelper import verify_local_bear

good_file = """
file { '/some.conf':
ensure => present,
}
"""

bad_file = """
# foo
class test::foo { }
"""

PuppetLintBearTest = verify_local_bear(PuppetLintBear,
valid_files=(good_file,),
invalid_files=(bad_file,))

0 comments on commit ee34cdc

Please sign in to comment.