Home Reference Source Repository

gulp-stylelint

NPM version Build Status Join the chat at https://gitter.im/olegskl/gulp-stylelint

A Gulp plugin that runs stylelint results through a list of reporters.

Installation

npm install gulp-stylelint --save-dev

Quick start

With gulp-stylelint, it's easy to generate CSS lint reports based on stylelint results.

Once you have configured stylelint (e.g. you have a .stylelintrc file), start with the following code. You will find additional configuration options below.

import gulp from 'gulp';
import gulpStylelint from 'gulp-stylelint';
import stylelintTextFormatter from 'stylelint-text-formatter';

gulp.task('lint-css', function lintCssTask() {
  return gulp
    .src('src/**/*.css')
    .pipe(gulpStylelint({
      reporters: [
        {formatter: 'string', console: true}
      ]
    }));
});

Note that if you're using ES5, you will have to access the library via the default property due to the way exports are handled in Babel 6:

var gulpStylelint = require('gulp-stylelint').default;

Formatters

Below is the list of currently available stylelint formatters. Some of them are bundled with stylelint by default and exposed on gulpStylelint.formatters. Others need to be installed. You can write a custom formatter to tailor the reporting to your needs.

Options

Below is an example with all available options provided:

import gulp from 'gulp';
import gulpStylelint from 'gulp-stylelint';
import myStylelintFormatter from 'my-stylelint-formatters';

gulp.task('lint-css', function lintCssTask() {
  return gulp
    .src('src/**/*.css')
    .pipe(gulpStylelint({
      failAfterError: true,
      reportOutputDir: 'reports/lint',
      reporters: [
        {formatter: 'verbose', console: true},
        {formatter: 'json', save: 'report.json'},
        {formatter: myStylelintFormatter, save: 'my-custom-report.txt'}
      ],
      debug: true
    }));
});

failAfterError

When set to true, the process will end with non-zero error code if any error-level warnings were raised. Defaults to true.

reportOutputDir

Base directory for lint results written to filesystem. Defaults to current working directory.

reporters

List of reporter configuration objects (see below). Defaults to an empty array.

{
  // stylelint results formatter:
  // - pass a function for imported, custom or exposed formatters
  // - pass a string ("string", "verbose", "json") for formatters
  //   bundled with stylelint by default
  formatter: myFormatter,

  // save the formatted result to a file:
  save: 'text-report.txt',

  // log the formatted result to console:
  console: true
}

debug

When set to true, the error handler will print an error stack trace. Defaults to false.

License

MIT License