67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
const globals = require('globals');
|
|
const react = require('eslint-plugin-react');
|
|
const reactHooks = require('eslint-plugin-react-hooks');
|
|
const unusedImports = require('eslint-plugin-unused-imports');
|
|
const { uiDependencyConfig } = require('./scripts/ui-dependency-policy.cjs');
|
|
|
|
module.exports = [
|
|
{
|
|
ignores: [
|
|
'**/.*',
|
|
'dist/**',
|
|
'node_modules/**',
|
|
'logs/**',
|
|
'report/**',
|
|
'playwright-report/**',
|
|
'test-results/**',
|
|
'blob-report/**',
|
|
'src/assets/brand-icons/*.js',
|
|
],
|
|
},
|
|
uiDependencyConfig,
|
|
{
|
|
files: ['**/*.{js,jsx}'],
|
|
linterOptions: { reportUnusedDisableDirectives: 'off' },
|
|
languageOptions: {
|
|
ecmaVersion: 2022,
|
|
sourceType: 'module',
|
|
parserOptions: { ecmaFeatures: { jsx: true } },
|
|
globals: { ...globals.browser, ...globals.node, ...globals.es2021 },
|
|
},
|
|
settings: { react: { version: 'detect' } },
|
|
plugins: {
|
|
react,
|
|
'react-hooks': reactHooks,
|
|
'unused-imports': unusedImports,
|
|
},
|
|
rules: {
|
|
'no-multiple-empty-lines': ['error', { max: 1 }],
|
|
|
|
// ===== 防线:杜绝“用了未定义/未导入标识符”导致的运行时崩溃(本次线上事故根因)=====
|
|
// 让规则识别 JSX 中使用到的组件/React,避免误报。
|
|
'react/jsx-uses-vars': 'error',
|
|
'react/jsx-uses-react': 'error',
|
|
// 未定义标识符 = 直接报错(构建/CI 即拦截)。
|
|
'no-undef': 'error',
|
|
// 未使用的 import = error 且可 --fix 自动移除(含 JSX/副作用识别);
|
|
// 未使用的变量 = warn(不阻断,下划线前缀豁免)。
|
|
'no-unused-vars': 'off',
|
|
'unused-imports/no-unused-imports': 'error',
|
|
'unused-imports/no-unused-vars': [
|
|
'warn',
|
|
{
|
|
vars: 'all',
|
|
varsIgnorePattern: '^_',
|
|
args: 'none',
|
|
caughtErrors: 'none',
|
|
argsIgnorePattern: '^_',
|
|
ignoreRestSiblings: true,
|
|
},
|
|
],
|
|
// React Hooks 规则。
|
|
'react-hooks/rules-of-hooks': 'error',
|
|
'react-hooks/exhaustive-deps': 'warn',
|
|
},
|
|
},
|
|
];
|