@gua-os/eslint-config
v1.0.1
Published
Gua 开源 ESLint flat 配置(Alloy + Vue + TypeScript + Prettier 兼容)
Downloads
79
Maintainers
Readme
@gua-os/eslint-config
封装与 @gua/framework 同源的 ESLint 9 flat 规则栈:@eslint/js、typescript-eslint、eslint-plugin-vue、eslint-config-alloy、eslint-config-prettier、globals。
实现语言为 TypeScript(src/eslint.config.ts),发布与本地 pnpm install 时通过 tsc 编译到 dist/eslint.config.js;包入口 exports 指向编译产物,无需 jiti。修改源码后执行 pnpm run build(prepare / prepack 也会自动执行)。
与 docs/编码规范.md 的对齐(本包默认覆盖 Alloy)
在 Alloy 之上增加 codingStandardRules,落实文档中可自动检查的条款:
| 文档要点 | ESLint |
| -------- | ------ |
| SFC 顺序:<template> → <script> → <style> | vue/block-order;关闭已弃用的 vue/component-tags-order |
| <script> 必须使用 lang="ts" | vue/block-lang(仅约束 script) |
| 样式默认 scoped,允许第二段无 scoped(文档中的全局样式例外) | vue/enforce-style-attribute:scoped + plain |
| 仅 <script setup> 组合式 | vue/component-api-style: ['script-setup'] |
| defineProps / defineEmits 用 TS 泛型 | vue/define-props-declaration、vue/define-emits-declaration:type-based |
| 避免 any | @typescript-eslint/no-explicit-any: warn(渐进;可传入 eslint({ ... }) 改为 error / off) |
文档未在本包中自动落实的示例(仍需评审或另加插件):src/** 下文件 kebab-case、禁止 .js 业务文件、单向数据流与目录结构等。
在业务项目中使用
1. 依赖
pnpm add -D eslint typescript @gua-os/eslint-config
# 或从本仓库子包路径 / npm pack 产物安装,见下2. eslint.config.mjs
import { eslint } from '@gua-os/eslint-config';
export default eslint({
// 按需覆盖 codingStandardRules / Alloy,例如关闭 any 提示:
// '@typescript-eslint/no-explicit-any': 'off',
});3. 脚本
ESLint 9 推荐:
{
"scripts": {
"lint": "eslint . --fix"
}
}