@@ -1061,8 +1061,17 @@ limit_req_log_level warn;
10611061``` js
10621062// .eslintrc.js
10631063
1064- // $ pnpm add -D eslint@^8.0.0 eslint-config-airbnb eslint-plugin-import eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-config-airbnb-typescript @typescript-eslint/eslint-plugin@^7.0.0 @typescript-eslint/parser@^7.0.0 eslint-plugin-no-unsanitized eslint-plugin-react-perf @tanstack/eslint-plugin-query eslint-plugin-unicorn eslint-plugin-promise eslint-plugin-jsdoc eslint-plugin-eslint-comments
1064+ const airbnbReactRules = require (' eslint-config-airbnb/rules/react' );
1065+
10651066module .exports = {
1067+ parserOptions: {
1068+ project: [
1069+ ' ./tsconfig.json' ,
1070+ ' ./tsconfig.node.json' ,
1071+ ' ./tsconfig.test.json' ,
1072+ ],
1073+ },
1074+ // $ pnpm add -D eslint@^8.0.0 eslint-config-airbnb eslint-plugin-import eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-config-airbnb-typescript @typescript-eslint/eslint-plugin@^7.0.0 @typescript-eslint/parser@^7.0.0 eslint-plugin-no-unsanitized eslint-plugin-react-perf @tanstack/eslint-plugin-query eslint-plugin-unicorn eslint-plugin-promise eslint-plugin-jsdoc eslint-plugin-eslint-comments
10661075 extends: [
10671076 ' airbnb' ,
10681077 ' airbnb/hooks' ,
@@ -1078,6 +1087,48 @@ module.exports = {
10781087 ' plugin:jsdoc/recommended-typescript' ,
10791088 ' plugin:eslint-comments/recommended' ,
10801089 ],
1090+ rules: {
1091+ // React 17+ 不用再引入 React
1092+ ' react/react-in-jsx-scope' : ' off' ,
1093+ ' react/jsx-uses-react' : ' off' ,
1094+ // 常见的缩写是众所周知且易于阅读的
1095+ ' unicorn/prevent-abbreviations' : ' off' ,
1096+ // Airbnb 更喜欢使用 forEach
1097+ ' unicorn/no-array-for-each' : ' off' ,
1098+ },
1099+ overrides: [
1100+ {
1101+ files: ' *.tsx' ,
1102+ rules: {
1103+ ' react/require-default-props' : [airbnbReactRules .rules [' react/require-default-props' ][0 ], {
1104+ ... airbnbReactRules .rules [' react/require-default-props' ][1 ],
1105+ functions: ' defaultArguments' ,
1106+ }],
1107+ },
1108+ },
1109+ // $ pnpm add -D eslint-plugin-jest eslint-plugin-testing-library
1110+ {
1111+ files: [
1112+ ' ./tests/unit/**/*.{spec,test}.{js,jsx,ts,tsx}' ,
1113+ ' ./src/**/__tests__/**/*.{js,jsx,ts,tsx}' ,
1114+ ' ./src/**/*.{spec,test}.{js,jsx,ts,tsx}' ,
1115+ ],
1116+ extends: [
1117+ ' plugin:jest/recommended' ,
1118+ ' plugin:jest/style' ,
1119+ ' plugin:testing-library/react' ,
1120+ ]
1121+ },
1122+ // $ pnpm add -D eslint-plugin-playwright
1123+ {
1124+ files: [
1125+ ' ./tests/e2e/**/*.{js,ts}' ,
1126+ ],
1127+ extends: [
1128+ ' plugin:playwright/recommended' ,
1129+ ]
1130+ },
1131+ ],
10811132};
10821133```
10831134 </TabItem >
0 commit comments