Skip to content

Commit f4e0900

Browse files
authored
chore: upgrade lint toolchain (#6901)
* fix: build docs * fix: deps
1 parent dffae73 commit f4e0900

13 files changed

Lines changed: 1238 additions & 342 deletions

File tree

.github/workflows/build-docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ jobs:
109109
username: ${{ secrets.FASTGPT_ALI_IMAGE_USER }}
110110
password: ${{ secrets.FASTGPT_ALI_IMAGE_PSW }}
111111

112+
- name: Prepare Docker workspace catalog
113+
run: cp pnpm-workspace.yaml document/pnpm-workspace.yaml
114+
112115
- name: Build and push Docker images (CN)
113116
if: matrix.domain_config.suffix == 'cn'
114117
uses: docker/build-push-action@v5

.github/workflows/preview-docs-build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ jobs:
2828
- name: Set up Docker Buildx
2929
uses: docker/setup-buildx-action@v3
3030

31+
- name: Prepare Docker workspace catalog
32+
run: cp pnpm-workspace.yaml document/pnpm-workspace.yaml
33+
3134
- name: Build Docker image (no push)
3235
uses: docker/build-push-action@v6
3336
with:

document/.textlintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
content/**/*.en.mdx

document/.textlintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"plugins": ["mdx"],
3+
"rules": {
4+
"preset-zh-technical-writing": true
5+
}
6+
}

document/content/self-host/upgrading/4-15/4150.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ FILE_TOKEN_KEY=
7070

7171
## 代码优化
7272

73-
1. 重新调整代码结构,升级 nextjs 最新版,切换至 turbopack 构建,提高构建速度;升级容器默认 node 至 24。
73+
1. 重新调整代码结构,升级 Next.js 最新版,切换至 Turbopack 构建,提高构建速度;升级容器默认 Node.js 至 24。
7474
2. 优化 Agent tool 声明和运行,统一所有 tool 的声明和运行方式。
7575
3. 文件上传内容从 system prompt 中放到 user message 中,提高 cache 命中率。
76-
4. 服务端 env 加载全部使用`@t3-oss/env-core`,增加更多类型检查。其余服务,也采用集中导出 env 的方式进行环境变量使用。
76+
4. 服务端 env 加载全部使用 `@t3-oss/env-core`,增加更多类型检查。其余服务,也采用集中导出 env 的方式进行环境变量使用。
77+
5. 升级了项目工程化工具链版本,包括 ESLint、Prettier、textlint 和 lint-staged 工具。

document/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"dev": "next dev --turbo",
99
"start": "next start",
1010
"postinstall": "fumadocs-mdx",
11-
"format-doc": "pnpx zhlint --dir ./ *.mdx --fix",
11+
"format-doc": "pnpm exec textlint --fix \"content/**/*.mdx\" && pnpm exec prettier --config ../.prettierrc.js --write \"**/*.mdx\" && pnpm exec textlint \"content/**/*.mdx\"",
12+
"lint-doc:text": "pnpm exec textlint \"content/**/*.mdx\"",
1213
"initDocTime": "node ./script/initDocTime.js",
1314
"initDocToc": "node ./script/generateToc.js",
1415
"checkDocRefs": "node ./script/checkDocRefs.js",
@@ -47,8 +48,10 @@
4748
"@types/react-dom": "^19.1.6",
4849
"postcss": "^8.5.10",
4950
"tailwindcss": "^4.1.11",
51+
"textlint": "catalog:lint",
52+
"textlint-plugin-mdx": "catalog:lint",
53+
"textlint-rule-preset-zh-technical-writing": "catalog:lint",
5054
"typescript": "^5.8.3",
51-
"zhlint": "^0.8.2",
5255
"zod": "^4.0.5"
5356
}
5457
}

lint-staged.config.mjs

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@ import path from 'node:path';
33
const quoteFiles = (files) =>
44
files.map((file) => JSON.stringify(path.relative(process.cwd(), file))).join(' ');
55

6+
const toAbsolutePath = (file) => (path.isAbsolute(file) ? file : path.resolve(process.cwd(), file));
7+
8+
const quoteDocumentFiles = (files) =>
9+
files
10+
.map((file) =>
11+
JSON.stringify(path.relative(path.join(process.cwd(), 'document'), toAbsolutePath(file)))
12+
)
13+
.join(' ');
14+
15+
const quoteDocumentArtifactPaths = () =>
16+
[
17+
'document/data/doc-last-modified.json',
18+
'document/content/toc.mdx',
19+
'document/content/toc.en.mdx'
20+
]
21+
.map((file) => JSON.stringify(file))
22+
.join(' ');
23+
24+
const withoutTranslatedDocumentFiles = (files) =>
25+
files.filter((file) => {
26+
const documentPath = path.relative(path.join(process.cwd(), 'document'), toAbsolutePath(file));
27+
return !/\.[a-z]{2}\.mdx$/.test(documentPath);
28+
});
29+
630
const withoutIgnoredPaths = (files) =>
731
files.filter((file) => {
832
const relativePath = path.relative(process.cwd(), file);
@@ -17,17 +41,29 @@ const withoutIgnoredPaths = (files) =>
1741
});
1842

1943
export default {
20-
'./document/**/**/*.mdx': (files) =>
21-
files.length === 0
22-
? []
23-
: [
24-
'pnpm -C ./document run format-doc',
25-
'pnpm -C ./document run initDocTime',
26-
'pnpm -C ./document run initDocToc',
27-
'pnpm -C ./document run checkDocRefs',
28-
'pnpm -C ./document run removeInvalidImg',
29-
'git add .'
30-
],
44+
'./document/**/**/*.mdx': (files) => {
45+
if (files.length === 0) return [];
46+
47+
const filenames = quoteDocumentFiles(files);
48+
const textlintFiles = withoutTranslatedDocumentFiles(files);
49+
const textlintFilenames = quoteDocumentFiles(textlintFiles);
50+
51+
return [
52+
...(textlintFiles.length > 0
53+
? [`pnpm -C ./document exec textlint --fix ${textlintFilenames}`]
54+
: []),
55+
`pnpm -C ./document exec prettier --config ../.prettierrc.js --write ${filenames}`,
56+
...(textlintFiles.length > 0
57+
? [`pnpm -C ./document exec textlint ${textlintFilenames}`]
58+
: []),
59+
'pnpm -C ./document run initDocTime',
60+
'pnpm -C ./document run initDocToc',
61+
'pnpm -C ./document run checkDocRefs',
62+
'pnpm -C ./document run removeInvalidImg',
63+
`git add -- ${quoteDocumentArtifactPaths()}`,
64+
'git add -u -- document/public/imgs'
65+
];
66+
},
3167
'**/*.{ts,tsx}': (files) => {
3268
const lintFiles = withoutIgnoredPaths(files);
3369
if (lintFiles.length === 0) return [];

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@
2828
"devDependencies": {
2929
"@chakra-ui/cli": "^2.4.1",
3030
"@vitest/coverage-v8": "catalog:",
31-
"eslint": "catalog:eslint",
32-
"eslint-config-next": "catalog:eslint",
31+
"eslint": "catalog:lint",
32+
"eslint-config-next": "catalog:lint",
3333
"husky": "^8.0.3",
3434
"i18next": "catalog:",
3535
"js-yaml": "catalog:",
36-
"lint-staged": "catalog:",
36+
"lint-staged": "catalog:lint",
3737
"mongodb-memory-server": "catalog:",
3838
"next-i18next": "catalog:",
39-
"prettier": "catalog:",
39+
"prettier": "catalog:lint",
4040
"react-i18next": "catalog:",
4141
"turbo": "2.9.9",
42-
"typescript-eslint": "catalog:eslint",
42+
"typescript-eslint": "catalog:lint",
4343
"typescript": "catalog:",
4444
"vitest": "catalog:"
4545
},

0 commit comments

Comments
 (0)