Commit e495d69e authored by mark hellewell's avatar mark hellewell Committed by Sebastian Wiesner

[Fix #138] Add syntax checkers for Puppet

The first checker, `puppet-parser`, uses puppet's own `puppet parser
validate` command to check syntax. The second checker,
`puppet-puppet-lint`, is chained to the first and uses the
`puppet-lint` program to check adherence to the Puppet style
guidelines.

Add four new unit tests to test single line and multiline error
patterns from `puppet-parser`, and to test ERROR and WARNING error
patterns from `puppet-puppet-lint`.

Update the Vagrant provisioning script to install puppet.
parent 40e8e13c
......@@ -18,6 +18,7 @@
(depends-on "cperl-mode")
(depends-on "php-mode")
(depends-on "php+-mode")
(depends-on "puppet-mode")
(depends-on "sass-mode")
(depends-on "scala-mode2")
(depends-on "scss-mode")
......
......@@ -38,6 +38,7 @@ Features
- Lua
- Perl
- PHP
- Puppet
- Python
- Ruby
- Rust
......@@ -142,6 +143,7 @@ The following people contributed to flycheck:
- [Magnar Sveen][magnars] developed the awesome [dash.el][] and [s.el][]
libraries, that drive considerable parts of Flycheck's internals.
- [Marian Schubert][maio] added the Perl syntax checker.
- [Mark Hellewell][markhellewell] added the Puppet syntax and style checkers.
- [Martin Grenfell][scrooloose] created the awesome Vim library [syntastic][]
which inspired this project and many of its checkers.
- [Peter Vasil][ptrv] contributed syntax checkers for XML, Lua and Go (using `go
......@@ -208,3 +210,4 @@ See [COPYING][] for details.
[thisirs]: https://github.com/thisirs
[syl20bnr]: https://github.com/syl20bnr
[flycheck-color-mode-line.el]: https://github.com/syl20bnr/flycheck-color-mode-line
[markhellewell]: https://github.com/markhellewell
......@@ -576,6 +576,14 @@ Add missing customization group for syntax checker options
@unnumberedsec master (unreleased)
@itemize @bullet
@item
New syntax checkers:
@itemize @bullet
@item
@ghissue{138, Puppet}
@end itemize
@item
Improvements:
......
......@@ -21,6 +21,8 @@ order of their appearance in the default value of
@iflyc perl
@iflyc php
@iflyc php-phpcs
@iflyc puppet-parser
@iflyc puppet-lint
@iflyc python-flake8
@iflyc python-pylint
@iflyc rst
......
......@@ -32,6 +32,10 @@ considerable parts of Flycheck's internals.
@uref{https://github.com/maio, Marian Schubert} added the Perl syntax
checker.
@item
@uref{https://github.com/markhellewell, Mark Hellewell} added the Puppet
syntax and style checkers.
@item
@uref{https://github.com/scrooloose, Martin Grenfell} created the
awesome Vim library @uref{https://github.com/scrooloose/syntastic,
......
No preview for this file type
......@@ -71,6 +71,8 @@ Perl
@item
PHP (using the PHP Command Line and PHP CodeSniffer)
@item
Puppet (using @command{puppet parser} and @command{puppet-lint})
@item
Python (using @command{flake8}, @command{pylint}, or @command{pyflakes})
@item
Ruby (using @command{rubocop} or @command{ruby})
......
......@@ -110,6 +110,8 @@ buffer-local wherever it is set."
perl
php
php-phpcs
puppet-parser
puppet-lint
python-flake8
python-pylint
rst
......@@ -2611,6 +2613,27 @@ See URL `http://pear.php.net/package/PHP_CodeSniffer/'."
("\\(?1:.*\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\): warning - \\(?4:.*\\)" warning))
:modes '(php-mode php+-mode))
(flycheck-declare-checker puppet-parser
"A Puppet DSL syntax checker using puppet's own parser.
See URL `http://www.puppetlabs.com/'."
:command '("puppet" "parser" "validate" "--color=false" source)
:error-patterns
'(("^.*?: Could not parse for environment \\w+: \\(?4:\\(.*\n\\)*?.*?\\) at \\(?1:\/.*\\):\\(?2:[0-9]+\\)$" error))
:modes 'puppet-mode
:next-checkers '((no-errors . puppet-lint)))
(flycheck-declare-checker puppet-lint
"A Puppet DSL style checker using puppet-lint.
See URL `http://www.puppet-lint.com/'."
:command '("puppet-lint" "--with-filename" source-original)
:predicate (and (buffer-file-name) (not (buffer-modified-p)))
:error-patterns
'(("^\\(?1:.*\\) - WARNING: \\(?4:.*\\) on line \\(?2:[0-9]+\\)" warning)
("^\\(?1:.*\\) - ERROR: \\(?4:.*\\) on line \\(?2:[0-9]+\\)" error))
:modes 'puppet-mode)
(flycheck-def-config-file-var flycheck-flake8rc python-flake8 ".flake8rc")
(flycheck-def-option-var flycheck-flake8-maximum-complexity nil python-flake8
......
# "case statement without a default case"
case $::operatingsystem {
debian: {
$version = '1.2.3'
}
redhat: {
$version = '6.6.6'
}
}
# Test multi-line error messages.
#
# Error: Could not parse for environment production: Unclosed quote after '' in 'something
# }
# ' at parser_err3.pp:2
#
class {'parser_err3':
hello => 'something
}
# Test single line error message
class {'parser_err1':
hello => 'something',,
}
;;; test-puppet-lint.el --- Test the puppet linter -*- lexical-binding: t; -*-
;; Copyright (c) 2013 Mark Hellewell <mark.hellewell@gmail.com>
;;
;; Author: Mark Hellewell <mark.hellewell@gmail.com>
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Code:
(require 'ert)
(require 'flycheck)
(require 'puppet-mode)
(ert-deftest checker-puppet-lint-warning ()
:expected-result (flycheck-testsuite-fail-unless-checker 'puppet-lint)
(flycheck-testsuite-should-syntax-check
"checkers/puppet-lint-warning.pp" 'puppet-mode nil
'(2 nil "case statement without a default case" warning)))
(ert-deftest checker-puppet-lint-error ()
:expected-result (flycheck-testsuite-fail-unless-checker 'puppet-lint)
(flycheck-testsuite-should-syntax-check
"checkers/puppet-lint/error/manifests/puppet-lint-error.pp" 'puppet-mode nil
'(2 nil "mlayout not in autoload module layout" error)))
;; Local Variables:
;; coding: utf-8
;; End:
;;; test-puppet-lint.el ends here
;;; test-puppet-parser.el --- Test the puppet parser -*- lexical-binding: t; -*-
;; Copyright (c) 2013 Mark Hellewell <mark.hellewell@gmail.com>
;;
;; Author: Mark Hellewell <mark.hellewell@gmail.com>
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Code:
(require 'ert)
(require 'flycheck)
(require 'puppet-mode)
(ert-deftest checker-puppet-parser-singleline-syntax-error ()
"Test a real syntax error with puppet parser."
:expected-result (flycheck-testsuite-fail-unless-checker 'puppet-parser)
(flycheck-testsuite-should-syntax-check
"checkers/puppet-parser-singleline.pp" 'puppet-mode nil
'(3 nil "Syntax error at ','; expected '}'" error)))
(ert-deftest checker-puppet-parser-multiline-syntax-error ()
"Test a real (multi line) syntax error with puppet parser."
:expected-result (flycheck-testsuite-fail-unless-checker 'puppet-parser)
(flycheck-testsuite-should-syntax-check
"checkers/puppet-parser-multiline.pp" 'puppet-mode nil
'(8 nil "Unclosed quote after '' in 'something
}
'" error)))
;; Local Variables:
;; coding: utf-8
;; End:
;;; test-puppet-parser.el ends here
......@@ -88,6 +88,9 @@ ppa ppa:cassou/emacs \
# entry
deb_src "esl-erlang" "deb http://binaries.erlang-solutions.com/debian precise contrib"
deb_src_key "http://binaries.erlang-solutions.com/debian/erlang_solutions.asc"
# Install puppet using Puppet Labs own repo.
deb_src "puppetlabs" "deb http://apt.puppetlabs.com precise main"
deb_src_key "http://apt.puppetlabs.com/keyring.gpg"
apt_update
# Install texinfo to build documentation
......@@ -114,6 +117,7 @@ apt bash \
lacheck \
lua5.2 \
php5-cli \
puppet \
ruby1.9.1 \
rust \
scala \
......@@ -136,7 +140,8 @@ npm coffeelint \
gem haml \
rubocop \
sass
sass \
puppet-lint
# Install Elixir compiler.
ELIXIR_VERSION=0.8.2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment