- 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.
推薦閱讀
- 黑客攻防實(shí)戰(zhàn)技術(shù)完全手冊(cè):掃描、嗅探、入侵與防御
- 網(wǎng)管員典藏書(shū)架:網(wǎng)絡(luò)管理與運(yùn)維實(shí)戰(zhàn)寶典
- 物聯(lián)網(wǎng)識(shí)別技術(shù)
- Twilio Cookbook
- 通信簡(jiǎn)史:從信鴿到6G+
- Learning Swift(Second Edition)
- Spring 5.0 Projects
- TD-LTE無(wú)線網(wǎng)絡(luò)規(guī)劃與設(shè)計(jì)
- Scala Design Patterns.
- 現(xiàn)場(chǎng)綜合化網(wǎng)絡(luò)運(yùn)營(yíng)與維護(hù):運(yùn)營(yíng)商數(shù)字化轉(zhuǎn)型技術(shù)與實(shí)踐
- 算力網(wǎng)絡(luò):云網(wǎng)融合2.0時(shí)代的網(wǎng)絡(luò)架構(gòu)與關(guān)鍵技術(shù)
- Building Microservices with Spring
- 物聯(lián)網(wǎng)商業(yè)設(shè)計(jì)與案例
- SD-WAN 架構(gòu)與技術(shù)
- 國(guó)外物聯(lián)網(wǎng)透視