- React Design Patterns and Best Practices(Second Edition)
- Carlos Santana Roldán
- 173字
- 2021-06-24 15:43:41
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.
推薦閱讀
- MERN Quick Start Guide
- Twilio Cookbook
- OpenLayers Cookbook
- 新一代物聯網架構技術:分層算力網絡
- 計算機網絡安全實訓教程(第二版)
- 互聯網基礎資源技術與應用發展態勢(2021—2023)
- 網絡安全技術與解決方案(修訂版)
- 網管員必讀:網絡管理(第2版)
- WordPress Web Application Development
- OMNeT++與網絡仿真
- 一本書讀懂物聯網
- 物聯網的機遇與利用
- Corona SDK Application Design
- 視聽變革:廣電的新媒體戰略
- Hands-On Cloud:Native Microservices with Jakarta EE