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