|
1 |
| -import antfu from '@antfu/eslint-config' |
| 1 | +const { builtinModules } = require('node:module') |
2 | 2 |
|
3 |
| -export default antfu() |
| 3 | +const DOMGlobals = ['window', 'document'] |
| 4 | +const NodeGlobals = ['module', 'require'] |
| 5 | + |
| 6 | +const banConstEnum = { |
| 7 | + selector: 'TSEnumDeclaration[const=true]', |
| 8 | + message: |
| 9 | + 'Please use non-const enums. This project automatically inlines enums.', |
| 10 | +} |
| 11 | + |
| 12 | +/** |
| 13 | + * @type {import('eslint-define-config').ESLintConfig} |
| 14 | + */ |
| 15 | +module.exports = { |
| 16 | + parser: '@typescript-eslint/parser', |
| 17 | + parserOptions: { |
| 18 | + sourceType: 'module', |
| 19 | + }, |
| 20 | + plugins: ['jest', 'import', '@typescript-eslint'], |
| 21 | + rules: { |
| 22 | + 'no-debugger': 'error', |
| 23 | + 'no-console': ['error', { allow: ['warn', 'error', 'info'] }], |
| 24 | + // most of the codebase are expected to be env agnostic |
| 25 | + 'no-restricted-globals': ['error', ...DOMGlobals, ...NodeGlobals], |
| 26 | + |
| 27 | + 'no-restricted-syntax': [ |
| 28 | + 'error', |
| 29 | + banConstEnum, |
| 30 | + // since we target ES2015 for baseline support, we need to forbid object |
| 31 | + // rest spread usage in destructure as it compiles into a verbose helper. |
| 32 | + 'ObjectPattern > RestElement', |
| 33 | + // tsc compiles assignment spread into Object.assign() calls, but esbuild |
| 34 | + // still generates verbose helpers, so spread assignment is also prohiboted |
| 35 | + 'ObjectExpression > SpreadElement', |
| 36 | + 'AwaitExpression', |
| 37 | + ], |
| 38 | + 'sort-imports': ['error', { ignoreDeclarationSort: true }], |
| 39 | + |
| 40 | + 'import/no-nodejs-modules': [ |
| 41 | + 'error', |
| 42 | + { allow: builtinModules.map(mod => `node:${mod}`) }, |
| 43 | + ], |
| 44 | + // This rule enforces the preference for using '@ts-expect-error' comments in TypeScript |
| 45 | + // code to indicate intentional type errors, improving code clarity and maintainability. |
| 46 | + '@typescript-eslint/prefer-ts-expect-error': 'error', |
| 47 | + // Enforce the use of 'import type' for importing types |
| 48 | + '@typescript-eslint/consistent-type-imports': [ |
| 49 | + 'error', |
| 50 | + { |
| 51 | + fixStyle: 'inline-type-imports', |
| 52 | + disallowTypeAnnotations: false, |
| 53 | + }, |
| 54 | + ], |
| 55 | + // Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers |
| 56 | + '@typescript-eslint/no-import-type-side-effects': 'error', |
| 57 | + }, |
| 58 | + overrides: [ |
| 59 | + // tests, no restrictions (runs in Node / jest with jsdom) |
| 60 | + { |
| 61 | + files: ['**/__tests__/**', 'packages/dts-test/**'], |
| 62 | + rules: { |
| 63 | + 'no-console': 'off', |
| 64 | + 'no-restricted-globals': 'off', |
| 65 | + 'no-restricted-syntax': 'off', |
| 66 | + 'jest/no-disabled-tests': 'error', |
| 67 | + 'jest/no-focused-tests': 'error', |
| 68 | + }, |
| 69 | + }, |
| 70 | + // shared, may be used in any env |
| 71 | + { |
| 72 | + files: ['packages/shared/**', '.eslintrc.cjs'], |
| 73 | + rules: { |
| 74 | + 'no-restricted-globals': 'off', |
| 75 | + }, |
| 76 | + }, |
| 77 | + // Packages targeting DOM |
| 78 | + { |
| 79 | + files: ['packages/{vue,vue-compat,runtime-dom}/**'], |
| 80 | + rules: { |
| 81 | + 'no-restricted-globals': ['error', ...NodeGlobals], |
| 82 | + }, |
| 83 | + }, |
| 84 | + // Packages targeting Node |
| 85 | + { |
| 86 | + files: ['packages/{compiler-sfc,compiler-ssr,server-renderer}/**'], |
| 87 | + rules: { |
| 88 | + 'no-restricted-globals': ['error', ...DOMGlobals], |
| 89 | + 'no-restricted-syntax': ['error', banConstEnum], |
| 90 | + }, |
| 91 | + }, |
| 92 | + // Private package, browser only + no syntax restrictions |
| 93 | + { |
| 94 | + files: [ |
| 95 | + 'packages/template-explorer/**', |
| 96 | + 'packages/sfc-playground/**', |
| 97 | + 'playground/**', |
| 98 | + ], |
| 99 | + rules: { |
| 100 | + 'no-restricted-globals': ['error', ...NodeGlobals], |
| 101 | + 'no-restricted-syntax': ['error', banConstEnum], |
| 102 | + 'no-console': 'off', |
| 103 | + }, |
| 104 | + }, |
| 105 | + // JavaScript files |
| 106 | + { |
| 107 | + files: ['*.js', '*.cjs'], |
| 108 | + rules: { |
| 109 | + // We only do `no-unused-vars` checks for js files, TS files are checked by TypeScript itself. |
| 110 | + 'no-unused-vars': ['error', { vars: 'all', args: 'none' }], |
| 111 | + }, |
| 112 | + }, |
| 113 | + // Node scripts |
| 114 | + { |
| 115 | + files: [ |
| 116 | + 'scripts/**', |
| 117 | + './*.{js,ts}', |
| 118 | + 'packages/*/*.js', |
| 119 | + 'packages/vue/*/*.js', |
| 120 | + ], |
| 121 | + rules: { |
| 122 | + 'no-restricted-globals': 'off', |
| 123 | + 'no-restricted-syntax': ['error', banConstEnum], |
| 124 | + 'no-console': 'off', |
| 125 | + }, |
| 126 | + }, |
| 127 | + // Import nodejs modules in compiler-sfc |
| 128 | + { |
| 129 | + files: ['packages/compiler-sfc/src/**'], |
| 130 | + rules: { |
| 131 | + 'import/no-nodejs-modules': ['error', { allow: builtinModules }], |
| 132 | + }, |
| 133 | + }, |
| 134 | + ], |
| 135 | +} |
0 commit comments