2026-12-04 08:52:50 -08:00
|
|
|
|
'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 = [
|
|
|
|
|
|
{
|
2026-12-04 18:36:57 -08:00
|
|
|
|
// web/ 是新版界面(TypeScript + React),有自己的 ESLint 配置与依赖。
|
|
|
|
|
|
ignores: ['node_modules/', 'e2e/node_modules/', 'e2e/out/', 'e2e/baseline/', 'data/', 'backups/', 'web/'],
|
2026-12-04 08:52:50 -08:00
|
|
|
|
},
|
|
|
|
|
|
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 } },
|
2026-12-04 09:02:52 -08:00
|
|
|
|
rules: {
|
|
|
|
|
|
// 经典脚本的顶层声明是供其他脚本与页面事件使用的全局名字,单文件无法判断是否被用到;只检查局部变量。
|
|
|
|
|
|
'no-unused-vars': ['warn', { args: 'none', vars: 'local' }],
|
|
|
|
|
|
},
|
2026-12-04 08:52:50 -08:00
|
|
|
|
},
|
|
|
|
|
|
// 浏览器与服务端共用的 UMD 文件:仅在 typeof module 判断成立时使用 module/require。
|
|
|
|
|
|
{
|
|
|
|
|
|
files: [
|
|
|
|
|
|
'public/calculations.js',
|
|
|
|
|
|
'public/credit-card-fees.js',
|
|
|
|
|
|
'public/fee-estimates.js',
|
|
|
|
|
|
'public/order-copy.js',
|
2026-12-04 18:56:01 -08:00
|
|
|
|
'public/order-entry-model.js',
|
2026-12-04 08:52:50 -08:00
|
|
|
|
'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 } },
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|