Get unlimited public & private packages + team-based management with npm Teams.Learn more »

gulp-pug-linter

1.3.0 • Public • Published

gulp-pug-linter

Gulp plugin to lint Jade or Pug files

Status

npm
Codeship Status Coverage Status Dependencies Status Dev Dependencies Status Conventional Commits Greenkeeper badge

About

Screenshot from Terminal

A no-frills wrapper for the pug-lint CLI tool. It expects the same configuration files as the CLI. This means that whether you prefer configuring the linter with .pug-lintrc, .pug-lint.json, package.json ("pugLintConfig": ...), or even with 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 after it encounters lint errors. That's important if you care about making the Continuous Integration (CI) builds fail after error.

Installation

$ npm install gulp-pug-linter --save-dev

Options

  • failAfterError - whether to throw a plugin error after encountering one or more lint errors
  • reporter - reporter type, name, module, or function to show lint errors

Usage

Basic

To lint the template files without breaking the build, pipe the source files into pugLinter({ reporter: 'default' }):

// gulpfile.js
const gulp = require('gulp');
const pugLinter = require('gulp-pug-linter');
 
gulp.task('lint:template', () => (
  gulp
    .src('./**/*.pug')
    .pipe(pugLinter({ reporter: 'default' }))
));

Note that specifying a reporter key with an invalid value would fall back to the 'default' reporter and display a warning. The screenshot above shows the 'default' reporter in action.

Fail After Error(s)

If you want to break the build after seeing one or more errors, set the { failAfterError: true } option on pugLinter():

// gulpfile.js
const gulp = require('gulp');
const pugLinter = require('gulp-pug-linter');
 
gulp.task('lint:template', () => (
  gulp
    .src('./**/*.pug')
    .pipe(pugLinter({ failAfterError: true }))
));

Note that without a reporter option, this usage example would break the build without displaying any lint errors. This might be useful in pre-production CI builds or during a git bisect.

External Reporter

If you want to specify an external module as a reporter, you may provide its constructor:

// gulpfile.js
const gulp = require('gulp');
const pugLinter = require('gulp-pug-linter');
const pugLintStylish = require('puglint-stylish');
 
gulp.task('lint:template', () => (
  gulp
    .src('./**/*.pug')
    .pipe(pugLinter({ reporter: pugLintStylish }))
));

Or you may provide the module's name:

// gulpfile.js
const gulp = require('gulp');
const pugLinter = require('gulp-pug-linter');
 
gulp.task('lint:template', () => (
  gulp
    .src('./**/*.pug')
    .pipe(pugLinter({ reporter: 'puglint-stylish' }))
));

Custom Reporter

You may define a custom reporter:

// gulpfile.js
const gulp = require('gulp');
const pugLinter = require('gulp-pug-linter');
 
const myReporter = (errors) => {
  errors.map(error => console.error(error.message));
};
 
gulp.task('lint:template', () => (
  gulp
    .src('./**/*.pug')
    .pipe(pugLinter({ reporter: myReporter }))
));

Install

npm i gulp-pug-linter

DownloadsWeekly Downloads

1,193

Version

1.3.0

License

MIT

Unpacked Size

43.1 kB

Total Files

12

Last publish

Collaborators

  • avatar