@5rabbits/eslint-config 中文文档教程
5rabbits ESLint config
Lemontech 产品的共享 ESLint 配置。
Installation
- Install
@5rabbits/eslint-config
and its dependencies:
$ export PKG=@5rabbits/eslint-config && npm info $PKG peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs yarn add --dev $PKG
如果您有
.eslintrc
文件,请添加"extends": ["@5rabbits"]
。如果您没有
.eslintrc
文件,请在项目的根目录下创建它:
$ echo '{\n "extends": ["@5rabbits"]\n}' > .eslintrc
Usage
- Add a
lint
script to yourpackage.json
:
{
"scripts": {
"lint": "eslint . --ext .js,.jsx"
}
}
- Run with
yarn lint
to check the entire project.
Prettier
如果项目使用 code>prettier(推荐),安装eslint-config-prettier
并将 "prettier"
附加到 .eslintrc
extends
数组。
Integrations
Git
您可以使用 husky
和 lint-staged
在提交之前对更改的文件进行 lint。 示例:
// package.json
{
"lint-staged": {
"*.{js,jsx}": ["eslint"]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
如果更改导致 lint 错误,提交将失败,直到您修复它们。
Webpack
使用 eslint-loader
在 webpack 构建中自动检查文件。
Rollup
使用 rollup-plugin-eslint
在汇总构建中自动检查文件。
5rabbits ESLint config
Shared ESLint configuration for Lemontech products.
Installation
- Install
@5rabbits/eslint-config
and its dependencies:
$ export PKG=@5rabbits/eslint-config && npm info $PKG peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs yarn add --dev $PKG
If you have an
.eslintrc
file, add"extends": ["@5rabbits"]
.If you don't have an
.eslintrc
file, create it on the root of your project:
$ echo '{\n "extends": ["@5rabbits"]\n}' > .eslintrc
Usage
- Add a
lint
script to yourpackage.json
:
{
"scripts": {
"lint": "eslint . --ext .js,.jsx"
}
}
- Run with
yarn lint
to check the entire project.
Prettier
If the projects uses prettier
(recommended), install eslint-config-prettier
and append "prettier"
to the .eslintrc
extends
array.
Integrations
Git
You can use husky
and lint-staged
to lint the changed files before commiting. Example:
// package.json
{
"lint-staged": {
"*.{js,jsx}": ["eslint"]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
If the changes causes lint errors the commit will fail until you fix them.
Webpack
Use eslint-loader
to automatically lint files on webpack builds.
Rollup
Use rollup-plugin-eslint
to automatically lint files on rollup builds.