lint.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. const { parallel, src } = require('gulp')
  2. const eslint = require('gulp-eslint')
  3. const { shellTask } = require('./util')
  4. exports.lint = parallel(
  5. shellTask('tslint --project .'),
  6. lintBuiltJs, // assumes already built!
  7. lintNodeJs,
  8. lintTests
  9. )
  10. /*
  11. ONLY checks two things:
  12. - code is ES5 compliant (for IE11)
  13. - does not access any globals. this is important because the typescript compiler allows
  14. accessing globals that are defined in the project for tests (tests/automated/globals.d.ts)
  15. */
  16. function lintBuiltJs() {
  17. return src([
  18. 'package?(-premium)/*/dist/**/*.js',
  19. '!**/*.esm.js', // ESM has non-browser syntax. doing only the UMD is sufficient
  20. '!**/*.min.js'
  21. ])
  22. .pipe(
  23. eslint({
  24. parserOptions: { 'ecmaVersion': 5 },
  25. envs: [ 'browser', 'commonjs', 'amd' ],
  26. rules: { 'no-undef': 2 }
  27. })
  28. )
  29. .pipe(eslint.format())
  30. .pipe(eslint.failAfterError())
  31. }
  32. function lintNodeJs() {
  33. return src([
  34. '*.js', // config files in root
  35. 'scripts/**/*.js'
  36. ])
  37. .pipe(
  38. eslint({
  39. configFile: 'eslint.json',
  40. envs: [ 'node' ]
  41. })
  42. )
  43. .pipe(eslint.format())
  44. .pipe(eslint.failAfterError())
  45. }
  46. /*
  47. we would want to use tslint with jsRules:true, but doesn't work at all,
  48. because of tslint-config-standard possibly
  49. */
  50. function lintTests() {
  51. return src([
  52. 'package?(-premium)/__tests__/**/*.js'
  53. ])
  54. .pipe(
  55. eslint({
  56. configFile: 'eslint.json',
  57. envs: [ 'browser' ],
  58. rules: { 'no-undef': 0 } // ignore referencing globals. tsc already checks this
  59. })
  60. )
  61. .pipe(eslint.format())
  62. .pipe(eslint.failAfterError())
  63. }