@aigne/doc-smith 0.8.12-beta.8 → 0.8.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/agents/publish/index.yaml +4 -0
- package/agents/publish/publish-docs.mjs +77 -5
- package/agents/publish/translate-meta.mjs +103 -0
- package/agents/update/generate-document.yaml +30 -28
- package/agents/update/update-document-detail.yaml +3 -1
- package/agents/utils/update-branding.mjs +69 -0
- package/package.json +16 -2
- package/prompts/common/document/role-and-personality.md +3 -1
- package/prompts/detail/d2-diagram/guide.md +7 -1
- package/prompts/detail/d2-diagram/user-prompt.md +3 -0
- package/prompts/detail/generate/system-prompt.md +6 -7
- package/prompts/detail/generate/user-prompt.md +12 -3
- package/prompts/detail/update/user-prompt.md +0 -2
- package/prompts/structure/update/user-prompt.md +0 -4
- package/utils/file-utils.mjs +69 -24
- package/utils/markdown-checker.mjs +0 -20
- package/utils/request.mjs +7 -0
- package/utils/upload-files.mjs +231 -0
- package/utils/utils.mjs +11 -1
- package/.aigne/doc-smith/config.yaml +0 -77
- package/.aigne/doc-smith/history.yaml +0 -37
- package/.aigne/doc-smith/media-description.yaml +0 -91
- package/.aigne/doc-smith/output/structure-plan.json +0 -162
- package/.aigne/doc-smith/preferences.yml +0 -97
- package/.aigne/doc-smith/upload-cache.yaml +0 -1830
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -28
- package/.github/workflows/ci.yml +0 -54
- package/.github/workflows/create-release-pr.yaml +0 -21
- package/.github/workflows/publish-docs.yml +0 -65
- package/.github/workflows/release.yml +0 -49
- package/.github/workflows/reviewer.yml +0 -54
- package/.release-please-manifest.json +0 -3
- package/RELEASE.md +0 -9
- package/assets/screenshots/doc-complete-setup.png +0 -0
- package/assets/screenshots/doc-generate-docs.png +0 -0
- package/assets/screenshots/doc-generate.png +0 -0
- package/assets/screenshots/doc-generated-successfully.png +0 -0
- package/assets/screenshots/doc-publish.png +0 -0
- package/assets/screenshots/doc-regenerate.png +0 -0
- package/assets/screenshots/doc-translate-langs.png +0 -0
- package/assets/screenshots/doc-translate.png +0 -0
- package/assets/screenshots/doc-update.png +0 -0
- package/biome.json +0 -73
- package/codecov.yml +0 -15
- package/docs/_sidebar.md +0 -15
- package/docs/configuration-initial-setup.ja.md +0 -179
- package/docs/configuration-initial-setup.md +0 -198
- package/docs/configuration-initial-setup.zh-TW.md +0 -179
- package/docs/configuration-initial-setup.zh.md +0 -179
- package/docs/configuration-managing-preferences.ja.md +0 -100
- package/docs/configuration-managing-preferences.md +0 -100
- package/docs/configuration-managing-preferences.zh-TW.md +0 -100
- package/docs/configuration-managing-preferences.zh.md +0 -100
- package/docs/configuration.ja.md +0 -69
- package/docs/configuration.md +0 -69
- package/docs/configuration.zh-TW.md +0 -69
- package/docs/configuration.zh.md +0 -69
- package/docs/getting-started.ja.md +0 -107
- package/docs/getting-started.md +0 -107
- package/docs/getting-started.zh-TW.md +0 -107
- package/docs/getting-started.zh.md +0 -107
- package/docs/guides-cleaning-up.ja.md +0 -51
- package/docs/guides-cleaning-up.md +0 -52
- package/docs/guides-cleaning-up.zh-TW.md +0 -51
- package/docs/guides-cleaning-up.zh.md +0 -51
- package/docs/guides-evaluating-documents.ja.md +0 -66
- package/docs/guides-evaluating-documents.md +0 -107
- package/docs/guides-evaluating-documents.zh-TW.md +0 -66
- package/docs/guides-evaluating-documents.zh.md +0 -66
- package/docs/guides-generating-documentation.ja.md +0 -151
- package/docs/guides-generating-documentation.md +0 -89
- package/docs/guides-generating-documentation.zh-TW.md +0 -151
- package/docs/guides-generating-documentation.zh.md +0 -151
- package/docs/guides-interactive-chat.ja.md +0 -85
- package/docs/guides-interactive-chat.md +0 -93
- package/docs/guides-interactive-chat.zh-TW.md +0 -85
- package/docs/guides-interactive-chat.zh.md +0 -85
- package/docs/guides-managing-history.ja.md +0 -48
- package/docs/guides-managing-history.md +0 -53
- package/docs/guides-managing-history.zh-TW.md +0 -48
- package/docs/guides-managing-history.zh.md +0 -48
- package/docs/guides-publishing-your-docs.ja.md +0 -78
- package/docs/guides-publishing-your-docs.md +0 -83
- package/docs/guides-publishing-your-docs.zh-TW.md +0 -78
- package/docs/guides-publishing-your-docs.zh.md +0 -78
- package/docs/guides-translating-documentation.ja.md +0 -95
- package/docs/guides-translating-documentation.md +0 -100
- package/docs/guides-translating-documentation.zh-TW.md +0 -95
- package/docs/guides-translating-documentation.zh.md +0 -95
- package/docs/guides-updating-documentation.ja.md +0 -77
- package/docs/guides-updating-documentation.md +0 -79
- package/docs/guides-updating-documentation.zh-TW.md +0 -77
- package/docs/guides-updating-documentation.zh.md +0 -77
- package/docs/guides.ja.md +0 -32
- package/docs/guides.md +0 -32
- package/docs/guides.zh-TW.md +0 -32
- package/docs/guides.zh.md +0 -32
- package/docs/overview.ja.md +0 -61
- package/docs/overview.md +0 -61
- package/docs/overview.zh-TW.md +0 -61
- package/docs/overview.zh.md +0 -61
- package/docs/release-notes.ja.md +0 -255
- package/docs/release-notes.md +0 -288
- package/docs/release-notes.zh-TW.md +0 -255
- package/docs/release-notes.zh.md +0 -255
- package/prompts/common/afs/afs-tools-usage.md +0 -5
- package/prompts/common/afs/use-afs-instruction.md +0 -1
- package/release-please-config.json +0 -14
- package/tests/agents/chat/chat.test.mjs +0 -46
- package/tests/agents/clear/choose-contents.test.mjs +0 -284
- package/tests/agents/clear/clear-auth-tokens.test.mjs +0 -268
- package/tests/agents/clear/clear-document-config.test.mjs +0 -167
- package/tests/agents/clear/clear-document-structure.test.mjs +0 -380
- package/tests/agents/clear/clear-generated-docs.test.mjs +0 -222
- package/tests/agents/evaluate/code-snippet.test.mjs +0 -163
- package/tests/agents/evaluate/fixtures/api-services.md +0 -87
- package/tests/agents/evaluate/fixtures/js-sdk.md +0 -94
- package/tests/agents/evaluate/generate-report.test.mjs +0 -312
- package/tests/agents/generate/check-document-structure.test.mjs +0 -45
- package/tests/agents/generate/check-need-generate-structure.test.mjs +0 -279
- package/tests/agents/generate/document-structure-tools/add-document.test.mjs +0 -449
- package/tests/agents/generate/document-structure-tools/delete-document.test.mjs +0 -410
- package/tests/agents/generate/document-structure-tools/generate-sub-structure.test.mjs +0 -277
- package/tests/agents/generate/document-structure-tools/move-document.test.mjs +0 -476
- package/tests/agents/generate/document-structure-tools/update-document.test.mjs +0 -548
- package/tests/agents/generate/generate-structure.test.mjs +0 -45
- package/tests/agents/generate/user-review-document-structure.test.mjs +0 -319
- package/tests/agents/history/view.test.mjs +0 -97
- package/tests/agents/init/init.test.mjs +0 -1657
- package/tests/agents/prefs/prefs.test.mjs +0 -431
- package/tests/agents/publish/publish-docs.test.mjs +0 -787
- package/tests/agents/translate/choose-language.test.mjs +0 -311
- package/tests/agents/translate/translate-document.test.mjs +0 -51
- package/tests/agents/update/check-document.test.mjs +0 -463
- package/tests/agents/update/check-update-is-single.test.mjs +0 -300
- package/tests/agents/update/document-tools/update-document-content.test.mjs +0 -329
- package/tests/agents/update/generate-document.test.mjs +0 -51
- package/tests/agents/update/save-and-translate-document.test.mjs +0 -369
- package/tests/agents/update/user-review-document.test.mjs +0 -582
- package/tests/agents/utils/action-success.test.mjs +0 -54
- package/tests/agents/utils/check-detail-result.test.mjs +0 -743
- package/tests/agents/utils/check-feedback-refiner.test.mjs +0 -478
- package/tests/agents/utils/choose-docs.test.mjs +0 -406
- package/tests/agents/utils/exit.test.mjs +0 -70
- package/tests/agents/utils/feedback-refiner.test.mjs +0 -51
- package/tests/agents/utils/find-item-by-path.test.mjs +0 -517
- package/tests/agents/utils/find-user-preferences-by-path.test.mjs +0 -382
- package/tests/agents/utils/format-document-structure.test.mjs +0 -364
- package/tests/agents/utils/fs.test.mjs +0 -267
- package/tests/agents/utils/load-sources.test.mjs +0 -1470
- package/tests/agents/utils/save-docs.test.mjs +0 -109
- package/tests/agents/utils/save-output.test.mjs +0 -315
- package/tests/agents/utils/save-single-doc.test.mjs +0 -364
- package/tests/agents/utils/transform-detail-datasources.test.mjs +0 -320
- package/tests/utils/auth-utils.test.mjs +0 -596
- package/tests/utils/blocklet.test.mjs +0 -336
- package/tests/utils/conflict-detector.test.mjs +0 -355
- package/tests/utils/constants.test.mjs +0 -295
- package/tests/utils/d2-utils.test.mjs +0 -437
- package/tests/utils/deploy.test.mjs +0 -399
- package/tests/utils/docs-finder-utils.test.mjs +0 -650
- package/tests/utils/file-utils.test.mjs +0 -521
- package/tests/utils/history-utils.test.mjs +0 -206
- package/tests/utils/kroki-utils.test.mjs +0 -646
- package/tests/utils/linter/fixtures/css/keyword-error.css +0 -1
- package/tests/utils/linter/fixtures/css/missing-semicolon.css +0 -1
- package/tests/utils/linter/fixtures/css/syntax-error.css +0 -1
- package/tests/utils/linter/fixtures/css/undeclare-variable.css +0 -1
- package/tests/utils/linter/fixtures/css/unused-variable.css +0 -2
- package/tests/utils/linter/fixtures/css/valid-code.css +0 -1
- package/tests/utils/linter/fixtures/dockerfile/keyword-error.dockerfile +0 -1
- package/tests/utils/linter/fixtures/dockerfile/missing-semicolon.dockerfile +0 -2
- package/tests/utils/linter/fixtures/dockerfile/syntax-error.dockerfile +0 -2
- package/tests/utils/linter/fixtures/dockerfile/undeclare-variable.dockerfile +0 -1
- package/tests/utils/linter/fixtures/dockerfile/unused-variable.dockerfile +0 -1
- package/tests/utils/linter/fixtures/dockerfile/valid-code.dockerfile +0 -2
- package/tests/utils/linter/fixtures/go/keyword-error.go +0 -5
- package/tests/utils/linter/fixtures/go/missing-semicolon.go +0 -5
- package/tests/utils/linter/fixtures/go/syntax-error.go +0 -6
- package/tests/utils/linter/fixtures/go/undeclare-variable.go +0 -5
- package/tests/utils/linter/fixtures/go/unused-variable.go +0 -5
- package/tests/utils/linter/fixtures/go/valid-code.go +0 -7
- package/tests/utils/linter/fixtures/js/keyword-error.js +0 -3
- package/tests/utils/linter/fixtures/js/missing-semicolon.js +0 -6
- package/tests/utils/linter/fixtures/js/syntax-error.js +0 -4
- package/tests/utils/linter/fixtures/js/undeclare-variable.js +0 -3
- package/tests/utils/linter/fixtures/js/unused-variable.js +0 -7
- package/tests/utils/linter/fixtures/js/valid-code.js +0 -15
- package/tests/utils/linter/fixtures/json/keyword-error.json +0 -1
- package/tests/utils/linter/fixtures/json/missing-semicolon.json +0 -1
- package/tests/utils/linter/fixtures/json/syntax-error.json +0 -1
- package/tests/utils/linter/fixtures/json/undeclare-variable.json +0 -1
- package/tests/utils/linter/fixtures/json/unused-variable.json +0 -1
- package/tests/utils/linter/fixtures/json/valid-code.json +0 -1
- package/tests/utils/linter/fixtures/jsx/keyword-error.jsx +0 -5
- package/tests/utils/linter/fixtures/jsx/missing-semicolon.jsx +0 -5
- package/tests/utils/linter/fixtures/jsx/syntax-error.jsx +0 -5
- package/tests/utils/linter/fixtures/jsx/undeclare-variable.jsx +0 -5
- package/tests/utils/linter/fixtures/jsx/unused-variable.jsx +0 -4
- package/tests/utils/linter/fixtures/jsx/valid-code.jsx +0 -5
- package/tests/utils/linter/fixtures/python/keyword-error.py +0 -3
- package/tests/utils/linter/fixtures/python/missing-semicolon.py +0 -2
- package/tests/utils/linter/fixtures/python/syntax-error.py +0 -3
- package/tests/utils/linter/fixtures/python/undeclare-variable.py +0 -3
- package/tests/utils/linter/fixtures/python/unused-variable.py +0 -6
- package/tests/utils/linter/fixtures/python/valid-code.py +0 -12
- package/tests/utils/linter/fixtures/ruby/keyword-error.rb +0 -2
- package/tests/utils/linter/fixtures/ruby/missing-semicolon.rb +0 -1
- package/tests/utils/linter/fixtures/ruby/syntax-error.rb +0 -2
- package/tests/utils/linter/fixtures/ruby/undeclare-variable.rb +0 -1
- package/tests/utils/linter/fixtures/ruby/unused-variable.rb +0 -2
- package/tests/utils/linter/fixtures/ruby/valid-code.rb +0 -1
- package/tests/utils/linter/fixtures/sass/keyword-error.sass +0 -2
- package/tests/utils/linter/fixtures/sass/missing-semicolon.sass +0 -3
- package/tests/utils/linter/fixtures/sass/syntax-error.sass +0 -3
- package/tests/utils/linter/fixtures/sass/undeclare-variable.sass +0 -2
- package/tests/utils/linter/fixtures/sass/unused-variable.sass +0 -4
- package/tests/utils/linter/fixtures/sass/valid-code.sass +0 -2
- package/tests/utils/linter/fixtures/scss/keyword-error.scss +0 -1
- package/tests/utils/linter/fixtures/scss/missing-semicolon.scss +0 -1
- package/tests/utils/linter/fixtures/scss/syntax-error.scss +0 -1
- package/tests/utils/linter/fixtures/scss/undeclare-variable.scss +0 -1
- package/tests/utils/linter/fixtures/scss/unused-variable.scss +0 -2
- package/tests/utils/linter/fixtures/scss/valid-code.scss +0 -1
- package/tests/utils/linter/fixtures/shell/keyword-error.sh +0 -5
- package/tests/utils/linter/fixtures/shell/missing-semicolon.sh +0 -3
- package/tests/utils/linter/fixtures/shell/syntax-error.sh +0 -4
- package/tests/utils/linter/fixtures/shell/undeclare-variable.sh +0 -3
- package/tests/utils/linter/fixtures/shell/unused-variable.sh +0 -4
- package/tests/utils/linter/fixtures/shell/valid-code.sh +0 -3
- package/tests/utils/linter/fixtures/ts/keyword-error.ts +0 -1
- package/tests/utils/linter/fixtures/ts/missing-semicolon.ts +0 -1
- package/tests/utils/linter/fixtures/ts/syntax-error.ts +0 -1
- package/tests/utils/linter/fixtures/ts/undeclare-variable.ts +0 -1
- package/tests/utils/linter/fixtures/ts/unused-variable.ts +0 -3
- package/tests/utils/linter/fixtures/ts/valid-code.ts +0 -3
- package/tests/utils/linter/fixtures/tsx/keyword-error.tsx +0 -5
- package/tests/utils/linter/fixtures/tsx/missing-semicolon.tsx +0 -5
- package/tests/utils/linter/fixtures/tsx/syntax-error.tsx +0 -5
- package/tests/utils/linter/fixtures/tsx/undeclare-variable.tsx +0 -6
- package/tests/utils/linter/fixtures/tsx/unused-variable.tsx +0 -6
- package/tests/utils/linter/fixtures/tsx/valid-code.tsx +0 -5
- package/tests/utils/linter/fixtures/vue/keyword-error.vue +0 -6
- package/tests/utils/linter/fixtures/vue/missing-semicolon.vue +0 -6
- package/tests/utils/linter/fixtures/vue/syntax-error.vue +0 -6
- package/tests/utils/linter/fixtures/vue/undeclare-variable.vue +0 -6
- package/tests/utils/linter/fixtures/vue/unused-variable.vue +0 -7
- package/tests/utils/linter/fixtures/vue/valid-code.vue +0 -6
- package/tests/utils/linter/fixtures/yaml/keyword-error.yml +0 -1
- package/tests/utils/linter/fixtures/yaml/missing-semicolon.yml +0 -2
- package/tests/utils/linter/fixtures/yaml/syntax-error.yml +0 -1
- package/tests/utils/linter/fixtures/yaml/undeclare-variable.yml +0 -1
- package/tests/utils/linter/fixtures/yaml/unused-variable.yml +0 -2
- package/tests/utils/linter/fixtures/yaml/valid-code.yml +0 -3
- package/tests/utils/linter/index.test.mjs +0 -440
- package/tests/utils/linter/scan-results.mjs +0 -42
- package/tests/utils/load-config.test.mjs +0 -141
- package/tests/utils/markdown/index.test.mjs +0 -478
- package/tests/utils/mermaid-validator.test.mjs +0 -541
- package/tests/utils/mock-chat-model.mjs +0 -12
- package/tests/utils/preferences-utils.test.mjs +0 -465
- package/tests/utils/save-value-to-config.test.mjs +0 -483
- package/tests/utils/utils.test.mjs +0 -941
|
@@ -1,440 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import fsSync from "node:fs";
|
|
3
|
-
import fs from "node:fs/promises";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
|
|
7
|
-
import { CODE_LANGUAGE_MAP_LINTER } from "../../../utils/constants/linter.mjs";
|
|
8
|
-
import { lintCode } from "../../../utils/linter/index.mjs";
|
|
9
|
-
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
-
const __dirname = path.dirname(__filename);
|
|
12
|
-
|
|
13
|
-
// Expected exact counts observed from linter service for our fixtures.
|
|
14
|
-
// Generated by local scan-results script.
|
|
15
|
-
const EXPECTED = {
|
|
16
|
-
js: {
|
|
17
|
-
"undeclare-variable.js": { errors: 1, warnings: 2 },
|
|
18
|
-
"keyword-error.js": { errors: 2, warnings: 1 },
|
|
19
|
-
"missing-semicolon.js": { errors: 0, warnings: 1 },
|
|
20
|
-
"syntax-error.js": { errors: 1, warnings: 1 },
|
|
21
|
-
"unused-variable.js": { errors: 0, warnings: 2 },
|
|
22
|
-
"valid-code.js": { errors: 0, warnings: 0 },
|
|
23
|
-
},
|
|
24
|
-
python: {
|
|
25
|
-
"missing-semicolon.py": { errors: 0, warnings: 1 },
|
|
26
|
-
"unused-variable.py": { errors: 0, warnings: 2 },
|
|
27
|
-
"valid-code.py": { errors: 0, warnings: 2 },
|
|
28
|
-
"keyword-error.py": { errors: 0, warnings: 1 },
|
|
29
|
-
"undeclare-variable.py": { errors: 0, warnings: 1 },
|
|
30
|
-
"syntax-error.py": { errors: 0, warnings: 1 },
|
|
31
|
-
},
|
|
32
|
-
css: {
|
|
33
|
-
"missing-semicolon.css": { errors: 0, warnings: 0 },
|
|
34
|
-
"syntax-error.css": { errors: 0, warnings: 0 },
|
|
35
|
-
"unused-variable.css": { errors: 0, warnings: 0 },
|
|
36
|
-
"keyword-error.css": { errors: 0, warnings: 0 },
|
|
37
|
-
"valid-code.css": { errors: 0, warnings: 0 },
|
|
38
|
-
"undeclare-variable.css": { errors: 0, warnings: 0 },
|
|
39
|
-
},
|
|
40
|
-
ts: {
|
|
41
|
-
"undeclare-variable.ts": { errors: 1, warnings: 0 },
|
|
42
|
-
"valid-code.ts": { errors: 0, warnings: 0 },
|
|
43
|
-
"unused-variable.ts": { errors: 0, warnings: 1 },
|
|
44
|
-
"missing-semicolon.ts": { errors: 0, warnings: 0 },
|
|
45
|
-
"keyword-error.ts": { errors: 2, warnings: 0 },
|
|
46
|
-
"syntax-error.ts": { errors: 2, warnings: 0 },
|
|
47
|
-
},
|
|
48
|
-
jsx: {
|
|
49
|
-
"valid-code.jsx": { errors: 0, warnings: 1 },
|
|
50
|
-
"keyword-error.jsx": { errors: 0, warnings: 0 },
|
|
51
|
-
"syntax-error.jsx": { errors: 0, warnings: 0 },
|
|
52
|
-
"missing-semicolon.jsx": { errors: 0, warnings: 1 },
|
|
53
|
-
"unused-variable.jsx": { errors: 0, warnings: 2 },
|
|
54
|
-
"undeclare-variable.jsx": { errors: 0, warnings: 1 },
|
|
55
|
-
},
|
|
56
|
-
yaml: {
|
|
57
|
-
"unused-variable.yml": { errors: 0, warnings: 1 },
|
|
58
|
-
"valid-code.yml": { errors: 0, warnings: 1 },
|
|
59
|
-
"syntax-error.yml": { errors: 1, warnings: 1 },
|
|
60
|
-
"missing-semicolon.yml": { errors: 0, warnings: 1 },
|
|
61
|
-
"keyword-error.yml": { errors: 0, warnings: 1 },
|
|
62
|
-
"undeclare-variable.yml": { errors: 3, warnings: 0 },
|
|
63
|
-
},
|
|
64
|
-
sass: {
|
|
65
|
-
"syntax-error.sass": { errors: 0, warnings: 0 },
|
|
66
|
-
"unused-variable.sass": { errors: 0, warnings: 0 },
|
|
67
|
-
"keyword-error.sass": { errors: 0, warnings: 0 },
|
|
68
|
-
"undeclare-variable.sass": { errors: 0, warnings: 0 },
|
|
69
|
-
"valid-code.sass": { errors: 0, warnings: 0 },
|
|
70
|
-
"missing-semicolon.sass": { errors: 0, warnings: 0 },
|
|
71
|
-
},
|
|
72
|
-
json: {
|
|
73
|
-
"missing-semicolon.json": { errors: 0, warnings: 0 },
|
|
74
|
-
"unused-variable.json": { errors: 0, warnings: 0 },
|
|
75
|
-
"keyword-error.json": { errors: 1, warnings: 0 },
|
|
76
|
-
"undeclare-variable.json": { errors: 2, warnings: 0 },
|
|
77
|
-
"syntax-error.json": { errors: 1, warnings: 0 },
|
|
78
|
-
"valid-code.json": { errors: 0, warnings: 0 },
|
|
79
|
-
},
|
|
80
|
-
tsx: {
|
|
81
|
-
"unused-variable.tsx": { errors: 0, warnings: 2 },
|
|
82
|
-
"undeclare-variable.tsx": { errors: 0, warnings: 2 },
|
|
83
|
-
"valid-code.tsx": { errors: 0, warnings: 1 },
|
|
84
|
-
"missing-semicolon.tsx": { errors: 0, warnings: 1 },
|
|
85
|
-
"keyword-error.tsx": { errors: 0, warnings: 0 },
|
|
86
|
-
"syntax-error.tsx": { errors: 0, warnings: 0 },
|
|
87
|
-
},
|
|
88
|
-
ruby: {
|
|
89
|
-
"valid-code.rb": { errors: 0, warnings: 0 },
|
|
90
|
-
"keyword-error.rb": { errors: 0, warnings: 0 },
|
|
91
|
-
"syntax-error.rb": { errors: 0, warnings: 0 },
|
|
92
|
-
"undeclare-variable.rb": { errors: 0, warnings: 0 },
|
|
93
|
-
"missing-semicolon.rb": { errors: 0, warnings: 0 },
|
|
94
|
-
"unused-variable.rb": { errors: 0, warnings: 0 },
|
|
95
|
-
},
|
|
96
|
-
dockerfile: {
|
|
97
|
-
"syntax-error.dockerfile": { errors: 1, warnings: 1 },
|
|
98
|
-
"unused-variable.dockerfile": { errors: 0, warnings: 0 },
|
|
99
|
-
"keyword-error.dockerfile": { errors: 1, warnings: 0 },
|
|
100
|
-
"valid-code.dockerfile": { errors: 0, warnings: 0 },
|
|
101
|
-
"undeclare-variable.dockerfile": { errors: 0, warnings: 0 },
|
|
102
|
-
"missing-semicolon.dockerfile": { errors: 0, warnings: 1 },
|
|
103
|
-
},
|
|
104
|
-
scss: {
|
|
105
|
-
"keyword-error.scss": { errors: 0, warnings: 0 },
|
|
106
|
-
"syntax-error.scss": { errors: 0, warnings: 0 },
|
|
107
|
-
"undeclare-variable.scss": { errors: 0, warnings: 0 },
|
|
108
|
-
"valid-code.scss": { errors: 0, warnings: 0 },
|
|
109
|
-
"missing-semicolon.scss": { errors: 0, warnings: 0 },
|
|
110
|
-
"unused-variable.scss": { errors: 0, warnings: 0 },
|
|
111
|
-
},
|
|
112
|
-
vue: {
|
|
113
|
-
"unused-variable.vue": { errors: 0, warnings: 0 },
|
|
114
|
-
"missing-semicolon.vue": { errors: 0, warnings: 0 },
|
|
115
|
-
"valid-code.vue": { errors: 0, warnings: 0 },
|
|
116
|
-
"keyword-error.vue": { errors: 0, warnings: 0 },
|
|
117
|
-
"syntax-error.vue": { errors: 0, warnings: 0 },
|
|
118
|
-
"undeclare-variable.vue": { errors: 0, warnings: 0 },
|
|
119
|
-
},
|
|
120
|
-
go: {
|
|
121
|
-
"valid-code.go": { errors: 0, warnings: 0 },
|
|
122
|
-
"unused-variable.go": { errors: 0, warnings: 0 },
|
|
123
|
-
"undeclare-variable.go": { errors: 0, warnings: 0 },
|
|
124
|
-
"keyword-error.go": { errors: 0, warnings: 0 },
|
|
125
|
-
"syntax-error.go": { errors: 0, warnings: 0 },
|
|
126
|
-
"missing-semicolon.go": { errors: 0, warnings: 0 },
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
// Error handling tests for uncovered lines
|
|
131
|
-
describe("lintCode error handling", () => {
|
|
132
|
-
test("should throw error when code parameter is missing", async () => {
|
|
133
|
-
await expect(lintCode({ code: null })).rejects.toThrow("Code parameter is required");
|
|
134
|
-
await expect(lintCode({ code: undefined })).rejects.toThrow("Code parameter is required");
|
|
135
|
-
await expect(lintCode({ code: "" })).rejects.toThrow("Code parameter is required");
|
|
136
|
-
await expect(lintCode({})).rejects.toThrow("Code parameter is required");
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
test("should throw error for HTTP error response", async () => {
|
|
140
|
-
const originalFetch = globalThis.fetch;
|
|
141
|
-
|
|
142
|
-
// Mock fetch to return HTTP error
|
|
143
|
-
globalThis.fetch = async () => ({
|
|
144
|
-
ok: false,
|
|
145
|
-
status: 500,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
await expect(lintCode({ code: "console.log('test')" })).rejects.toThrow(
|
|
150
|
-
"HTTP error! status: 500",
|
|
151
|
-
);
|
|
152
|
-
} finally {
|
|
153
|
-
globalThis.fetch = originalFetch;
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test("should throw error for invalid response data", async () => {
|
|
158
|
-
const originalFetch = globalThis.fetch;
|
|
159
|
-
|
|
160
|
-
// Mock fetch to return response with null data
|
|
161
|
-
globalThis.fetch = async () => ({
|
|
162
|
-
ok: true,
|
|
163
|
-
json: async () => null,
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
try {
|
|
167
|
-
await expect(lintCode({ code: "console.log('test')" })).rejects.toThrow(
|
|
168
|
-
"Invalid response data",
|
|
169
|
-
);
|
|
170
|
-
} finally {
|
|
171
|
-
globalThis.fetch = originalFetch;
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
test("should handle fetch timeout and other network errors", async () => {
|
|
176
|
-
const originalFetch = globalThis.fetch;
|
|
177
|
-
|
|
178
|
-
// Mock fetch to throw network error
|
|
179
|
-
globalThis.fetch = async () => {
|
|
180
|
-
throw new Error("Network error");
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
try {
|
|
184
|
-
await expect(lintCode({ code: "console.log('test')" })).rejects.toThrow(
|
|
185
|
-
"Linting failed: Network error",
|
|
186
|
-
);
|
|
187
|
-
} finally {
|
|
188
|
-
globalThis.fetch = originalFetch;
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
test("should handle JSON parsing errors", async () => {
|
|
193
|
-
const originalFetch = globalThis.fetch;
|
|
194
|
-
|
|
195
|
-
// Mock fetch to return invalid JSON
|
|
196
|
-
globalThis.fetch = async () => ({
|
|
197
|
-
ok: true,
|
|
198
|
-
json: async () => {
|
|
199
|
-
throw new Error("Invalid JSON");
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
try {
|
|
204
|
-
await expect(lintCode({ code: "console.log('test')" })).rejects.toThrow(
|
|
205
|
-
"Linting failed: Invalid JSON",
|
|
206
|
-
);
|
|
207
|
-
} finally {
|
|
208
|
-
globalThis.fetch = originalFetch;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
test("should handle AbortController abort signal", async () => {
|
|
213
|
-
const originalFetch = globalThis.fetch;
|
|
214
|
-
|
|
215
|
-
// Mock fetch to simulate abort error
|
|
216
|
-
globalThis.fetch = async (_url, _options) => {
|
|
217
|
-
// Simulate immediate abort
|
|
218
|
-
const error = new Error("The operation was aborted");
|
|
219
|
-
error.name = "AbortError";
|
|
220
|
-
throw error;
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
try {
|
|
224
|
-
await expect(lintCode({ code: "console.log('test')" })).rejects.toThrow(
|
|
225
|
-
"Linting failed: The operation was aborted",
|
|
226
|
-
);
|
|
227
|
-
} finally {
|
|
228
|
-
globalThis.fetch = originalFetch;
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
describe("lintCode js", () => {
|
|
234
|
-
const jsLinter = CODE_LANGUAGE_MAP_LINTER.js;
|
|
235
|
-
|
|
236
|
-
test("should lint js undeclare variable error", async () => {
|
|
237
|
-
const code = await fs.readFile(
|
|
238
|
-
path.join(__dirname, "fixtures/js/undeclare-variable.js"),
|
|
239
|
-
"utf-8",
|
|
240
|
-
);
|
|
241
|
-
const result = await lintCode({ code, linter: jsLinter });
|
|
242
|
-
if (!result || !Array.isArray(result.issues)) return;
|
|
243
|
-
const expectMap = EXPECTED?.js?.["undeclare-variable.js"];
|
|
244
|
-
if (!expectMap) return;
|
|
245
|
-
const errors = result.issues.filter((x) => x.severity === "error").length;
|
|
246
|
-
const warnings = result.issues.filter((x) => x.severity === "warning").length;
|
|
247
|
-
expect(errors).toEqual(expectMap.errors);
|
|
248
|
-
expect(warnings).toEqual(expectMap.warnings);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
test("should lint js keyword error", async () => {
|
|
252
|
-
const code = await fs.readFile(path.join(__dirname, "fixtures/js/keyword-error.js"), "utf-8");
|
|
253
|
-
const result = await lintCode({ code, linter: "biome-lint" });
|
|
254
|
-
if (!result || !Array.isArray(result.issues)) return;
|
|
255
|
-
const expectMap = EXPECTED?.js?.["keyword-error.js"];
|
|
256
|
-
if (!expectMap) return;
|
|
257
|
-
const errors = result.issues.filter((x) => x.severity === "error").length;
|
|
258
|
-
const warnings = result.issues.filter((x) => x.severity === "warning").length;
|
|
259
|
-
expect(errors).toEqual(expectMap.errors);
|
|
260
|
-
expect(warnings).toEqual(expectMap.warnings);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
test("should lint js missing semicolon error", async () => {
|
|
264
|
-
const code = await fs.readFile(
|
|
265
|
-
path.join(__dirname, "fixtures/js/missing-semicolon.js"),
|
|
266
|
-
"utf-8",
|
|
267
|
-
);
|
|
268
|
-
const result = await lintCode({ code, linter: jsLinter });
|
|
269
|
-
if (!result || !Array.isArray(result.issues)) return;
|
|
270
|
-
const expectMap = EXPECTED?.js?.["missing-semicolon.js"];
|
|
271
|
-
if (!expectMap) return;
|
|
272
|
-
const errors = result.issues.filter((x) => x.severity === "error").length;
|
|
273
|
-
const warnings = result.issues.filter((x) => x.severity === "warning").length;
|
|
274
|
-
expect(errors).toEqual(expectMap.errors);
|
|
275
|
-
expect(warnings).toEqual(expectMap.warnings);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
test("should lint js syntax error in syntax-error.js", async () => {
|
|
279
|
-
const code = await fs.readFile(path.join(__dirname, "fixtures/js/syntax-error.js"), "utf-8");
|
|
280
|
-
const result = await lintCode({ code, linter: jsLinter });
|
|
281
|
-
if (!result || !Array.isArray(result.issues)) return;
|
|
282
|
-
const expectMap = EXPECTED?.js?.["syntax-error.js"];
|
|
283
|
-
if (!expectMap) return;
|
|
284
|
-
const errors = result.issues.filter((x) => x.severity === "error").length;
|
|
285
|
-
const warnings = result.issues.filter((x) => x.severity === "warning").length;
|
|
286
|
-
expect(errors).toEqual(expectMap.errors);
|
|
287
|
-
expect(warnings).toEqual(expectMap.warnings);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
test("should lint js code with unused variables", async () => {
|
|
291
|
-
const code = await fs.readFile(path.join(__dirname, "fixtures/js/unused-variable.js"), "utf-8");
|
|
292
|
-
const result = await lintCode({ code, linter: jsLinter });
|
|
293
|
-
if (!result || !Array.isArray(result.issues)) return;
|
|
294
|
-
const expectMap = EXPECTED?.js?.["unused-variable.js"];
|
|
295
|
-
if (!expectMap) return;
|
|
296
|
-
const errors = result.issues.filter((x) => x.severity === "error").length;
|
|
297
|
-
const warnings = result.issues.filter((x) => x.severity === "warning").length;
|
|
298
|
-
expect(errors).toEqual(expectMap.errors);
|
|
299
|
-
expect(warnings).toEqual(expectMap.warnings);
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
test("should lint valid js code with no errors", async () => {
|
|
303
|
-
const code = await fs.readFile(path.join(__dirname, "fixtures/js/valid-code.js"), "utf-8");
|
|
304
|
-
const result = await lintCode({ code, linter: jsLinter });
|
|
305
|
-
if (!result || !Array.isArray(result.issues)) return;
|
|
306
|
-
const expectMap = EXPECTED?.js?.["valid-code.js"];
|
|
307
|
-
if (!expectMap) return;
|
|
308
|
-
const errors = result.issues.filter((x) => x.severity === "error").length;
|
|
309
|
-
const warnings = result.issues.filter((x) => x.severity === "warning").length;
|
|
310
|
-
expect(errors).toEqual(expectMap.errors);
|
|
311
|
-
expect(warnings).toEqual(expectMap.warnings);
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
// Helper to create a suite for a language
|
|
316
|
-
function createLanguageSuite({ langKey, fixtureDir, suffix }) {
|
|
317
|
-
const linter = CODE_LANGUAGE_MAP_LINTER[langKey];
|
|
318
|
-
// Skip if fixture files for this language do not exist to avoid ENOENT errors
|
|
319
|
-
const validPath = path.join(__dirname, `fixtures/${fixtureDir}/valid-code${suffix || ""}`);
|
|
320
|
-
if (!fsSync.existsSync(validPath)) return;
|
|
321
|
-
|
|
322
|
-
describe(`lintCode ${langKey}`, () => {
|
|
323
|
-
test(`should lint ${langKey} undeclare variable error`, async () => {
|
|
324
|
-
const code = await fs.readFile(
|
|
325
|
-
path.join(__dirname, `fixtures/${fixtureDir}/undeclare-variable${suffix || ""}`),
|
|
326
|
-
"utf-8",
|
|
327
|
-
);
|
|
328
|
-
const result = await lintCode({ code, linter, suffix });
|
|
329
|
-
if (!result || !Array.isArray(result.issues)) return;
|
|
330
|
-
const key = `undeclare-variable${suffix || ""}`.replace(/^[.]/, "");
|
|
331
|
-
const expectMap = EXPECTED?.[fixtureDir]?.[key];
|
|
332
|
-
if (!expectMap) return;
|
|
333
|
-
const errors = result.issues.filter((x) => x.severity === "error").length;
|
|
334
|
-
const warnings = result.issues.filter((x) => x.severity === "warning").length;
|
|
335
|
-
expect(errors).toEqual(expectMap.errors);
|
|
336
|
-
expect(warnings).toEqual(expectMap.warnings);
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
test(`should lint ${langKey} keyword error`, async () => {
|
|
340
|
-
const code = await fs.readFile(
|
|
341
|
-
path.join(__dirname, `fixtures/${fixtureDir}/keyword-error${suffix || ""}`),
|
|
342
|
-
"utf-8",
|
|
343
|
-
);
|
|
344
|
-
const result = await lintCode({ code, linter, suffix });
|
|
345
|
-
if (!result || !Array.isArray(result.issues)) return;
|
|
346
|
-
const expectMap = EXPECTED?.[fixtureDir]?.[`keyword-error${suffix || ""}`];
|
|
347
|
-
if (!expectMap) return;
|
|
348
|
-
const errors = result.issues.filter((x) => x.severity === "error").length;
|
|
349
|
-
const warnings = result.issues.filter((x) => x.severity === "warning").length;
|
|
350
|
-
expect(errors).toEqual(expectMap.errors);
|
|
351
|
-
expect(warnings).toEqual(expectMap.warnings);
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
test(`should lint ${langKey} missing semicolon/style issue`, async () => {
|
|
355
|
-
const file = `missing-semicolon${suffix || ""}`;
|
|
356
|
-
const code = await fs.readFile(
|
|
357
|
-
path.join(__dirname, `fixtures/${fixtureDir}/${file}`),
|
|
358
|
-
"utf-8",
|
|
359
|
-
);
|
|
360
|
-
const result = await lintCode({ code, linter, suffix });
|
|
361
|
-
if (!result || !Array.isArray(result.issues)) return;
|
|
362
|
-
const expectMap = EXPECTED?.[fixtureDir]?.[file];
|
|
363
|
-
if (!expectMap) return;
|
|
364
|
-
const errors = result.issues.filter((x) => x.severity === "error").length;
|
|
365
|
-
const warnings = result.issues.filter((x) => x.severity === "warning").length;
|
|
366
|
-
expect(errors).toEqual(expectMap.errors);
|
|
367
|
-
expect(warnings).toEqual(expectMap.warnings);
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
test(`should lint ${langKey} syntax error`, async () => {
|
|
371
|
-
const code = await fs.readFile(
|
|
372
|
-
path.join(__dirname, `fixtures/${fixtureDir}/syntax-error${suffix || ""}`),
|
|
373
|
-
"utf-8",
|
|
374
|
-
);
|
|
375
|
-
const result = await lintCode({ code, linter, suffix });
|
|
376
|
-
if (!result || !Array.isArray(result.issues)) return;
|
|
377
|
-
const expectMap = EXPECTED?.[fixtureDir]?.[`syntax-error${suffix || ""}`];
|
|
378
|
-
if (!expectMap) return;
|
|
379
|
-
const errors = result.issues.filter((x) => x.severity === "error").length;
|
|
380
|
-
const warnings = result.issues.filter((x) => x.severity === "warning").length;
|
|
381
|
-
expect(errors).toEqual(expectMap.errors);
|
|
382
|
-
expect(warnings).toEqual(expectMap.warnings);
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
test(`should lint ${langKey} code with unused variables`, async () => {
|
|
386
|
-
const code = await fs.readFile(
|
|
387
|
-
path.join(__dirname, `fixtures/${fixtureDir}/unused-variable${suffix || ""}`),
|
|
388
|
-
"utf-8",
|
|
389
|
-
);
|
|
390
|
-
const result = await lintCode({ code, linter, suffix });
|
|
391
|
-
if (!result || !Array.isArray(result.issues)) return;
|
|
392
|
-
const expectMap = EXPECTED?.[fixtureDir]?.[`unused-variable${suffix || ""}`];
|
|
393
|
-
if (!expectMap) return;
|
|
394
|
-
const errors = result.issues.filter((x) => x.severity === "error").length;
|
|
395
|
-
const warnings = result.issues.filter((x) => x.severity === "warning").length;
|
|
396
|
-
expect(errors).toEqual(expectMap.errors);
|
|
397
|
-
expect(warnings).toEqual(expectMap.warnings);
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
test(`should lint valid ${langKey} code with no errors`, async () => {
|
|
401
|
-
const code = await fs.readFile(
|
|
402
|
-
path.join(__dirname, `fixtures/${fixtureDir}/valid-code${suffix || ""}`),
|
|
403
|
-
"utf-8",
|
|
404
|
-
);
|
|
405
|
-
const result = await lintCode({ code, linter, suffix });
|
|
406
|
-
if (!result || !Array.isArray(result.issues)) return;
|
|
407
|
-
const expectMap = EXPECTED?.[fixtureDir]?.[`valid-code${suffix || ""}`];
|
|
408
|
-
if (!expectMap) return;
|
|
409
|
-
const errors = result.issues.filter((x) => x.severity === "error").length;
|
|
410
|
-
const warnings = result.issues.filter((x) => x.severity === "warning").length;
|
|
411
|
-
expect(errors).toEqual(expectMap.errors);
|
|
412
|
-
expect(warnings).toEqual(expectMap.warnings);
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// Create suites for other languages defined in CODE_LANGUAGE_MAP_LINTER
|
|
418
|
-
// FIXME: @zhanghan lint error is wrong, skip it now
|
|
419
|
-
// createLanguageSuite({ langKey: "python", fixtureDir: "python", suffix: ".py" });
|
|
420
|
-
createLanguageSuite({ langKey: "shell", fixtureDir: "shell", suffix: ".sh" });
|
|
421
|
-
// FIXME: @zhanghan lint error is wrong, skip it now
|
|
422
|
-
// createLanguageSuite({ langKey: "go", fixtureDir: "go", suffix: ".go" });
|
|
423
|
-
// FIXME: @zhanghan lint error is wrong, skip it now
|
|
424
|
-
// createLanguageSuite({ langKey: "ruby", fixtureDir: "ruby", suffix: ".rb" });
|
|
425
|
-
createLanguageSuite({ langKey: "dockerfile", fixtureDir: "dockerfile", suffix: ".dockerfile" });
|
|
426
|
-
createLanguageSuite({ langKey: "yaml", fixtureDir: "yaml", suffix: ".yml" });
|
|
427
|
-
// FIXME: @zhanghan lint error failed, skip it now
|
|
428
|
-
// createLanguageSuite({ langKey: "css", fixtureDir: "css", suffix: ".css" });
|
|
429
|
-
// FIXME: @zhanghan lint error failed (INSERT INTO lint_results), skip it now
|
|
430
|
-
// createLanguageSuite({ langKey: "jsx", fixtureDir: "jsx", suffix: ".jsx" });
|
|
431
|
-
// FIXME: @zhanghan lint error failed (INSERT INTO lint_results), skip it now
|
|
432
|
-
// createLanguageSuite({ langKey: "tsx", fixtureDir: "tsx", suffix: ".tsx" });
|
|
433
|
-
createLanguageSuite({ langKey: "ts", fixtureDir: "ts", suffix: ".ts" });
|
|
434
|
-
// FIXME: @zhanghan lint error failed (ESLint couldn't find a configuration file), skip it now
|
|
435
|
-
// createLanguageSuite({ langKey: "vue", fixtureDir: "vue", suffix: ".vue" });
|
|
436
|
-
// FIXME: @zhanghan lint error failed (Error: No configuration provided), skip it now
|
|
437
|
-
// createLanguageSuite({ langKey: "sass", fixtureDir: "sass", suffix: ".sass" });
|
|
438
|
-
// FIXME: @zhanghan lint error failed (Error: No configuration provided), skip it now
|
|
439
|
-
// createLanguageSuite({ langKey: "scss", fixtureDir: "scss", suffix: ".scss" });
|
|
440
|
-
createLanguageSuite({ langKey: "json", fixtureDir: "json", suffix: ".json" });
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
const fixturesRoot = path.join(process.cwd(), "tests", "utils", "linter", "fixtures");
|
|
5
|
-
const { lintCode } = await import(
|
|
6
|
-
`file://${path.join(process.cwd(), "utils", "linter", "index.mjs")}`
|
|
7
|
-
);
|
|
8
|
-
const { CODE_LANGUAGE_MAP_LINTER } = await import(
|
|
9
|
-
`file://${path.join(process.cwd(), "utils", "constants", "linter.mjs")}`
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
async function scan() {
|
|
13
|
-
const langs = await fs.readdir(fixturesRoot);
|
|
14
|
-
const results = {};
|
|
15
|
-
for (const lang of langs) {
|
|
16
|
-
const dir = path.join(fixturesRoot, lang);
|
|
17
|
-
const stat = await fs.stat(dir);
|
|
18
|
-
if (!stat.isDirectory()) continue;
|
|
19
|
-
const files = await fs.readdir(dir);
|
|
20
|
-
if (files.length === 0) continue;
|
|
21
|
-
const linter =
|
|
22
|
-
CODE_LANGUAGE_MAP_LINTER[lang] || CODE_LANGUAGE_MAP_LINTER[lang.replace(".", "")] || null;
|
|
23
|
-
results[lang] = [];
|
|
24
|
-
for (const file of files) {
|
|
25
|
-
const filePath = path.join(dir, file);
|
|
26
|
-
const code = await fs.readFile(filePath, "utf-8");
|
|
27
|
-
const suffix = path.extname(file);
|
|
28
|
-
try {
|
|
29
|
-
const res = await lintCode({ code, linter: linter || undefined, suffix });
|
|
30
|
-
const issues = Array.isArray(res?.issues) ? res.issues : [];
|
|
31
|
-
const errors = issues.filter((i) => i.severity === "error").length;
|
|
32
|
-
const warnings = issues.filter((i) => i.severity === "warning").length;
|
|
33
|
-
results[lang].push({ file, success: res?.success, total: issues.length, errors, warnings });
|
|
34
|
-
} catch (err) {
|
|
35
|
-
results[lang].push({ file, error: String(err) });
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
console.log(JSON.stringify(results, null, 2));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
await scan();
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
-
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import loadConfig from "../../utils/load-config.mjs";
|
|
6
|
-
|
|
7
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
|
|
9
|
-
describe("load-config", () => {
|
|
10
|
-
let testDir;
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
// Create a temporary test directory
|
|
14
|
-
testDir = join(__dirname, "test-load-config");
|
|
15
|
-
await mkdir(testDir, { recursive: true });
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterEach(async () => {
|
|
19
|
-
// Clean up test directory
|
|
20
|
-
try {
|
|
21
|
-
await rm(testDir, { recursive: true, force: true });
|
|
22
|
-
} catch {
|
|
23
|
-
// Ignore cleanup errors since they don't affect test results
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test("should load valid YAML config file", async () => {
|
|
28
|
-
const configPath = join(testDir, "config.yaml");
|
|
29
|
-
const configContent = `
|
|
30
|
-
projectName: "Test Project"
|
|
31
|
-
locale: "en"
|
|
32
|
-
docsDir: "./docs"
|
|
33
|
-
sourcesPath:
|
|
34
|
-
- "./src"
|
|
35
|
-
- "./lib"
|
|
36
|
-
`;
|
|
37
|
-
await writeFile(configPath, configContent);
|
|
38
|
-
|
|
39
|
-
const result = await loadConfig({ config: configPath });
|
|
40
|
-
|
|
41
|
-
expect(result).toBeDefined();
|
|
42
|
-
expect(result.projectName).toBe("Test Project");
|
|
43
|
-
expect(result.locale).toBe("en");
|
|
44
|
-
expect(result.docsDir).toBe("./docs");
|
|
45
|
-
expect(result.sourcesPath).toEqual(["./src", "./lib"]);
|
|
46
|
-
expect(result.lastGitHead).toBe("");
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test("should handle appUrl parameter", async () => {
|
|
50
|
-
const configPath = join(testDir, "config.yaml");
|
|
51
|
-
const configContent = `
|
|
52
|
-
projectName: "Test Project"
|
|
53
|
-
locale: "en"
|
|
54
|
-
`;
|
|
55
|
-
await writeFile(configPath, configContent);
|
|
56
|
-
|
|
57
|
-
const result = await loadConfig({
|
|
58
|
-
config: configPath,
|
|
59
|
-
appUrl: "example.com",
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
expect(result.appUrl).toBe("https://example.com");
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test("should preserve appUrl with existing protocol", async () => {
|
|
66
|
-
const configPath = join(testDir, "config.yaml");
|
|
67
|
-
const configContent = `
|
|
68
|
-
projectName: "Test Project"
|
|
69
|
-
locale: "en"
|
|
70
|
-
`;
|
|
71
|
-
await writeFile(configPath, configContent);
|
|
72
|
-
|
|
73
|
-
const result = await loadConfig({
|
|
74
|
-
config: configPath,
|
|
75
|
-
appUrl: "http://localhost:3000",
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
expect(result.appUrl).toBe("http://localhost:3000");
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("should handle absolute config path", async () => {
|
|
82
|
-
const configPath = join(testDir, "absolute-config.yaml");
|
|
83
|
-
const configContent = `
|
|
84
|
-
projectName: "Absolute Path Test"
|
|
85
|
-
locale: "zh"
|
|
86
|
-
`;
|
|
87
|
-
await writeFile(configPath, configContent);
|
|
88
|
-
|
|
89
|
-
const result = await loadConfig({ config: configPath });
|
|
90
|
-
|
|
91
|
-
expect(result.projectName).toBe("Absolute Path Test");
|
|
92
|
-
expect(result.locale).toBe("zh");
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test("should throw error for non-existent config file", async () => {
|
|
96
|
-
const nonExistentPath = join(testDir, "non-existent.yaml");
|
|
97
|
-
|
|
98
|
-
await expect(loadConfig({ config: nonExistentPath })).rejects.toThrow(
|
|
99
|
-
`Config file not found: ${nonExistentPath}`,
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test("should throw error for invalid YAML syntax", async () => {
|
|
104
|
-
const configPath = join(testDir, "invalid.yaml");
|
|
105
|
-
const invalidContent = `
|
|
106
|
-
projectName: "Test
|
|
107
|
-
locale: en
|
|
108
|
-
invalid: yaml: syntax
|
|
109
|
-
`;
|
|
110
|
-
await writeFile(configPath, invalidContent);
|
|
111
|
-
|
|
112
|
-
await expect(loadConfig({ config: configPath })).rejects.toThrow(
|
|
113
|
-
"Failed to parse config file:",
|
|
114
|
-
);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test("should throw error for empty config file", async () => {
|
|
118
|
-
const configPath = join(testDir, "empty.yaml");
|
|
119
|
-
await writeFile(configPath, "");
|
|
120
|
-
|
|
121
|
-
// Empty YAML files result in null, which causes an error in the processing
|
|
122
|
-
await expect(loadConfig({ config: configPath })).rejects.toThrow(
|
|
123
|
-
"Failed to parse config file:",
|
|
124
|
-
);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test("should handle config with lastGitHead", async () => {
|
|
128
|
-
const configPath = join(testDir, "config-with-git.yaml");
|
|
129
|
-
const configContent = `
|
|
130
|
-
projectName: "Git Project"
|
|
131
|
-
lastGitHead: "abc123def456"
|
|
132
|
-
locale: "en"
|
|
133
|
-
`;
|
|
134
|
-
await writeFile(configPath, configContent);
|
|
135
|
-
|
|
136
|
-
const result = await loadConfig({ config: configPath });
|
|
137
|
-
|
|
138
|
-
expect(result.lastGitHead).toBe("abc123def456");
|
|
139
|
-
expect(result.projectName).toBe("Git Project");
|
|
140
|
-
});
|
|
141
|
-
});
|