配置: - rustfmt.toml: 固化 max_width=100 / 4 空格缩进,cargo fmt 全量格式化 - Cargo.toml: 配置 [lints.rust] 与 [lints.clippy] 渐进式规则 - .github/workflows/ci.yml: Rust(fmt+clippy+test) + 前端(eslint+tsc+test) 双平台 CI - Makefile: 新增 check/fmt/fix 目标,clippy 对齐 --all-targets --all-features - web: eslint flat config + prettier 配置 + package.json 脚本与依赖 - src/main.rs: loop→while 修复 clippy::never_loop 对抗性审查发现并修复: - eslint 缺 caughtErrorsIgnorePattern 导致 catch(_) 误报为 error - 前端 lint 未接入 CI,现已补上 Lint 步骤 - Makefile 与 CI 的 clippy flags 不一致,已对齐
57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
import js from '@eslint/js';
|
||
import tseslint from 'typescript-eslint';
|
||
import reactHooks from 'eslint-plugin-react-hooks';
|
||
import reactRefresh from 'eslint-plugin-react-refresh';
|
||
import globals from 'globals';
|
||
|
||
export default tseslint.config(
|
||
// 全局忽略
|
||
{
|
||
ignores: ['dist/**', 'node_modules/**', 'coverage/**'],
|
||
},
|
||
// 基础推荐规则
|
||
js.configs.recommended,
|
||
...tseslint.configs.recommended,
|
||
{
|
||
files: ['src/**/*.{ts,tsx}'],
|
||
languageOptions: {
|
||
ecmaVersion: 2022,
|
||
globals: globals.browser,
|
||
},
|
||
plugins: {
|
||
'react-hooks': reactHooks,
|
||
'react-refresh': reactRefresh,
|
||
},
|
||
rules: {
|
||
// React Hooks 规则升级为 error(这是真正的 bug 来源)
|
||
...reactHooks.configs.recommended.rules,
|
||
'react-refresh/only-export-components': [
|
||
'warn',
|
||
{ allowConstantExport: true },
|
||
],
|
||
// 渐进式策略:TypeScript 推荐规则默认 warn,不阻断
|
||
// 仅把最关键的几个升级为 error
|
||
'@typescript-eslint/no-unused-vars': [
|
||
'error',
|
||
{
|
||
argsIgnorePattern: '^_',
|
||
varsIgnorePattern: '^_',
|
||
// catch (_) 是"故意忽略错误"的惯用法,单独配置项控制
|
||
caughtErrorsIgnorePattern: '^_',
|
||
},
|
||
],
|
||
'@typescript-eslint/no-explicit-any': 'warn',
|
||
// no-console 在测试环境外保留 console
|
||
'no-console': ['warn', { allow: ['warn', 'error'] }],
|
||
},
|
||
},
|
||
// 测试文件放宽规则
|
||
{
|
||
files: ['src/**/*.test.{ts,tsx}', 'src/test/**'],
|
||
rules: {
|
||
'@typescript-eslint/no-explicit-any': 'off',
|
||
'no-console': 'off',
|
||
},
|
||
},
|
||
);
|