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
6
5
const banConstEnum = {
7
6
selector : 'TSEnumDeclaration[const=true]' ,
8
7
message :
9
- 'Please use non-const enums. This project automatically inlines enums.'
8
+ 'Please use non-const enums. This project automatically inlines enums.' ,
10
9
}
11
10
12
11
/**
@@ -15,9 +14,9 @@ const banConstEnum = {
15
14
module . exports = {
16
15
parser : '@typescript-eslint/parser' ,
17
16
parserOptions : {
18
- sourceType : 'module'
17
+ sourceType : 'module' ,
19
18
} ,
20
- plugins : [ 'jest' ] ,
19
+ plugins : [ 'jest' , 'import' , '@typescript-eslint' ] ,
21
20
rules : {
22
21
'no-debugger' : 'error' ,
23
22
// most of the codebase are expected to be env agnostic
@@ -32,8 +31,27 @@ module.exports = {
32
31
// tsc compiles assignment spread into Object.assign() calls, but esbuild
33
32
// still generates verbose helpers, so spread assignment is also prohiboted
34
33
'ObjectExpression > SpreadElement' ,
35
- 'AwaitExpression'
36
- ]
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' ,
37
55
} ,
38
56
overrides : [
39
57
// tests, no restrictions (runs in Node / jest with jsdom)
@@ -43,54 +61,66 @@ module.exports = {
43
61
'no-restricted-globals' : 'off' ,
44
62
'no-restricted-syntax' : 'off' ,
45
63
'jest/no-disabled-tests' : 'error' ,
46
- 'jest/no-focused-tests' : 'error'
47
- }
64
+ 'jest/no-focused-tests' : 'error' ,
65
+ } ,
48
66
} ,
49
67
// shared, may be used in any env
50
68
{
51
- files : [ 'packages/shared/**' ] ,
69
+ files : [ 'packages/shared/**' , '.eslintrc.cjs' ] ,
52
70
rules : {
53
- 'no-restricted-globals' : 'off'
54
- }
71
+ 'no-restricted-globals' : 'off' ,
72
+ } ,
55
73
} ,
56
74
// Packages targeting DOM
57
75
{
58
76
files : [ 'packages/{vue,vue-compat,runtime-dom}/**' ] ,
59
77
rules : {
60
- 'no-restricted-globals' : [ 'error' , ...NodeGlobals ]
61
- }
78
+ 'no-restricted-globals' : [ 'error' , ...NodeGlobals ] ,
79
+ } ,
62
80
} ,
63
81
// Packages targeting Node
64
82
{
65
83
files : [ 'packages/{compiler-sfc,compiler-ssr,server-renderer}/**' ] ,
66
84
rules : {
67
85
'no-restricted-globals' : [ 'error' , ...DOMGlobals ] ,
68
- 'no-restricted-syntax' : [ 'error' , banConstEnum ]
69
- }
86
+ 'no-restricted-syntax' : [ 'error' , banConstEnum ] ,
87
+ } ,
70
88
} ,
71
89
// Private package, browser only + no syntax restrictions
72
90
{
73
91
files : [ 'packages/template-explorer/**' , 'packages/sfc-playground/**' ] ,
74
92
rules : {
75
93
'no-restricted-globals' : [ 'error' , ...NodeGlobals ] ,
76
- 'no-restricted-syntax' : [ 'error' , banConstEnum ]
77
- }
94
+ 'no-restricted-syntax' : [ 'error' , banConstEnum ] ,
95
+ } ,
78
96
} ,
79
97
// JavaScript files
80
98
{
81
99
files : [ '*.js' , '*.cjs' ] ,
82
100
rules : {
83
101
// We only do `no-unused-vars` checks for js files, TS files are checked by TypeScript itself.
84
- 'no-unused-vars' : [ 'error' , { vars : 'all' , args : 'none' } ]
85
- }
102
+ 'no-unused-vars' : [ 'error' , { vars : 'all' , args : 'none' } ] ,
103
+ } ,
86
104
} ,
87
105
// Node scripts
88
106
{
89
- files : [ 'scripts/**' , '*.{js,ts}' , 'packages/**/index.js' ] ,
107
+ files : [
108
+ 'scripts/**' ,
109
+ './*.{js,ts}' ,
110
+ 'packages/*/*.js' ,
111
+ 'packages/vue/*/*.js' ,
112
+ ] ,
90
113
rules : {
91
114
'no-restricted-globals' : 'off' ,
92
- 'no-restricted-syntax' : [ 'error' , banConstEnum ]
93
- }
94
- }
95
- ]
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
+ ] ,
96
126
}
0 commit comments