@qiaer/eslint-config-vue3
@qiaer/eslint-config-vue3
面向 Vue 3 + TypeScript 的 ESLint 可共享配置,继承 @qiaer/eslint-config,并启用 Vue 3 推荐规则与 TypeScript 规则。
特性
- 继承
@qiaer/eslint-config(Standard Style + ESLint 8) - 使用 vue-eslint-parser + @typescript-eslint/parser 解析
.vue、.ts、.tsx - 启用 plugin:vue/vue3-recommended、plugin:@typescript-eslint/recommended
- 内置 import 排序(Vue / @vue 优先、@element-plus 归为 internal)
- 针对
*.ts/*.vue关闭no-undef,测试目录放宽no-console - 自定义
vue/html-self-closing,关闭部分 TS 严格规则便于渐进采用
安装
npm
npm install @qiaer/eslint-config-vue3 --save-dev
yarn
yarn add @qiaer/eslint-config-vue3 --dev
pnpm
pnpm add @qiaer/eslint-config-vue3 --save-dev
使用
在项目根目录的 .eslintrc.js、.eslintrc.json 或 .eslintrc 中扩展本配置。
.eslintrc.js
module.exports = {
extends: ['@qiaer/eslint-config-vue3'],
}
.eslintrc.json
{
"extends": "@qiaer/eslint-config-vue3"
}
覆盖规则
module.exports = {
extends: ['@qiaer/eslint-config-vue3'],
rules: {
'vue/multi-word-component-names': 'error',
'@typescript-eslint/no-explicit-any': 'warn',
},
}
主要规则
TypeScript
- @typescript-eslint/consistent-type-imports:类型导入使用
type关键字 - explicit-module-boundary-types / no-explicit-any / no-non-null-*:默认关闭,可按需开启
Vue
- vue/html-self-closing:void / 组件自闭合,普通 HTML 不自闭合
- vue/no-v-html、vue/require-default-prop、vue/require-explicit-emits、vue/multi-word-component-names:默认关闭
Import
- import/first、import/no-duplicates:error
- import/order:分组排序,Vue / @vue 置前,@element-plus 为 internal
命令行
npx eslint . --ext .js,.ts,.vue
npx eslint . --ext .js,.ts,.vue --fix
更新日志
v1.0.0-beta.0
- 依赖
@qiaer/eslint-config升级为 ^1.0.0-beta.0 - 升级 ESLint 至 ^8.57.0,@typescript-eslint/* 至 ^7.18.0,TypeScript 至 ^5.0.0
- 升级 eslint-plugin-vue 至 ^9.22.0,新增 vue-eslint-parser ^9.4.3
- 移除 eslint-define-config,配置改为直接
module.exports - 增加 exports、files、engines,统一脚本为
--config=index.js - parserOptions 增加 ecmaVersion: 2022
- 完善 README(npm/yarn/pnpm、使用方式、规则说明)
说明:当前使用 file:../eslint-config 链接本地包,便于 Lerna 开发。发布前需将依赖改回版本号(如 ^1.0.0-beta.0)再执行 lerna publish,否则发布后的包无法正确安装。
许可证
MIT
Related Packages
Version History
| Version | Released | License |
|---|---|---|
| 0.1.3 | ISC |