Gulp plugin to lint Pug (nee Jade) files
A no-frills wrapper for the pug-lint
CLI. It expects the same configuration files as does the CLI tool. This means that whether you prefer linting from .pug-lintrc
, .pug-lint.json
, directly from package.json
("pugLintConfig": ...
), or even the legacy .jade
files, this plugin is going to work for you right out of the box. In addition, it can be set to fail once it encounters lint errors. That's important if you care about making the Continuous Integration (CI) builds to fail on error.
$ npm install gulp-pug-linter --save-dev
To see lint errors without breaking the build, simply pipe the Pug source files into .pugLinter()
and then into the handy, built-in reporter pugLinter.reporter()
. This is great for watching the *.pug
files as you're developing them.
// gulpfile.js
var gulp = require('gulp')
var pugLinter = require('gulp-pug-linter')
gulp.task('lint:template', function () {
return gulp
.src('./**/*.pug')
.pipe(pugLinter())
.pipe(pugLinter.reporter())
})
To break the build on lint errors, make sure that pugLinter.reporter
is set to 'fail'
, like so:
// gulpfile.js
var gulp = require('gulp')
var pugLinter = require('gulp-pug-linter')
gulp.task('lint:template', function () {
return gulp
.src('./**/*.pug')
.pipe(pugLinter())
.pipe(pugLinter.reporter('fail'))
})
Specify external modules as reporters using either the module's constructor or the module's name:
// gulpfile.js
var gulp = require('gulp')
var pugLinter = require('gulp-pug-linter')
var myPugLintReporter = require('my-pug-lint-reporter')
gulp.task('lint:template', function () {
return gulp
.src('./**/*.pug')
.pipe(pugLinter())
.pipe(pugLinter.reporter(myPugLintReporter))
})
- OR -
// gulpfile.js
var gulp = require('gulp')
var pugLinter = require('gulp-pug-linter')
gulp.task('lint:template', function () {
return gulp
.src('./**/*.pug')
.pipe(pugLinter())
.pipe(pugLinter.reporter('my-pug-lint-reporter'))
})
Specify your own custom reporter:
// gulpfile.js
var gulp = require('gulp')
var pugLinter = require('gulp-pug-linter')
var myReporter = function (errors) {
if (errors.length) { console.error('It broke!') }
}
gulp.task('lint:template', function () {
return gulp
.src('./**/*.pug')
.pipe(pugLinter())
.pipe(pugLinter.reporter(myReporter))
})