@wetoria/eslint-config
v1.0.1
Published
Shared ESLint configuration for Wetoria projects
Readme
@wetoria/eslint-config
共享的 ESLint 配置包,基于 @antfu/eslint-config。
安装
pnpm add -D @wetoria/eslint-config @antfu/eslint-config eslint使用方法
方法 1: 直接使用默认配置
// eslint.config.mjs
import wetoriaEslint from '@wetoria/eslint-config'
export default wetoriaEslint方法 2: 使用函数式配置(推荐,支持扩展)
// eslint.config.mjs
import { createEslintConfig } from '@wetoria/eslint-config'
export default createEslintConfig({
type: 'app', // 或 'lib'
typescript: true,
formatters: true,
ignores: [
'custom-ignore-pattern',
],
rules: {
// 覆盖或添加自定义规则
'no-console': 'error',
},
stylistic: {
indent: 2,
quotes: 'single',
},
})方法 3: 进一步扩展
// eslint.config.mjs
import { createEslintConfig } from '@wetoria/eslint-config'
import antfu from '@antfu/eslint-config'
export default [
...createEslintConfig({
type: 'app',
rules: {
'custom-rule': 'warn',
},
}),
// 添加额外的配置
{
rules: {
'another-rule': 'error',
},
},
]方法 4: 使用基础配置模块
// eslint.config.mjs
import antfu from '@antfu/eslint-config'
import { baseRules, baseIgnores } from '@wetoria/eslint-config/base'
export default antfu(
{
type: 'lib',
ignores: [...baseIgnores, 'custom-ignore'],
},
{
rules: {
...baseRules,
'custom-rule': 'warn',
},
},
)配置选项
| 选项 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| type | 'lib' \| 'app' | 'lib' | 项目类型 |
| typescript | boolean | true | 是否启用 TypeScript |
| formatters | boolean | true | 是否启用格式化 |
| ignores | string[] | [] | 额外的忽略模式 |
| rules | Object | {} | 额外的规则覆盖 |
| stylistic | Object | { indent: 2, quotes: 'single' } | 样式配置 |
| extends | Function[] | [] | 额外的配置扩展函数 |
在 Monorepo 中使用
在 monorepo 中,可以在根目录使用,也可以在每个子项目中单独使用:
// 根目录 eslint.config.mjs
import { createEslintConfig } from '@wetoria/eslint-config'
export default createEslintConfig({
ignores: [
'packages/*/dist',
'apps/*/dist',
],
})更新配置
当需要更新共享配置时,只需修改 packages/eslint-config 中的文件,所有使用该配置的项目会自动获得更新(在 monorepo 中)或需要重新安装依赖。
