I
I
ilya23062018-11-19 10:04:30
Sass
ilya2306, 2018-11-19 10:04:30

How to use gulp-stylelint with gulp-sass?

I collect styles using gulp-sass. I lint with gulp-stylelint.
There are several input files, each of which is collected separately. Each file has an import.
Tell me how to lint styles before compiling them, but including linting files via import.
Function for compiling styles

const gulp = require('gulp');
const sass = require('gulp-sass');
const plumber = require('gulp-plumber');
const gulpStylelint = require('gulp-stylelint');

function compileStyles(src, dest) {
  return gulp.src(src)
    .pipe(plumber({
      errorHandler: console.error
    }))
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest(dest));
}

Function for linting:
function lintStyles(src) {
  return gulp.src(src)
    .pipe(gulpStylelint({
      failAfterError: true,
      reporters: [
        {formatter: 'string', console: true}
      ]
    }));
}

There is an option to run style linting before compilation, but then all files will be checked, but I would like only those files that are used in the input file to be checked.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
amf1k, 2018-11-19
@amf1k

It will probably be easier not to put the linter into gulp, but just make the script in packege.json

"scripts": {
    "style:lint": "stylelint 'src/style/**/*.scss' --syntax scss",
    "style:fix": "stylelint 'src/style/**/*.scss' --syntax scss --fix",
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question