Files
image-workbench-desktop/eslint.config.js
T

68 lines
2.8 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.
// ESLint 扁平配置 —— P4-16a。
// 目的:给「要拼接成单文件发布」的两处代码加一道**正确性**静态护栏
// (重复键 / 不可达代码 / 自赋值 / 用例错误 / 未定义标识符等),不做风格化(避免无谓 churn)。
// · src/**/*.js:模块化 IIFE,启用 no-undef(浏览器 + es2022 + Buffer 兜底);
// · app.js :单文件 IIFE,自带数百个顶层全局(含 window.IWB* 导入),
// 故**不启用 no-undef**,只挂与作用域无关的正确性规则。
const globals = require('globals')
const sharedRules = {
'no-dupe-keys': 'error',
'no-dupe-args': 'error',
'no-dupe-else-if': 'error',
'no-redeclare': 'error',
'no-unreachable': 'error',
'no-self-assign': 'error',
'no-cond-assign': 'error',
'no-constant-condition': 'error',
'no-fallthrough': 'error',
'no-sparse-arrays': 'error',
'use-isnan': 'error',
'valid-typeof': 'error',
'no-obj-calls': 'error',
'no-unsafe-negation': 'error',
'no-irregular-whitespace': 'error',
'no-unexpected-multiline': 'error',
'no-async-promise-executor': 'error',
'no-shadow-restricted-names': 'error',
'no-debugger': 'error',
'no-empty': ['error', { allowEmptyCatch: true }],
}
module.exports = [
{
ignores: ['dist/**', 'node_modules/**', 'test-results/**', 'playwright-report/**', '.wrangler/**'],
},
{
files: ['src/**/*.js'],
languageOptions: {
ecmaVersion: 2022,
sourceType: 'script',
// Buffer:双环境(浏览器/Node)兜底分支用(`typeof btoa==='function' ? btoa(...) : Buffer...`),浏览器路径永不触达。
globals: { ...globals.browser, ...globals.es2022, Buffer: 'readonly' },
},
linterOptions: { reportUnusedDisableDirectives: true },
rules: { 'no-undef': 'error', ...sharedRules },
},
{
files: ['app.js'],
languageOptions: {
ecmaVersion: 2022,
sourceType: 'script',
// 2026-10-28:补全 globals 并开启 no-undef。
// 之前 app.js 只跑 sharedRules、没有 no-undef ⇒ 未定义变量长期无人发现。
// 实测扫出 33 处未定义引用,其中 refs / setDiagRev 是真缺陷(会在运行期 ReferenceError)。
// React / ReactDOM 由 index.html 的 CDN script 注入,属只读全局
globals: {
...globals.browser, ...globals.es2022, React: 'readonly', ReactDOM: 'readonly',
// 由 src/canvas-actions.js、src/canvas-node-factory.js 挂在 window 上(跨文件全局)
CanvasActions: 'readonly', CanvasNodeFactory: 'readonly',
// 由 src/workspace-purge.js 挂载(v3.24.76:彻底删除的连带清理,含清标签/session/objectURL)
IWBWorkspacePurge: 'readonly',
},
},
linterOptions: { reportUnusedDisableDirectives: true },
rules: { ...sharedRules, 'no-undef': 'error' },
},
]