This package is pure ESM. Please read this.
A Gulp plugin that runs stylelint results through a list of reporters with ESM support.
Note
REQUIREMENTS: Supports gulp v4 and v5, stylelint > 16 and node >= 18.12.0.
# YARN
yarn add stylelint gulp-stylelint-esm -D
# NPM
npm install stylelint gulp-stylelint-esm --save-dev
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 gStylelintEsm from 'gulp-stylelint-esm';
function lintCssTask() {
return gulp
.src('src/**/*.css')
.pipe(gStylelintEsm({
reporters: [
{ formatter: 'string', console: true }
]
}));
}
Below is the list of currently available stylelint formatters. Some of them are bundled with stylelint by default and exposed on gStylelintEsm.formatters
object. Others need to be installed. You can write a custom formatter to tailor the reporting to your needs.
Formatters bundled with stylelint: "compact"
, "github"
, "json"
, "string (default)"
, "tap"
, "unix"
, "verbose"
.
gulp-stylelint-esm supports all stylelint and Node.js API options except:
files
, code will be provided by gulp insteadformatter
, formatters are defined in thereporters
optioncache
, gulp caching should be used instead
and accepts a custom set of options listed below:
import gulp from 'gulp';
import gStylelintEsm from 'gulp-stylelint-esm';
import { myStylelintFormatter } from 'my-stylelint-formatter';
function lintCssTask() {
return gulp
.src('src/**/*.css')
.pipe(gStylelintEsm({
failAfterError: true,
reportOutputDir: 'reports/lint',
reporters: [
{ formatter: 'verbose', console: true },
{ formatter: 'json', save: 'report.json' },
{ formatter: myStylelintFormatter, save: 'my-custom-report.txt' }
],
debug: true
}));
}
When set to true
, the process will end with non-zero error code if any error-level warnings were raised. Defaults to true
.
Base directory for lint results written to filesystem. Defaults to current working directory process.cwd()
.
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 for formatters bundled with stylelint
// "string (default)", "compact", "github", "json", "tap", "unix", "verbose"
formatter: myFormatter,
// save the formatted result to a file (optional):
save: 'text-report.txt',
// log the formatted result to console (optional):
console: true
}
When set to true
, the error handler will print an error stack trace. Defaults to false
.
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
.
import gulp from 'gulp';
import gStylelintEsm from 'gulp-stylelint-esm';
function fixCssTask() {
return gulp
.src('src/**/*.css')
.pipe(gStylelintEsm({
fix: true
}))
.pipe(gulp.dest('src'));
}
See the LICENSE file for license rights and limitations (MIT).