Skip to content

Commit 6efb9ee

Browse files
committed
home fixed eslint with prettier
1 parent cb141c0 commit 6efb9ee

23 files changed

+219
-221
lines changed

.prettierrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('@cs-magic/prettier-config')
1+
module.exports = require("@cs-magic/prettier-config")

apps/home-v2

packages/tools/eslint-config/README.md

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,19 @@ CS Magic 项目的共享 ESLint 配置。
1313
```js
1414
// 根目录 .eslintrc.js
1515
module.exports = {
16-
root: true,
17-
extends: [
18-
'@cs-magic/eslint-config/typescript-type-checked',
19-
'@cs-magic/eslint-config/prettier',
20-
],
21-
parserOptions: {
22-
project: ['./tsconfig.json', './packages/*/tsconfig.json'],
23-
},
24-
ignorePatterns: ['**/dist/**', '**/node_modules/**'],
16+
root: true,
17+
extends: ["@cs-magic/eslint-config/typescript-type-checked", "@cs-magic/eslint-config/prettier"],
18+
parserOptions: {
19+
project: ["./tsconfig.json", "./packages/*/tsconfig.json"],
20+
},
21+
ignorePatterns: ["**/dist/**", "**/node_modules/**"],
2522
}
2623
```
2724

2825
4. 如果遇到性能问题,可以:
29-
- 使用 `.eslintignore` 排除不需要检查的文件
30-
- 使用基础的 typescript 配置而不是 typescript-type-checked
31-
- 在 CI 中使用类型检查,本地开发时使用基础配置
26+
- 使用 `.eslintignore` 排除不需要检查的文件
27+
- 使用基础的 typescript 配置而不是 typescript-type-checked
28+
- 在 CI 中使用类型检查,本地开发时使用基础配置
3229

3330
## 安装
3431

@@ -37,6 +34,7 @@ npm install --save-dev @cs-magic/eslint-config
3734
```
3835

3936
## 使用
37+
4038
## 使用
4139

4240
创建 `.eslintrc.js` 文件:
@@ -45,10 +43,7 @@ npm install --save-dev @cs-magic/eslint-config
4543

4644
```js
4745
module.exports = {
48-
extends: [
49-
'@cs-magic/eslint-config/base',
50-
'@cs-magic/eslint-config/prettier',
51-
],
46+
extends: ["@cs-magic/eslint-config/base", "@cs-magic/eslint-config/prettier"],
5247
}
5348
```
5449

@@ -57,10 +52,7 @@ module.exports = {
5752
```js
5853
// .eslintrc.js
5954
module.exports = {
60-
extends: [
61-
'@cs-magic/eslint-config/typescript',
62-
'@cs-magic/eslint-config/prettier',
63-
],
55+
extends: ["@cs-magic/eslint-config/typescript", "@cs-magic/eslint-config/prettier"],
6456
}
6557
```
6658

@@ -69,12 +61,9 @@ module.exports = {
6961
```js
7062
// .eslintrc.js
7163
module.exports = {
72-
extends: [
73-
'@cs-magic/eslint-config/typescript-type-checked',
74-
'@cs-magic/eslint-config/prettier',
75-
],
64+
extends: ["@cs-magic/eslint-config/typescript-type-checked", "@cs-magic/eslint-config/prettier"],
7665
parserOptions: {
77-
project: './tsconfig.json',
66+
project: "./tsconfig.json",
7867
},
7968
}
8069
```
@@ -83,23 +72,17 @@ module.exports = {
8372

8473
```js
8574
module.exports = {
86-
extends: [
87-
'@cs-magic/eslint-config/react',
88-
'@cs-magic/eslint-config/prettier',
89-
],
75+
extends: ["@cs-magic/eslint-config/react", "@cs-magic/eslint-config/prettier"],
9076
}
9177
```
9278

9379
### Next.js 项目
9480

9581
```js
9682
module.exports = {
97-
extends: [
98-
'@cs-magic/eslint-config/next',
99-
'@cs-magic/eslint-config/prettier',
100-
],
83+
extends: ["@cs-magic/eslint-config/next", "@cs-magic/eslint-config/prettier"],
10184
parserOptions: {
102-
project: './tsconfig.json', // 如果需要类型检查
85+
project: "./tsconfig.json", // 如果需要类型检查
10386
},
10487
}
10588
```
@@ -132,9 +115,9 @@ public
132115

133116
```js
134117
module.exports = {
135-
extends: ['@cs-magic/eslint-config/react'],
118+
extends: ["@cs-magic/eslint-config/react"],
136119
rules: {
137120
// 你的自定义规则
138121
},
139122
}
140-
```
123+
```

packages/tools/eslint-config/package.json

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,37 @@
33
"version": "0.3.0",
44
"description": "Shared ESLint configurations for CS Magic projects",
55
"exports": {
6-
".": "./base.js",
7-
"./base": "./base.js",
8-
"./typescript": "./typescript.js",
9-
"./typescript-type-checked": "./typescript-type-checked.js",
10-
"./react": "./react.js",
11-
"./next": "./next.js",
12-
"./node": "./node.js",
13-
"./prettier": "./prettier.js"
6+
".": "./src/base.js",
7+
"./base": "./src/base.js",
8+
"./typescript": "./src/typescript.js",
9+
"./typescript-type-checked": "./src/typescript-type-checked.js",
10+
"./react": "./src/react.js",
11+
"./next": "./src/next.js",
12+
"./node": "./src/node.js",
13+
"./prettier": "./src/prettier.js"
1414
},
1515
"publishConfig": {
1616
"access": "public"
1717
},
1818
"files": [
19-
"base.js",
20-
"typescript.js",
21-
"typescript-type-checked.js",
22-
"react.js",
23-
"next.js",
24-
"node.js",
25-
"prettier.js"
19+
"src"
2620
],
2721
"peerDependencies": {
2822
"eslint": ">=8.0.0",
2923
"typescript": ">=4.0.0"
3024
},
3125
"devDependencies": {
26+
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
3227
"@typescript-eslint/eslint-plugin": "^6.0.0",
3328
"@typescript-eslint/parser": "^6.0.0",
34-
"eslint-config-prettier": "^9.0.0",
29+
"eslint-config-prettier": "^9.1.0",
3530
"eslint-import-resolver-typescript": "^3.6.0",
3631
"eslint-plugin-import": "^2.29.0",
3732
"eslint-plugin-jsx-a11y": "^6.8.0",
3833
"eslint-plugin-prettier": "^5.0.0",
3934
"eslint-plugin-react": "^7.33.0",
40-
"eslint-plugin-react-hooks": "^4.6.0"
35+
"eslint-plugin-react-hooks": "^4.6.0",
36+
"prettier-plugin-organize-imports": "^4.1.0"
4137
},
4238
"keywords": [
4339
"eslint",

packages/tools/eslint-config/prettier.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/tools/eslint-config/base.js renamed to packages/tools/eslint-config/src/base.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,7 @@ module.exports = {
1313
"no-var": "error",
1414
"prefer-const": "error",
1515
"no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
16-
"import/order": [
17-
"error",
18-
{
19-
groups: ["builtin", "external", "internal", "parent", "sibling", "index"],
20-
pathGroups: [
21-
{
22-
pattern: "contentlayer/generated",
23-
group: "internal",
24-
position: "after",
25-
},
26-
],
27-
"newlines-between": "always",
28-
alphabetize: { order: "asc" },
29-
},
30-
],
16+
"import/order": "off",
3117
},
3218

3319
settings: {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// prettier.js - Prettier 集成配置
2+
const prettierConfig = require("@cs-magic/prettier-config")
3+
const merge = require("lodash/merge")
4+
5+
module.exports = {
6+
extends: ["plugin:prettier/recommended"],
7+
rules: {
8+
"prettier/prettier": [
9+
"error",
10+
merge(prettierConfig, {
11+
importOrder: null,
12+
}),
13+
],
14+
},
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// typescript-type-checked.js - 需要类型信息的规则配置
2+
module.exports = {
3+
parser: "@typescript-eslint/parser",
4+
parserOptions: {
5+
project: true,
6+
},
7+
extends: [
8+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
9+
"plugin:@typescript-eslint/recommended-type-checked",
10+
"plugin:@typescript-eslint/stylistic-type-checked",
11+
"./typescript.js",
12+
],
13+
rules: {
14+
// 需要类型检查的规则
15+
"@typescript-eslint/no-floating-promises": "error",
16+
"@typescript-eslint/await-thenable": "error",
17+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
18+
"@typescript-eslint/restrict-template-expressions": "error",
19+
"@typescript-eslint/unbound-method": "error",
20+
"@typescript-eslint/no-misused-promises": "warn",
21+
},
22+
};
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// typescript.js - TypeScript 配置
2+
module.exports = {
3+
parser: "@typescript-eslint/parser",
4+
plugins: ["@typescript-eslint"],
5+
extends: ["plugin:import/typescript", "plugin:@typescript-eslint/recommended", "./base.js"],
6+
settings: {
7+
"import/resolver": {
8+
typescript: true,
9+
},
10+
},
11+
rules: {
12+
// TypeScript 特定规则
13+
"@typescript-eslint/explicit-module-boundary-types": "off",
14+
"@typescript-eslint/no-import-type-side-effects": "error",
15+
16+
// These opinionated rules are enabled in stylistic-type-checked above.
17+
// Feel free to reconfigure them to your own preference.
18+
"@typescript-eslint/array-type": "off",
19+
"@typescript-eslint/consistent-type-definitions": "off",
20+
21+
"@typescript-eslint/consistent-type-imports": [
22+
"warn",
23+
{
24+
prefer: "type-imports",
25+
fixStyle: "inline-type-imports",
26+
},
27+
],
28+
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
29+
"@typescript-eslint/require-await": "off",
30+
"@typescript-eslint/no-misused-promises": [
31+
"warn",
32+
{
33+
checksVoidReturn: { attributes: false },
34+
},
35+
],
36+
"@typescript-eslint/no-unsafe-call": "warn",
37+
"@typescript-eslint/no-unsafe-member-access": "warn",
38+
"@typescript-eslint/no-unsafe-assignment": "warn",
39+
"@typescript-eslint/no-empty-interface": "warn",
40+
"@typescript-eslint/no-unsafe-return": "warn",
41+
"@typescript-eslint/no-explicit-any": "warn",
42+
"@typescript-eslint/ban-ts-comment": "warn",
43+
"@typescript-eslint/no-floating-promises": "warn", // no-infer 没有意义
44+
"@typescript-eslint/no-inferrable-types": "off",
45+
"@typescript-eslint/prefer-nullish-coalescing": "warn",
46+
"@typescript-eslint/no-empty-function": "warn",
47+
"@typescript-eslint/no-namespace": "warn",
48+
"@typescript-eslint/no-redundant-type-constituents": "warn",
49+
"@typescript-eslint/dot-notation": "off",
50+
"@typescript-eslint/explicit-function-return-type": "off",
51+
"@typescript-eslint/no-unnecessary-type-assertion": "warn",
52+
"@typescript-eslint/no-unsafe-argument": "warn",
53+
"@typescript-eslint/no-unsafe-enum-comparison": "warn",
54+
"@typescript-eslint/no-var-requires": "warn",
55+
"@typescript-eslint/restrict-template-expressions": "warn",
56+
"@typescript-eslint/restrict-plus-operands": "warn",
57+
},
58+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// packages/tools/eslint-config/tsconfig.json
22
{
33
"extends": ["@cs-magic/ts-config"],
4-
"include": ["*.js"]
4+
"include": ["src/**.js"]
55
}

packages/tools/eslint-config/typescript-type-checked.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)