2.1.2 • Published 2 years ago

eslint-config-banggood v2.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Eslint Config of Banggood

安装

NPM

npm i eslint eslint-config-banggood -D

YARN

yarn add eslint eslint-config-banggood -D

使用

普通 js 项目

{
  extends: ["banggood"]
}

普通 typescript 项目

{
  extends: ["banggood/typescript"],
  parserOptions: {
    project: "./tsconfig.json",
  },
}

vue 项目

# vue2
{
  extends: ["banggood/vue/vue2"]
}
# vue3
{
  extends: ["banggood/vue/vue3"]
}

vue typescript 项目

# vue2
{
  extends: ["banggood/vue-typescript/vue2"],
  parserOptions: {
    project: "./tsconfig.json",
  },
}
# vue3
{
  extends: ["banggood/vue-typescript/vue3"],
  parserOptions: {
    project: "./tsconfig.json",
  },
}

alias

npm install eslint-import-resolver-alias --save-dev
settings: {
  'import/resolver': {
    alias: {
      map: [['@', './src']],
      extensions: ['.vue', '.json', '.js'],
    },
  },
},

sonarqube

https://github.com/SonarSource/eslint-plugin-sonarjs

可以根据需要单独添加 sonarqube 部分规则配置,如下:

但是要注意这部分规则无法覆盖 sonarqube 的所有必要规则。

{
  extends: ["banggood", "banggood/sonar"]
}

prettier

此包已添加了 prettier, 可以直接在项目新建 prettier 配置文件,如下例:

# .prettierrc
singleQuote: true

配合 husky lint-staged 使用

step 1

npm install husky lint-staged -D
或
yarn add husky lint-staged -D

step 2

# 添加如下类似配置
# package.json
"scripts": {
  "prepare": "husky install"
},
"lint-staged": {
  "*.md": "prettier --write",
  "*.{ts,tsx,js,vue,less,scss}": "prettier --write",
  "*.{ts,tsx,js,vue}": "eslint --fix",
  "*.{vue,css,less,scss}": "stylelint --fix"
}

step 3

npx husky add .husky/pre-commit "npx --no-install lint-staged"

配合 vscode 使用

step1

安装 vscode eslint 插件

step2

# 配置保存自动修复
"editor.codeActionsOnSave": {
  "source.fixAll": true
}

注意点:

  • 最新版的 eslint v8 不再支持 node v10, win7 请使用 v12
  • 旧项目接入时请先删除所有除了@vue/cli-plugin-eslint 外的所有 eslint 相关的包
2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.0

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.1

3 years ago

0.4.2

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago