官术网_书友最值得收藏!

Airbnb React/JSX style guide

The Airbnb React/JSX style guide is the most popular style guide for coding in React. 

To implement the Airbnb React/JSX style guide, we need to install some packages:

npm install --save-dev babel-eslint eslint eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react

You can check all the ESLint rules on the official website (https://eslint.org/docs/rules) and all the special React ESLint rules at https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules.

The rules that I prefer not to use, or that I prefer to change the default values of, are as follows:

  • comma-dangle: Off
  • arrow-parens: Off
  • max-len: 120
  • no-param-reassign: Off
  • function-paren-newline: Off
  • react/require-default-props: Off

First, you need to create a new file called .eslintrc at the root level:

  {
"parser": "babel-eslint",
"extends": "airbnb",
"rules": {
"arrow-parens": "off",
"comma-dangle": "off",
"function-paren-newline": "off",
"max-len": [1, 120],
"no-param-reassign": "off",
"react/require-default-props": "off"
}
}

To run your linter, you have to add a lint script into your package.json file:

 {
"scripts": {
"lint": "eslint --ext .jsx,.js src"
}
}

Now you can lint your files using the Airbnb React/JSX style guide.

主站蜘蛛池模板: 青州市| 揭阳市| 姚安县| 大关县| 巴东县| 浙江省| 天水市| 济源市| 巴楚县| 黄山市| 天祝| 克东县| 庄浪县| 正镶白旗| 仁寿县| 柞水县| 宝坻区| 平乡县| 电白县| 富宁县| 甘泉县| 衡山县| 神农架林区| 安乡县| 光山县| 淮安市| 博野县| 弥勒县| 铜鼓县| 大同市| 始兴县| 呼玛县| 军事| 延庆县| 巴彦县| 吉水县| 高淳县| 赤壁市| 阿拉善左旗| 海口市| 驻马店市|