-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
84 lines (79 loc) · 3.21 KB
/
Copy patheslint.config.js
File metadata and controls
84 lines (79 loc) · 3.21 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
// eslint.config.js - ESLint v9+ 新格式配置
import eslint from "@eslint/js"
import prettierConfig from "eslint-config-prettier"
import prettierPlugin from "eslint-plugin-prettier"
import nodeGlobals from "globals"
// 整合 Prettier 规则(ESLint v9+ 需手动组合规则)
// 说明:此前 "prettier/prettier" 被设为 "off",导致插件与配置形同负担:
// 仓库里 14 个文件不符合 .prettierrc 却不会被任何门禁发现。
// 这里改为 "warn"——先让差异可见、不阻断构建,待全量格式化后可视情况收紧为 "error"。
const prettierRules = {
...prettierConfig.rules,
"prettier/prettier": "warn",
}
export default [
// 1. 基础 ESLint 推荐规则
eslint.configs.recommended,
// 2. Node.js 环境配置(启用 Node 全局变量)
{
languageOptions: {
globals: {
...nodeGlobals.node, // 包含 require、module、__dirname 等 Node 全局变量
es2021: true,
},
ecmaVersion: "latest",
sourceType: "module", // 如果是 CommonJS 项目,改为 'script'
},
// 自定义规则(优先级高于默认规则)
rules: {
// 此前 no-unused-vars / no-empty / no-fallthrough / no-prototype-builtins
// 被整体关闭,直接导致约 20 个文件保留未使用的 import 而不被提示,
// 也让静默 catch 块无法被发现。这里恢复为 error。
"no-unused-vars": [
"error",
{
args: "after-used",
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
// catch 参数未使用是常见且有意为之的写法(保留原始错误便于调试),
// 不因它产生噪音;真正需要关注的是未使用的 import 与局部变量。
caughtErrors: "none",
caughtErrorsIgnorePattern: "^_",
},
],
"no-empty": ["error", { allowEmptyCatch: false }],
"no-fallthrough": "error",
"no-prototype-builtins": "error",
"no-useless-assignment": "error",
"no-console": "off", // CLI 工具的输出属正常交付内容
"no-undef": "error",
},
},
// 3. Prettier 集成配置(禁用冲突规则 + 启用 Prettier 规则)
{
plugins: {
prettier: prettierPlugin,
},
rules: prettierRules,
},
// 4. 忽略文件(替代原来的 .eslintignore)
{
ignores: [
"node_modules/**",
"**/node_modules/*",
"dist/**",
"coverage/**",
"*.log",
// temp/ 存放修复前的代码备份与中间产物,不是产品代码,
// 其中的"问题"是刻意保留的历史快照,不应计入门禁。
"temp/**",
// labs/ 为实验性脚本,未纳入 npm files,单独维护
"labs/**",
// data/、assets/、output/、test/temp 为数据与运行产物
"data/**",
"assets/**",
"output/**",
"test/temp/**",
],
},
]