@hcwhan/eslint-config
v1.0.8
Published
hcwhan's personal ESLint flat config presets, modular and opt-in.
Maintainers
Readme
@hcwhan/eslint-config
hcwhan 个人的 ESLint Flat Config 预设,单一入口 hcwhan() 工厂,按开关懒加载子配置。
特性
- 单一入口
hcwhan()工厂,按开关加载formatters/stylistic/unocss/globals/javascript/typescript/vue - 可选集成(UnoCSS/Vue)通过动态
import懒加载,未开启时不拉取对应 peer - 完全基于 TypeScript,附带
.d.ts类型定义 - 基于 ESLint Flat Config 标准
- 内置
@stylistic/eslint-plugin统一代码格式化
安装
pnpm add -D eslint @hcwhan/eslint-config按需加装 optional peer:
| 场景 | 需要安装 |
|---|---|
| UnoCSS | pnpm add -D @unocss/eslint-plugin |
| TypeScript | pnpm add -D typescript |
| Vue | pnpm add -D eslint-plugin-vue vue-eslint-parser |
快速开始
在项目根目录新建 eslint.config.mjs:
import hcwhan from '@hcwhan/eslint-config'
export default await hcwhan({
ignores: ['dist'],
})默认启用 formatters/stylistic/javascript/typescript;globals 不默认注入,需要时显式传入运行环境;如需 UnoCSS 或 Vue,显式打开:
export default await hcwhan({
ignores: ['dist'],
unocss: true,
vue: true,
})API
hcwhan(options?) 是一个 async 工厂函数,返回 Promise<Linter.Config[]>。options 整体可选,缺省等价于开启 formatters/stylistic/javascript/typescript、关闭 unocss/vue,且不注入任何 globals。
options
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| ignores | string[] | [] | 顶层 ignores 数组 |
| formatters | boolean | true | MD/JSON/YAML/TOML/CSS/HTML 格式化 |
| stylistic | boolean | true | @stylistic/* 规则 |
| unocss | boolean | false | UnoCSS 规则 |
| globals | 'node' \| 'browser' \| 'both' \| Linter.Globals | undefined | 为 JS/TS/Vue 注入 languageOptions.globals,未设置则不注入 |
| javascript | boolean | true | JS 核心规则(含 import-x / unused-imports / node / unicorn / regexp) |
| typescript | boolean | true | TypeScript 规则(同步加载,typescript-eslint 作为 dependency 随包提供) |
| vue | boolean | false | Vue 规则 |
开发
pnpm install
pnpm build # tsc -> dist/
pnpm run config # 重新生成 config/*.json 快照
pnpm lint # 自 lint许可
ISC
