装它|不再用操心ESLint配置

你们是否像我同样苦 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', } 复制代码

react native

module.exports = {
 root: true,  extends: '@youngjuning/airbnb',  env: {  'react-native/react-native': true,  }, } 复制代码

vue with typescript

module.exports = {
 root: true,  extends: '@youngjuning/airbnb',  parserOptions: {  parser: '@typescript-eslint/parser',  }, } 复制代码

更多

.eslintignore

!.eslintrc.js
!.prettierrc.js 复制代码

.prettierrc.js

module.exports = {
 ...require('@youngjuning/eslint-config-airbnb/.prettierrc.js'), } 复制代码

.prettierignore

**/node_modules/*
复制代码

.editorconfig

# 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 复制代码

yorkie & lint-staged

$ 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

相关文章
相关标签/搜索