你们是否像我同样苦 ESlint 久已呢?只是配置一个代码格式化工具,动辄10几个依赖。依赖之间又相互依赖,版本错误,配置顺序错误都会致使失效。html
就算熟练掌握了 ESLint 配置,可是换了项目,又要从新配置。若是是从React切换到Vue项目,状况会更糟糕,你不得不额外作一些无心义的配置工做。而我今天带来的 @youngjuning/eslint-config-airbnb 即是用来把你从繁琐的 ESLint 配置工做中解放出来的一款插件。vue
一款基于 airbnb 的强大的 eslint 配置插件,支持 vue、jsx、js、ts、tsx、html、jest,致力于把你从繁琐的 ESLint 配置工做中解放出来。node
首先,为了不冲突,请移除项目中已存在的配置,你能够保留 rulesreact
$ yarn add -D @youngjuning/eslint-config-airbnb
复制代码
Add to your eslint config (.eslintrc.js
):git
module.exports = {
root: true, extends: '@youngjuning/airbnb', } 复制代码
module.exports = {
root: true, extends: '@youngjuning/airbnb', env: { 'react-native/react-native': true, }, } 复制代码
module.exports = {
root: true, extends: '@youngjuning/airbnb', parserOptions: { parser: '@typescript-eslint/parser', }, } 复制代码
!.eslintrc.js !.prettierrc.js 复制代码
module.exports = {
...require('@youngjuning/eslint-config-airbnb/.prettierrc.js'), } 复制代码
**/node_modules/*
复制代码
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file root = true # Unix-style newlines with a newline ending every file [*] indent_style = space indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false [*.gradle] indent_size = 4 [BUCK] indent_size = 4 复制代码
$ yarn add -D yorkie lint-staged
复制代码
{
"gitHooks": { "pre-commit": "lint-staged" }, "lint-staged": { "*.{js,jsx,ts,tsx}": [ "eslint --fix", "git add" ], // you can add wxml/html... "*.{less,md,json}": [ "prettier --write", "git add" ] }, } 复制代码
本文首发于杨俊宁的博客,创做不易,您的点赞👍是我坚持的动力github