lint.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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(gulpif(!isProduction, eslint.format()))
  28. .pipe(gulpif(isProduction, eslint.formatEach('stylish', process.stdout)))
  29. .pipe(gulpif(isProduction, eslint.failOnError()))
  30. .on('data', gulpif(!isProduction, (file) => {
  31. if (file.eslint.messages && file.eslint.messages.length) gulp.fail = true;
  32. }));
  33. cb();
  34. };
  35. /**
  36. * Linting of sass / scss files
  37. *
  38. * @param cb: callback handler passed by gulp, signals task completion when called
  39. */
  40. const lintSass = (cb) => {
  41. gulp.src(
  42. path.join(
  43. config.paths.src,
  44. config.paths.sass,
  45. '/**/*.scss'
  46. ))
  47. .pipe(plumber())
  48. .pipe(gulpif(!isProduction, cached('sasslint')))
  49. .pipe(sassLint())
  50. .pipe(sassLint.format())
  51. .pipe(gulpif(isProduction, sassLint.failOnError()));
  52. cb();
  53. };
  54. /**
  55. * Linting of index.html
  56. *
  57. * @param cb: callback handler passed by gulp, signals task completion when called
  58. */
  59. const lintHtml = (cb) => {
  60. gulp.src(
  61. path.join(
  62. config.paths.src,
  63. config.paths.html,
  64. `${config.fileNames.html}.html`
  65. ))
  66. .pipe(htmlhint(config.htmlhintrc))
  67. .pipe(gulpif(!isProduction, htmlhint.reporter()))
  68. .pipe(gulpif(isProduction, htmlhint.failReporter()));
  69. cb();
  70. };
  71. const lint = (cb) => {
  72. gulp.parallel(
  73. lintSass,
  74. lintJs,
  75. lintHtml
  76. );
  77. cb();
  78. };
  79. export {
  80. lint,
  81. lintHtml,
  82. lintJs,
  83. lintSass
  84. };