import config from '../config'; import path from 'path'; import gulp from 'gulp'; import cached from 'gulp-cached'; import eslint from 'gulp-eslint'; import gulpif from 'gulp-if'; import htmlhint from 'gulp-htmlhint'; import plumber from 'gulp-plumber'; import sassLint from 'gulp-sass-lint'; const target = config.currentTarget; const isProduction = target === 'production'; /** * Linting of javascript and jsx files * * @param cb: callback handler passed by gulp, signals task completion when called */ const lintJs = (cb) => { gulp.src( path.join( config.paths.src, config.paths.js, '/**/*.{js, jsx}' )) .pipe(plumber()) .pipe(cached('eslint')) .pipe(eslint(config.eslint[target])) .pipe(eslint.format()) .pipe(eslint.failAfterError()); cb(); }; /** * Linting of sass / scss files * * @param cb: callback handler passed by gulp, signals task completion when called */ const lintSass = (cb) => { gulp.src( path.join( config.paths.src, config.paths.sass, '/**/*.scss' )) .pipe(plumber()) .pipe(gulpif(!isProduction, cached('sasslint'))) .pipe(sassLint()) .pipe(sassLint.format()) .pipe(gulpif(isProduction, sassLint.failOnError())); cb(); }; /** * Linting of index.html * * @param cb: callback handler passed by gulp, signals task completion when called */ const lintHtml = (cb) => { gulp.src( path.join( config.paths.src, config.paths.html, `${config.fileNames.html}.html` )) .pipe(htmlhint(config.htmlhintrc)) .pipe(gulpif(!isProduction, htmlhint.reporter())) .pipe(gulpif(isProduction, htmlhint.failReporter())); cb(); }; const lint = (cb) => { gulp.parallel( lintSass, lintJs, lintHtml ); cb(); }; export { lint, lintHtml, lintJs, lintSass };