Skip to content

Commit 27a3cb2

Browse files
committed
更新规范解释和说明,更新eslint配置文件
1 parent c8b3729 commit 27a3cb2

File tree

5 files changed

+224
-155
lines changed

5 files changed

+224
-155
lines changed

docs/reference/configuration/README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
10651066
module.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>

docs/specification/code/javascript/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ module.exports = {
679679

680680
## ESLint 注释
681681

682-
[`eslint-plugin-eslint-comments`](https://github.com/mysticatea/eslint-plugin-eslint-comments) 用于规范代码中ESLint注释的使用,防止不必要的禁用规则注释,确保规则禁用的原因清晰。
682+
[`eslint-plugin-eslint-comments`](https://github.com/mysticatea/eslint-plugin-eslint-comments) 用于规范代码中 ESLint 注释(例如 `/* eslint-disable */`)的使用,防止不必要的禁用规则注释,确保规则禁用的原因清晰。
683683

684684
```js
685685
// .eslintrc.js

docs/specification/code/jest/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ sidebar_position: 9
44

55
# Jest 规范
66

7+
[eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) 针对 Jest 测试框架的推荐规则,用于确保测试文件的语法和最佳实践符合 Jest 的要求,例如检查测试用例的命名、断言的使用等。
8+
79
```js
810
// .eslintrc.js
911

docs/specification/code/nextjs/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ sidebar_position: 8
44

55
# Next.js 规范
66

7+
[eslint-plugin-next](https://nextjs.org/docs/app/api-reference/config/eslint) 是针对 Next.js 框架的官方推荐规则集。它会检查 Next.js 项目中的常见错误和最佳实践,例如确保 `next/image` 组件的正确使用,或者 `Link` 组件的 `href` 属性格式正确等,有助于编写符合 Next.js 规范的代码。
8+
9+
```js
10+
// .eslintrc.js
11+
12+
module.exports = {
13+
extends: [
14+
'plugin:@next/next/recommended',
15+
],
16+
};
17+
```
18+
719
| 规则名称 | 错误级别 | 配置选项 | 描述 |
820
|----------|----------|----------|------|
921
| [`@next/next/google-font-display`](https://nextjs.org/docs/messages/google-font-display) | warn | - | 强制在Google Font链接中指定`display`属性 |

0 commit comments

Comments
 (0)