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