eslint-config-airbnb-vue3-ts

结合了 airbnb 和 prettier 风格规范的 eslint 配置,适用于 vue3、js、ts 项目。
4,966 7
Install
npm install eslint-config-airbnb-vue3-ts
Latest Version:0.3.1
License:MIT
Last Updated:Jun 27, 2024
Links: GitHub  ·  npm
Maintainer: bin-xzl

eslint-config-airbnb-vue3-ts

结合了 airbnb 和 prettier 风格规范的 eslint 配置,适用于 vue3、js、ts 项目。

使用

npm i -D eslint-config-airbnb-vue3-ts

配置 .eslintrc.js 文件:

module.exports = {
  root: true,
  env: {
    browser: true,
    node: true,
    es6: true,
  },
  extends: ['eslint-config-airbnb-vue3-ts'],
  rules: {
    // nestjs 请关闭以下规则,避免造成程序报错
    // '@typescript-eslint/consistent-type-imports': 'off',
    // 'no-empty-function': 'off',
    // 'no-useless-constructor': 'off',
    // 'max-classes-per-file': 'off',
  },
}

配置 .prettierrc.json 文件:

{
  "$schema": "https://json.schemastore.org/prettierrc",
  "singleQuote": true,
  "semi": false,
  "printWidth": 120,
  "tabWidth": 2,
  "useTabs": false,
  "jsxSingleQuote": false,
  "bracketSameLine": false,
  "jsxBracketSameLine": false,
  "trailingComma": "all"
}

配置 .vscode/settings.json 文件,当保存代码时使用 prettier 格式化代码:

{
  "editor.codeActionsOnSave": {
    "source.fixAll": "explicit"
  },
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode"
}

配置 .vscode/extensions.json 文件:

{
  "recommendations": ["Vue.volar", "dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}

这个 eslint 插件将代码格式化的规则都禁用掉了,因为项目代码特别多的时候,eslint 格式化会很慢,经常需要等待。

所以在 eslint 只保留了代码错误的检查,代码格式化的工作需要使用 vsocde + prettier 插件来完成。但是这只会在保存代码的时候格式化代码,不会在提交代码的时候格式化代码。

所以需要配置 ci/cd 工具来在提交代码的时候格式化代码,例如可以使用 lint-staged + husky 来实现。

PS:这里提供了一个 DEMO 以供参考,如果你觉得配置不生效或者出错了,可以参考这个示例。

Related Packages

@vue/eslint-config-airbnb

eslint-config-standard for Vue.js projects

6,445,725 74
@vue/eslint-config-airbnb-with-typescript

eslint-config-airbnb for Vue.js projects with TypeScript support

1,501,629 74
@forsakringskassan/eslint-config-vue

Försäkringskassans eslint shareable vue config

286,740 0
@scayle/eslint-config-storefront

SCAYLE Commerce Engine specific eslint configuration

218,314

Version History

Version Released License
0.3.1 MIT
0.3.0 MIT
0.2.4 MIT
0.2.3 MIT
0.2.2 MIT