.eslintrc.cjs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* eslint-disable no-restricted-globals */
  2. const DOMGlobals = ['window', 'document']
  3. const NodeGlobals = ['module', 'require']
  4. module.exports = {
  5. parser: '@typescript-eslint/parser',
  6. parserOptions: {
  7. sourceType: 'module'
  8. },
  9. plugins: ['jest'],
  10. rules: {
  11. 'no-debugger': 'error',
  12. // most of the codebase are expected to be env agnostic
  13. 'no-restricted-globals': ['error', ...DOMGlobals, ...NodeGlobals],
  14. 'no-restricted-syntax': [
  15. 'error',
  16. // since we target ES2015 for baseline support, we need to forbid object
  17. // rest spread usage in destructure as it compiles into a verbose helper.
  18. 'ObjectPattern > RestElement',
  19. // tsc compiles assignment spread into Object.assign() calls, but esbuild
  20. // still generates verbose helpers, so spread assignment is also prohiboted
  21. 'ObjectExpression > SpreadElement',
  22. 'AwaitExpression'
  23. ]
  24. },
  25. overrides: [
  26. // tests, no restrictions (runs in Node / jest with jsdom)
  27. {
  28. files: ['**/__tests__/**', 'packages/dts-test/**'],
  29. rules: {
  30. 'no-restricted-globals': 'off',
  31. 'no-restricted-syntax': 'off',
  32. 'jest/no-disabled-tests': 'error',
  33. 'jest/no-focused-tests': 'error'
  34. }
  35. },
  36. // shared, may be used in any env
  37. {
  38. files: ['packages/shared/**'],
  39. rules: {
  40. 'no-restricted-globals': 'off'
  41. }
  42. },
  43. // Packages targeting DOM
  44. {
  45. files: ['packages/{vue,vue-compat,runtime-dom}/**'],
  46. rules: {
  47. 'no-restricted-globals': ['error', ...NodeGlobals]
  48. }
  49. },
  50. // Packages targeting Node
  51. {
  52. files: [
  53. 'packages/{compiler-sfc,compiler-ssr,server-renderer,reactivity-transform}/**'
  54. ],
  55. rules: {
  56. 'no-restricted-globals': ['error', ...DOMGlobals],
  57. 'no-restricted-syntax': 'off'
  58. }
  59. },
  60. // Private package, browser only + no syntax restrictions
  61. {
  62. files: ['packages/template-explorer/**', 'packages/sfc-playground/**'],
  63. rules: {
  64. 'no-restricted-globals': ['error', ...NodeGlobals],
  65. 'no-restricted-syntax': 'off'
  66. }
  67. },
  68. // JavaScript files
  69. {
  70. files: ['*.js', '*.cjs'],
  71. rules: {
  72. // We only do `no-unused-vars` checks for js files, TS files are checked by TypeScript itself.
  73. 'no-unused-vars': ['error', { vars: 'all', args: 'none' }]
  74. }
  75. },
  76. // Node scripts
  77. {
  78. files: ['scripts/**', '*.{js,ts}', 'packages/**/index.js'],
  79. rules: {
  80. 'no-restricted-globals': 'off',
  81. 'no-restricted-syntax': 'off'
  82. }
  83. }
  84. ]
  85. }