forked from cocos/cocos-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
98 lines (96 loc) · 3.13 KB
/
eslint.config.js
File metadata and controls
98 lines (96 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import js from '@eslint/js';
import typescript from '@typescript-eslint/eslint-plugin';
import typescriptParser from '@typescript-eslint/parser';
import globals from 'globals';
export default [
js.configs.recommended,
{
files: ['**/*.{js,ts,tsx,vue}'],
languageOptions: {
ecmaVersion: 2022,
sourceType: 'commonjs',
parser: typescriptParser,
parserOptions: {
ecmaFeatures: {
modules: false,
},
},
globals: {
...globals.node,
...globals.commonjs,
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
EditorExtends: 'readonly',
cc: 'readonly',
ccm: 'readonly',
globalThis: 'readonly',
// 项目特定的全局类型
NodeJS: 'readonly',
UUID: 'readonly',
FilePath: 'readonly',
MTime: 'readonly',
},
},
plugins: {
'@typescript-eslint': typescript,
},
rules: {
// 引号规则 - 强制使用单引号
quotes: ['error', 'single', {
avoidEscape: true,
allowTemplateLiterals: true,
}],
'quote-props': ['error', 'as-needed', {
keywords: false,
unnecessary: true,
numbers: false
}],
// 其他常用规则
semi: ['error', 'always'],
'no-unused-vars': 'off', // 关闭基础规则,使用 TypeScript 版本
'@typescript-eslint/no-unused-vars': ['warn', {
argsIgnorePattern: '^_',
varsIgnorePattern: '^_'
}],
'no-console': 'off',
'prefer-const': 'error',
'no-var': 'error',
'no-empty': ['warn', {
allowEmptyCatch: true
}], // 允许空的 catch 块
// TypeScript 特定规则,确保语言服务正常工作
'@typescript-eslint/no-unused-imports': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'off',
// 允许重复的全局变量定义(当从模块导入时)
'no-redeclare': 'off',
},
},
{
files: ['**/*.test.{js,ts}', '**/*.spec.{js,ts}', '**/test/**/*.{js,ts}'],
languageOptions: {
globals: {
...globals.jest,
...globals.node,
...globals.commonjs,
...globals.es2022,
jest: 'readonly',
},
},
rules: {
'no-console': 'off', // 测试文件中允许 console
},
},
{
ignores: [
'dist/**',
'node_modules/**',
'build/**',
'coverage/**',
'*.min.js',
'*.bundle.js',
],
},
];