lint.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import config from '../config';
  2. import path from 'path';
  3. import gulp from 'gulp';
  4. import cached from 'gulp-cached';
  5. import eslint from 'gulp-eslint';
  6. import gulpif from 'gulp-if';
  7. import htmlhint from 'gulp-htmlhint';
  8. import plumber from 'gulp-plumber';
  9. import sassLint from 'gulp-sass-lint';
  10. const target = config.currentTarget;
  11. const isProduction = target === 'production';
  12. /**
  13. * Linting of javascript and jsx files
  14. *
  15. * @param cb: callback handler passed by gulp, signals task completion when called
  16. */
  17. const lintJs = (cb) => {
  18. gulp.src(
  19. path.join(
  20. config.paths.src,
  21. config.paths.js,
  22. '/**/*.{js, jsx}'
  23. ))
  24. .pipe(plumber())
  25. .pipe(cached('eslint'))
  26. .pipe(eslint(config.eslint[target]))
  27. .pipe(eslint.format())
  28. .pipe(eslint.failAfterError());
  29. cb();
  30. };
  31. /**
  32. * Linting of sass / scss files
  33. *
  34. * @param cb: callback handler passed by gulp, signals task completion when called
  35. */
  36. const lintSass = (cb) => {
  37. gulp.src(
  38. path.join(
  39. config.paths.src,
  40. config.paths.sass,
  41. '/**/*.scss'
  42. ))
  43. .pipe(plumber())
  44. .pipe(gulpif(!isProduction, cached('sasslint')))
  45. .pipe(sassLint())
  46. .pipe(sassLint.format())
  47. .pipe(gulpif(isProduction, sassLint.failOnError()));
  48. cb();
  49. };
  50. /**
  51. * Linting of index.html
  52. *
  53. * @param cb: callback handler passed by gulp, signals task completion when called
  54. */
  55. const lintHtml = (cb) => {
  56. gulp.src(
  57. path.join(
  58. config.paths.src,
  59. config.paths.html,
  60. `${config.fileNames.html}.html`
  61. ))
  62. .pipe(htmlhint(config.htmlhintrc))
  63. .pipe(gulpif(!isProduction, htmlhint.reporter()))
  64. .pipe(gulpif(isProduction, htmlhint.failReporter()));
  65. cb();
  66. };
  67. const lint = (cb) => {
  68. gulp.parallel(
  69. lintSass,
  70. lintJs,
  71. lintHtml
  72. );
  73. cb();
  74. };
  75. export {
  76. lint,
  77. lintHtml,
  78. lintJs,
  79. lintSass
  80. };