Package detail

@ronilaukkarinen/gulp-stylelint

ronilaukkarinen13.3kMIT14.1.2

Gulp plugin for running Stylelint results through various reporters.

gulpplugin, stylelint, postcss, css

readme

gulp-stylelint

NPM version

This is a fork of olegskl/gulp-stylelint which seems to have been sleeping for a long time. This fork aims to have always up to date stylelint version.

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

Installation

npm install stylelint @ronilaukkarinen/gulp-stylelint --save-dev

Quick start

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

const gulp = require('gulp');

gulp.task('lint-css', function lintCssTask() {
  const gulpStylelint = require('gulp-stylelint');

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

Formatters

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

  • "string" (same as gulpStylelint.formatters.string) – bundled with stylelint
  • "verbose" (same as gulpStylelint.formatters.verbose) – bundled with stylelint
  • "json" (same as gulpStylelint.formatters.json) – bundled with stylelint
  • stylelint-checkstyle-formatter – requires installation

Options

gulp-stylelint supports all stylelint options except files and formatter and accepts a custom set of options listed below:

const gulp = require('gulp');

gulp.task('lint-css', function lintCssTask() {
  const gulpStylelint = require('gulp-stylelint');
  const myStylelintFormatter = require('my-stylelint-formatter');

  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 (required):
  // - pass a function for imported, custom or exposed formatters
  // - pass a string ("string", "verbose", "json") for formatters bundled with stylelint
  formatter: myFormatter,

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

  // log the formatted result to console (optional):
  console: true
}

debug

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

Autofix

The fix: true option instructs stylelint to try to fix as many issues as possible. The fixes are applied to the gulp stream. The fixed content can be saved to file using gulp.dest.

const gulp = require('gulp');

gulp.task('fix-css', function fixCssTask() {
  const gulpStylelint = require('gulp-stylelint');

  return gulp
    .src('src/**/*.css')
    .pipe(gulpStylelint({
      fix: true
    }))
    .pipe(gulp.dest('src'));
});

License

MIT License

changelog

14.1.2: 2023-10-22

  • Remove unknown build badge
  • Update postcss to 8.4.31
  • Update stylelint to 15.11.0
  • Update stylelint-config-standard to 34.0.0

14.1.1: 2023-02-15

  • Change to less strict peer dependency of stylelint

14.1.0: 2023-02-13

  • Update stylelint to 15.1.0, #5 (kudos to @movahhedi for reminding me)

14.0.9: 2022-11-26

  • Update dependencies, replace some #6 (thanks @onigoetz)
  • Update eslint-plugin-jest
  • Add .eslintrc.js

14.0.8: 2022-11-14

  • Upgrade peerDependencies to stylelint 14.15.0

14.0.7: 2022-11-14

  • Remove deprecated tape test
  • Update stylelint to 14.15.0 (Fixes #5)
  • Add .nvmrc

14.0.6: 2022-02-24

  • Allow Node 12+ #2
  • Remove dependency to through2 #3

14.0.5: 2021-11-02

  • Update devDependency of stylelint to 14.0.1

14.0.4: 2021-10-28

  • Release npm package @ronilaukkarinen/gulp-stylelint

14.0.3: 2021-10-28

  • Update package.json
  • Update only needed packages

14.0.2: 2021-10-28

  • Update stylelint and dependencies