chore: 前后端引入代码检查工具并整改存量问题
为统一前后端代码规范与质量,前端引入 ESLint + Prettier,后端在 Spotless 之外新增 Checkstyle 与 SpotBugs,检查接入构建与打包流程并失败即阻断,同时一次性整改全部存量告警,检查范围为后端主源码与前端源码。 变更内容: - 前端新增 ESLint(flat config)与 Prettier 配置及 lint / lint:fix / format / format:check 脚本,并新增对应开发依赖 - 后端 build.gradle 应用 checkstyle 与 com.github.spotbugs 插件,新增 gradle/checkstyle/checkstyle.xml、suppressions.xml 与 gradle/spotbugs/exclude.xml - 新增 Gradle frontendLint 任务并作为 frontendBuild 前置,新增 lint 聚合任务(Spotless + Checkstyle + SpotBugs + 前端 ESLint) - 修复后端 Checkstyle 1 处(补花括号)与 SpotBugs 17 处(getParent() 判空、拆装箱冗余、异常捕获与日志、volatile 同步等),并按设计豁免值对象引用暴露等告警 - 修复前端规则问题(未使用变量、无意义赋值、v-for key、v-html 安全提示)并格式化存量文件 - README 补充依赖安装、代码检查与打包说明 说明: - SpotBugs 工具版本固定为 4.8.6,规避其 BCEL 与 Spring Boot BOM 选定 commons-lang3 3.14.0 的 NoSuchMethodError - 检查范围仅主源码,src/test/ 本地测试不纳入 Checkstyle/SpotBugs - 前端格式化统一为无分号、单引号、行宽 120、LF,与 .gitattributes 保持一致
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import js from '@eslint/js'
|
||||
import pluginVue from 'eslint-plugin-vue'
|
||||
import globals from 'globals'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import prettier from 'eslint-config-prettier'
|
||||
|
||||
export default tseslint.config(
|
||||
// 忽略构建产物与依赖目录
|
||||
{ ignores: ['dist/**', 'node_modules/**', 'public/**', 'src/**/*.d.ts'] },
|
||||
js.configs.recommended,
|
||||
...tseslint.configs.recommended,
|
||||
...pluginVue.configs['flat/recommended'],
|
||||
{
|
||||
// Vue 单文件组件的 <script lang="ts"> 交由 typescript-eslint 解析
|
||||
files: ['**/*.vue'],
|
||||
languageOptions: {
|
||||
parserOptions: { parser: tseslint.parser },
|
||||
},
|
||||
},
|
||||
{
|
||||
languageOptions: {
|
||||
globals: { ...globals.browser, ...globals.node },
|
||||
},
|
||||
rules: {
|
||||
// 存量大量 any 使用,暂不强制
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
// 单名单文件组件(Login/App/Calendar 等)为项目既有命名,不强制多词
|
||||
'vue/multi-word-component-names': 'off',
|
||||
// 泛型占位与解构忽略项允许;catch 绑定不强制使用(项目统一 catch (e) 写法)
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
argsIgnorePattern: '^_',
|
||||
varsIgnorePattern: '^_',
|
||||
caughtErrors: 'none',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
// 关闭与 Prettier 冲突的格式规则,必须放在最后
|
||||
prettier,
|
||||
)
|
||||
Reference in New Issue
Block a user