Files
weiguang-jewelry-ledger/新账系统/eslint.config.js
T
黄健铭andClaude Opus 5.5 2b9cb825be 修复ESLint发现的问题:重复定义、无效代码
- recoveries-ui.js:删除较早的 recoveryCardRate(与后一份逐字相同,运行时生效的本就是后一份)
- server.js:删除不可达的重复 GET /api/shop-settings 处理与重复的店主校验;删除从未被读取的初始值
- 订单取消/归属表单:去掉每个分支都会覆盖的变量初始值
- 去掉无效转义;测试夹具中的重复键保留实际生效的值
- 浏览器脚本的 no-unused-vars 只检查局部变量(顶层声明为跨文件全局名字)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 09:02:52 -08:00

88 lines
3.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
// ESLint 扁平配置。目标是发现重复定义、未定义变量和无效代码;只开启不需要改变运行行为就能满足的规则。
const js = require('@eslint/js');
const globals = require('globals');
const browserScripts = require('./eslint.browser-globals.js');
// public/index.html 按顺序加载的经典脚本共用全局作用域:每个脚本可以访问其他脚本的顶层声明
// (const 只读,let/function 等可写)。自身声明不能列入,否则 no-redeclare(builtinGlobals)会把本文件的
// 声明误报为重复定义;若两个脚本声明同一名字,则会如实报出跨文件重复定义。
const sharedScriptGlobals = Object.keys(browserScripts).map(file => ({
files: [file],
languageOptions: {
globals: Object.assign(
{},
...Object.entries(browserScripts)
.filter(([other]) => other !== file)
.map(([, names]) => names),
),
},
}));
module.exports = [
{
ignores: ['node_modules/', 'e2e/node_modules/', 'e2e/out/', 'e2e/baseline/', 'data/', 'backups/'],
},
js.configs.recommended,
{
linterOptions: { reportUnusedDisableDirectives: 'warn' },
rules: {
'no-redeclare': 'error',
'no-undef': 'error',
'no-unused-vars': ['warn', { args: 'none' }],
'no-empty': ['error', { allowEmptyCatch: true }],
// 关闭:正则里的 \x00-\x1f 是有意过滤控制字符(文件名、单元格、配置文本清洗),不是笔误。
'no-control-regex': 'off',
// 关闭:给重新抛出的错误补 cause 会改变抛出的错误对象(属于行为变化),且现有错误文案即面向用户的提示。
'preserve-caught-error': 'off',
// 收窄:模板字符串、正则与注释里的全角空格等是界面/打印文本的一部分,替换会改变输出。
'no-irregular-whitespace': [
'error',
{ skipStrings: true, skipTemplates: true, skipRegExps: true, skipComments: true },
],
},
},
// 后端:CommonJS 模块,运行于 Node。
{
files: ['**/*.js', '**/*.cjs'],
languageOptions: { ecmaVersion: 'latest', sourceType: 'commonjs', globals: { ...globals.node } },
},
// 浏览器经典脚本(含 print.js,由打印页单独加载)。
{
files: ['public/*.js'],
languageOptions: { sourceType: 'script', globals: { ...globals.browser } },
rules: {
// 经典脚本的顶层声明是供其他脚本与页面事件使用的全局名字,单文件无法判断是否被用到;只检查局部变量。
'no-unused-vars': ['warn', { args: 'none', vars: 'local' }],
},
},
// 浏览器与服务端共用的 UMD 文件:仅在 typeof module 判断成立时使用 module/require。
{
files: [
'public/calculations.js',
'public/credit-card-fees.js',
'public/fee-estimates.js',
'public/order-copy.js',
'public/order-formula.js',
'public/order-templates.js',
],
languageOptions: { globals: { module: 'readonly', require: 'readonly' } },
},
...sharedScriptGlobals,
// 单元测试:Node CommonJS。
{
files: ['test/**/*.js', 'test/**/*.cjs'],
languageOptions: { globals: { ...globals.node } },
},
// 端到端验证工具:Node;browser.mjs 为 ES 模块。
{
files: ['e2e/**/*.js', 'e2e/**/*.cjs', 'e2e/**/*.mjs'],
languageOptions: { globals: { ...globals.node } },
},
// browser.mjs 的 page.evaluate 回调在页面里执行,会用到 document/window 等浏览器全局。
{
files: ['e2e/**/*.mjs'],
languageOptions: { sourceType: 'module', globals: { ...globals.browser } },
},
];