@hamsterbase/evidra 0.3.3 → 0.5.0
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/dist/sdk/conformance-rules.js +167 -25
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sdk/rules.d.ts +9 -2
- package/dist/sdk/types--o0ku6ya.d.ts +21 -0
- package/dist/service/cli.js +198 -71
- package/dist/web/assets/InterVariable-DiVDrmQJ.woff2 +0 -0
- package/dist/web/assets/{cssMode-Dhqi33oU.js → cssMode-DHNTOGta.js} +1 -1
- package/dist/web/assets/{editor.api-BdoUH79A.js → editor.api-DrACi4Ft.js} +1 -1
- package/dist/web/assets/{freemarker2-Di1XsZv-.js → freemarker2-BZwhuUrf.js} +1 -1
- package/dist/web/assets/{handlebars-BmMiVsf3.js → handlebars-dcBiTm2k.js} +1 -1
- package/dist/web/assets/{html-BWw9s24y.js → html-4uGnY1Hx.js} +1 -1
- package/dist/web/assets/{htmlMode-BLrNvZ52.js → htmlMode-BAZ2gLM_.js} +1 -1
- package/dist/web/assets/index-Cp1GHnZQ.js +2 -0
- package/dist/web/assets/{javascript-Bw0zDh-8.js → javascript-D-sZtKfO.js} +1 -1
- package/dist/web/assets/{jsonMode-Bg-zBRn4.js → jsonMode-BLFT3pYI.js} +1 -1
- package/dist/web/assets/{liquid-QbiTMLnd.js → liquid-HD6sTxLL.js} +1 -1
- package/dist/web/assets/{lspLanguageFeatures-CxAtCJVb.js → lspLanguageFeatures-CfU_VfTV.js} +1 -1
- package/dist/web/assets/main-BJxJ6lK3.js +18 -0
- package/dist/web/assets/main-BTS_f34X.js +26 -0
- package/dist/web/assets/main-Bpk1-JEL.css +1 -0
- package/dist/web/assets/main-CAvFOBUt.css +2 -0
- package/dist/web/assets/{mdx-CEzuFeFS.js → mdx-BfzD71x2.js} +1 -1
- package/dist/web/assets/{monaco-BUdi4Xi9.js → monaco-CoScar16.js} +4 -4
- package/dist/web/assets/{python-_M325yHp.js → python-Dn3yZn9U.js} +1 -1
- package/dist/web/assets/{razor-B6FUqtCe.js → razor-Bbpo3gmC.js} +1 -1
- package/dist/web/assets/{tsMode-DTgoRzrO.js → tsMode-CWTXIUQy.js} +1 -1
- package/dist/web/assets/{typescript-Bzm0l5-o.js → typescript-BdGEKF1f.js} +1 -1
- package/dist/web/assets/useDisplayPreference-cWXttaFP.js +89 -0
- package/dist/web/assets/{workers-Cga5X6ar.js → workers-yymMcYwK.js} +1 -1
- package/dist/web/assets/{xml-BCwAkxsD.js → xml-dxLH6b19.js} +1 -1
- package/dist/web/assets/{yaml-ClBi6NOp.js → yaml-DizpY2pm.js} +1 -1
- package/dist/web/index.html +1 -2
- package/package.json +7 -2
- package/packages/conformance/rules/baseline-max-diff-pixels/RULE.md +21 -0
- package/packages/conformance/rules/index.md +1 -1
- package/skills/evidra/SKILL.md +7 -1
- package/dist/sdk/types-B6cBsknY.d.ts +0 -12
- package/dist/types/modules/core/contracts/comparison.d.ts +0 -41
- package/dist/types/modules/core/contracts/config.d.ts +0 -19
- package/dist/types/modules/core/contracts/context.d.ts +0 -6
- package/dist/types/modules/core/contracts/functions/addCase.d.ts +0 -128
- package/dist/types/modules/core/contracts/functions/addTask.d.ts +0 -14
- package/dist/types/modules/core/contracts/functions/approve.d.ts +0 -8
- package/dist/types/modules/core/contracts/functions/baselineChanges.d.ts +0 -14
- package/dist/types/modules/core/contracts/functions/compare.d.ts +0 -14
- package/dist/types/modules/core/contracts/functions/compareTask.d.ts +0 -6
- package/dist/types/modules/core/contracts/functions/compareTasks.d.ts +0 -18
- package/dist/types/modules/core/contracts/functions/deleteBaselineFile.d.ts +0 -8
- package/dist/types/modules/core/contracts/functions/finishTask.d.ts +0 -8
- package/dist/types/modules/core/contracts/functions/getBaseline.d.ts +0 -10
- package/dist/types/modules/core/contracts/functions/getBaselineChanges.d.ts +0 -6
- package/dist/types/modules/core/contracts/functions/getGitChanges.d.ts +0 -6
- package/dist/types/modules/core/contracts/functions/getGitDiff.d.ts +0 -8
- package/dist/types/modules/core/contracts/functions/getTaskCase.d.ts +0 -23
- package/dist/types/modules/core/contracts/functions/getTaskTree.d.ts +0 -21
- package/dist/types/modules/core/contracts/functions/gitChanges.d.ts +0 -25
- package/dist/types/modules/core/contracts/functions/index.d.ts +0 -18
- package/dist/types/modules/core/contracts/functions/listBaselines.d.ts +0 -5
- package/dist/types/modules/core/contracts/functions/listRuns.d.ts +0 -7
- package/dist/types/modules/core/contracts/functions/listTaskSummaries.d.ts +0 -15
- package/dist/types/modules/core/contracts/functions/listTasks.d.ts +0 -15
- package/dist/types/modules/core/contracts/functions/loadConfig.d.ts +0 -5
- package/dist/types/modules/core/contracts/functions/readProjectInfo.d.ts +0 -5
- package/dist/types/modules/core/contracts/functions/readTaskReport.d.ts +0 -6
- package/dist/types/modules/core/contracts/functions/resolveConfig.d.ts +0 -6
- package/dist/types/modules/core/contracts/functions/reviewBaselineChanges.d.ts +0 -9
- package/dist/types/modules/core/contracts/functions/reviewCodeChanges.d.ts +0 -9
- package/dist/types/modules/core/contracts/functions/taskRecords.d.ts +0 -6
- package/dist/types/modules/core/contracts/functions/updateBaseline.d.ts +0 -20
- package/dist/types/modules/core/contracts/git.d.ts +0 -14
- package/dist/types/modules/core/contracts/imageDiffPool.d.ts +0 -5
- package/dist/types/modules/core/contracts/index.d.ts +0 -30
- package/dist/types/modules/core/contracts/internal/compare.d.ts +0 -14
- package/dist/types/modules/core/contracts/internal/getBaseline.d.ts +0 -10
- package/dist/types/modules/core/contracts/internal/listTasks.d.ts +0 -12
- package/dist/types/modules/core/contracts/internal/taskRecords.d.ts +0 -6
- package/dist/types/modules/core/contracts/internal/updateBaseline.d.ts +0 -20
- package/dist/types/modules/core/contracts/model.d.ts +0 -80
- package/dist/types/modules/core/contracts/report.d.ts +0 -52
- package/dist/types/modules/core/contracts/repository.d.ts +0 -5
- package/dist/types/modules/core/contracts/requests.d.ts +0 -23
- package/dist/types/modules/core/contracts/scanCases.d.ts +0 -15
- package/dist/types/modules/core/contracts/shared.d.ts +0 -6
- package/dist/types/modules/core/contracts/snapshots.d.ts +0 -6
- package/dist/types/modules/core/contracts/taskRecord.d.ts +0 -76
- package/dist/types/modules/core/implementations/Functions/addCase.d.ts +0 -4
- package/dist/types/modules/core/implementations/Functions/addTask.d.ts +0 -4
- package/dist/types/modules/core/implementations/Functions/approve.d.ts +0 -6
- package/dist/types/modules/core/implementations/Functions/compare.d.ts +0 -15
- package/dist/types/modules/core/implementations/Functions/compareTask.d.ts +0 -3
- package/dist/types/modules/core/implementations/Functions/compareTasks.d.ts +0 -5
- package/dist/types/modules/core/implementations/Functions/deleteBaselineFile.d.ts +0 -4
- package/dist/types/modules/core/implementations/Functions/finishTask.d.ts +0 -4
- package/dist/types/modules/core/implementations/Functions/getBaseline.d.ts +0 -4
- package/dist/types/modules/core/implementations/Functions/getBaselineChanges.d.ts +0 -4
- package/dist/types/modules/core/implementations/Functions/getGitChanges.d.ts +0 -3
- package/dist/types/modules/core/implementations/Functions/getGitDiff.d.ts +0 -3
- package/dist/types/modules/core/implementations/Functions/getTaskCase.d.ts +0 -5
- package/dist/types/modules/core/implementations/Functions/getTaskTree.d.ts +0 -5
- package/dist/types/modules/core/implementations/Functions/listBaselines.d.ts +0 -3
- package/dist/types/modules/core/implementations/Functions/listTaskSummaries.d.ts +0 -2
- package/dist/types/modules/core/implementations/Functions/listTasks.d.ts +0 -4
- package/dist/types/modules/core/implementations/Functions/loadConfig.d.ts +0 -3
- package/dist/types/modules/core/implementations/Functions/readProjectInfo.d.ts +0 -3
- package/dist/types/modules/core/implementations/Functions/readTaskReport.d.ts +0 -3
- package/dist/types/modules/core/implementations/Functions/resolveConfig.d.ts +0 -9
- package/dist/types/modules/core/implementations/Functions/reviewBaselineChanges.d.ts +0 -4
- package/dist/types/modules/core/implementations/Functions/reviewCodeChanges.d.ts +0 -4
- package/dist/types/modules/core/implementations/Functions/taskRecords.d.ts +0 -4
- package/dist/types/modules/core/implementations/Functions/updateBaseline.d.ts +0 -5
- package/dist/types/modules/core/implementations/Utils/assertNamespace.d.ts +0 -1
- package/dist/types/modules/core/implementations/Utils/canonical.d.ts +0 -1
- package/dist/types/modules/core/implementations/Utils/createTaskId.d.ts +0 -1
- package/dist/types/modules/core/implementations/Utils/deletionAllowed.d.ts +0 -2
- package/dist/types/modules/core/implementations/Utils/download.d.ts +0 -3
- package/dist/types/modules/core/implementations/Utils/hash.d.ts +0 -1
- package/dist/types/modules/core/implementations/Utils/imageDiffPool.d.ts +0 -18
- package/dist/types/modules/core/implementations/Utils/imageKey.d.ts +0 -1
- package/dist/types/modules/core/implementations/Utils/loadBaseline.d.ts +0 -4
- package/dist/types/modules/core/implementations/Utils/mapLimit.d.ts +0 -1
- package/dist/types/modules/core/implementations/Utils/observationKey.d.ts +0 -1
- package/dist/types/modules/core/implementations/Utils/pngSize.d.ts +0 -4
- package/dist/types/modules/core/implementations/Utils/readJson.d.ts +0 -1
- package/dist/types/modules/core/implementations/Utils/readTaskRecord.d.ts +0 -2
- package/dist/types/modules/core/implementations/Utils/scanCases.d.ts +0 -9
- package/dist/types/modules/core/implementations/Utils/taskDirectory.d.ts +0 -1
- package/dist/types/modules/core/implementations/Utils/toCase.d.ts +0 -3
- package/dist/types/modules/core/implementations/Utils/toObservation.d.ts +0 -3
- package/dist/types/modules/core/implementations/Utils/toSnapshot.d.ts +0 -3
- package/dist/types/modules/core/implementations/Utils/writeBytesAtomic.d.ts +0 -1
- package/dist/types/modules/core/implementations/Utils/writeJsonAtomic.d.ts +0 -1
- package/dist/types/modules/core/implementations/Utils/writeTextAtomic.d.ts +0 -1
- package/dist/types/modules/core/implementations/baselineChanges.d.ts +0 -6
- package/dist/types/modules/core/implementations/config.d.ts +0 -6
- package/dist/types/modules/core/implementations/content.d.ts +0 -1
- package/dist/types/modules/core/implementations/evidra.d.ts +0 -31
- package/dist/types/modules/core/implementations/git.d.ts +0 -11
- package/dist/types/modules/core/implementations/gitChanges.d.ts +0 -29
- package/dist/types/modules/core/implementations/index.d.ts +0 -17
- package/dist/types/modules/core/implementations/internal/compare.d.ts +0 -15
- package/dist/types/modules/core/implementations/internal/getBaseline.d.ts +0 -4
- package/dist/types/modules/core/implementations/internal/listTasks.d.ts +0 -2
- package/dist/types/modules/core/implementations/internal/taskRecords.d.ts +0 -4
- package/dist/types/modules/core/implementations/internal/updateBaseline.d.ts +0 -5
- package/dist/types/modules/core/implementations/paths.d.ts +0 -48
- package/dist/types/modules/core/implementations/report.d.ts +0 -3
- package/dist/types/modules/core/implementations/reportResources.d.ts +0 -4
- package/dist/types/modules/core/implementations/reportStatus.d.ts +0 -10
- package/dist/types/modules/core/implementations/reportTree.d.ts +0 -5
- package/dist/types/modules/core/implementations/repository.d.ts +0 -10
- package/dist/types/modules/core/implementations/requests.d.ts +0 -13
- package/dist/types/modules/core/implementations/snapshots.d.ts +0 -11
- package/dist/types/modules/core/implementations/storage/local.d.ts +0 -3
- package/dist/types/modules/core/implementations/storage/objects.d.ts +0 -3
- package/dist/types/modules/core/index.d.ts +0 -21
- package/dist/types/packages/sdk/src/index.d.ts +0 -21
- package/dist/types/packages/sdk/src/types.d.ts +0 -9
- package/dist/web/assets/index-7nw0XeCR.css +0 -2
- package/dist/web/assets/index-DUtB8WRj.js +0 -35
|
@@ -1,19 +1,115 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { glob, readFile, stat } from "node:fs/promises";
|
|
2
3
|
import { promisify } from "node:util";
|
|
3
4
|
import { promises } from "node:fs";
|
|
4
5
|
import { execFile } from "node:child_process";
|
|
5
6
|
import { parseSync } from "oxc-parser";
|
|
7
|
+
// packages/conformance/builtinRules.ts
|
|
8
|
+
/** 内置规约的稳定 ID 同时对应随包发布的文档目录。 */
|
|
9
|
+
const builtinRules = {
|
|
10
|
+
baselineMaxDiffPixels: {
|
|
11
|
+
id: "baseline-max-diff-pixels",
|
|
12
|
+
displayName: "限制基线允许差异像素"
|
|
13
|
+
},
|
|
14
|
+
commitMessage: {
|
|
15
|
+
id: "commit-message",
|
|
16
|
+
displayName: "检查提交标题"
|
|
17
|
+
},
|
|
18
|
+
duplicateLocalization: {
|
|
19
|
+
id: "duplicate-localization",
|
|
20
|
+
displayName: "检查本地化键与默认文案"
|
|
21
|
+
},
|
|
22
|
+
e2eScenariosStructure: {
|
|
23
|
+
id: "e2e-scenarios-structure",
|
|
24
|
+
displayName: "检查端到端场景结构"
|
|
25
|
+
},
|
|
26
|
+
sameDirImportOnly: {
|
|
27
|
+
id: "same-dir-import-only",
|
|
28
|
+
displayName: "限制跨目录引用"
|
|
29
|
+
},
|
|
30
|
+
singleComponentFile: {
|
|
31
|
+
id: "single-component-file",
|
|
32
|
+
displayName: "单文件单组件"
|
|
33
|
+
},
|
|
34
|
+
sourceLocaleDefaults: {
|
|
35
|
+
id: "source-locale-defaults",
|
|
36
|
+
displayName: "检查源语言默认文案"
|
|
37
|
+
},
|
|
38
|
+
syncLocales: {
|
|
39
|
+
id: "sync-locales",
|
|
40
|
+
displayName: "同步本地化文件"
|
|
41
|
+
},
|
|
42
|
+
uiScenariosStructure: {
|
|
43
|
+
id: "ui-scenarios-structure",
|
|
44
|
+
displayName: "检查界面场景结构"
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
// packages/conformance/rules/baseline-max-diff-pixels/index.ts
|
|
48
|
+
function baselineMaxDiffPixels(options) {
|
|
49
|
+
const rule = builtinRules.baselineMaxDiffPixels;
|
|
50
|
+
const task = async ({ projectRoot }) => {
|
|
51
|
+
const { baselineDir, maxDiffPixels } = options;
|
|
52
|
+
if (typeof baselineDir !== "string" || !baselineDir.trim()) throw new Error("baselineDir 必须指定基线目录");
|
|
53
|
+
if (!Number.isSafeInteger(maxDiffPixels) || maxDiffPixels < 0) throw new Error("maxDiffPixels 必须是非负整数");
|
|
54
|
+
const root = path.resolve(projectRoot, baselineDir);
|
|
55
|
+
if (!(await stat(root)).isDirectory()) throw new Error(`基线路径必须是目录:${root}`);
|
|
56
|
+
const files = [];
|
|
57
|
+
for await (const file of glob("**/baseline*.json", {
|
|
58
|
+
cwd: root,
|
|
59
|
+
exclude: [
|
|
60
|
+
"**/node_modules/**",
|
|
61
|
+
"**/.git/**",
|
|
62
|
+
"**/cache/**"
|
|
63
|
+
]
|
|
64
|
+
})) if (/^baseline(?:-[a-f0-9]{64})?\.json$/.test(path.basename(file))) files.push(file);
|
|
65
|
+
files.sort();
|
|
66
|
+
let imageCount = 0;
|
|
67
|
+
const findings = [];
|
|
68
|
+
for (const file of files) {
|
|
69
|
+
const baselinePath = path.join(root, file);
|
|
70
|
+
const relative = path.relative(projectRoot, baselinePath);
|
|
71
|
+
let baseline;
|
|
72
|
+
try {
|
|
73
|
+
baseline = JSON.parse(await readFile(baselinePath, "utf8"));
|
|
74
|
+
} catch (error) {
|
|
75
|
+
findings.push(`${relative} 无法读取基线:${String(error)}`);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (!Array.isArray(baseline?.snapshots)) continue;
|
|
79
|
+
for (const snapshot of baseline.snapshots) {
|
|
80
|
+
if (snapshot?.type !== "image") continue;
|
|
81
|
+
imageCount++;
|
|
82
|
+
const tolerance = snapshot.maxDiffPixels ?? 0;
|
|
83
|
+
const label = `${relative} / ${baseline.name || baseline.id} / ${snapshot.name || snapshot.id}`;
|
|
84
|
+
if (!Number.isSafeInteger(tolerance) || tolerance < 0) findings.push(`${label} 的 maxDiffPixels 无效(${String(tolerance)})`);
|
|
85
|
+
else if (tolerance > maxDiffPixels) findings.push(`${label} 的 maxDiffPixels 为 ${tolerance},超过上限 ${maxDiffPixels}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
name: rule.id,
|
|
90
|
+
success: findings.length === 0,
|
|
91
|
+
messages: [`检查了 ${imageCount} 张基线图片,maxDiffPixels 上限为 ${maxDiffPixels}。`, ...findings].join("\n"),
|
|
92
|
+
howToFix: findings.length ? "检查报告中的文件和快照。需要调整阈值时,从测试上报配置设置 maxDiffPixels,重新上报后由用户审核基线。" : ""
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
return Object.assign(task, {
|
|
96
|
+
...rule,
|
|
97
|
+
readme: { builtin: rule.id }
|
|
98
|
+
});
|
|
99
|
+
}
|
|
6
100
|
// packages/conformance/rules/commit-message/index.ts
|
|
7
101
|
const execFileAsync = promisify(execFile);
|
|
8
102
|
function commitMessage(config = {}) {
|
|
9
|
-
|
|
103
|
+
const rule = builtinRules.commitMessage;
|
|
104
|
+
const ruleName = rule.id;
|
|
105
|
+
const task = async (common) => {
|
|
10
106
|
const { commits, scope } = await collectCommitSubjects(common.projectRoot, config.base);
|
|
11
107
|
const violations = commits.filter((commit) => (config.forbiddenPrefixes ?? ["```"]).some((prefix) => commit.subject.startsWith(prefix)));
|
|
12
108
|
const lines = [`扫描${scope} ${commits.length} 个提交 message。`];
|
|
13
109
|
if (violations.length === 0) {
|
|
14
110
|
lines.push("未发现以禁止的前缀开头的提交 message。");
|
|
15
111
|
return {
|
|
16
|
-
name:
|
|
112
|
+
name: ruleName,
|
|
17
113
|
success: true,
|
|
18
114
|
messages: lines.join("\n"),
|
|
19
115
|
howToFix: ""
|
|
@@ -22,12 +118,16 @@ function commitMessage(config = {}) {
|
|
|
22
118
|
lines.push(`发现 ${violations.length} 个提交 message 以禁止的前缀开头:`);
|
|
23
119
|
for (const violation of violations) lines.push(` - ${violation.hash.slice(0, 7)} ${violation.subject}`);
|
|
24
120
|
return {
|
|
25
|
-
name:
|
|
121
|
+
name: ruleName,
|
|
26
122
|
success: false,
|
|
27
123
|
messages: lines.join("\n"),
|
|
28
124
|
howToFix: "修改对应提交 message,移除禁止的前缀。"
|
|
29
125
|
};
|
|
30
126
|
};
|
|
127
|
+
return Object.assign(task, {
|
|
128
|
+
...rule,
|
|
129
|
+
readme: { builtin: rule.id }
|
|
130
|
+
});
|
|
31
131
|
}
|
|
32
132
|
async function collectCommitSubjects(repoRoot, base) {
|
|
33
133
|
const upstream = base ?? await readUpstream(repoRoot);
|
|
@@ -81,7 +181,9 @@ const SKIP_AST_KEYS$6 = /* @__PURE__ */ new Set([
|
|
|
81
181
|
"trailingComments"
|
|
82
182
|
]);
|
|
83
183
|
function duplicateLocalization(config) {
|
|
84
|
-
|
|
184
|
+
const rule = builtinRules.duplicateLocalization;
|
|
185
|
+
const ruleName = rule.id;
|
|
186
|
+
const task = async (common) => {
|
|
85
187
|
const options = {
|
|
86
188
|
...config,
|
|
87
189
|
repoRoot: common.projectRoot,
|
|
@@ -143,12 +245,16 @@ function duplicateLocalization(config) {
|
|
|
143
245
|
}
|
|
144
246
|
if (success) lines.push("No duplicate localization keys found.");
|
|
145
247
|
return {
|
|
146
|
-
name:
|
|
248
|
+
name: ruleName,
|
|
147
249
|
success,
|
|
148
250
|
messages: lines.join("\n"),
|
|
149
251
|
howToFix: success ? "" : "Replace template literals with string literals, and unify duplicate keys to share a single default message."
|
|
150
252
|
};
|
|
151
253
|
};
|
|
254
|
+
return Object.assign(task, {
|
|
255
|
+
...rule,
|
|
256
|
+
readme: { builtin: rule.id }
|
|
257
|
+
});
|
|
152
258
|
}
|
|
153
259
|
async function collectSourceFiles$2(root, excludeDirs, skipDirNames = [
|
|
154
260
|
"node_modules",
|
|
@@ -245,7 +351,9 @@ const SKIP_AST_KEYS$5 = /* @__PURE__ */ new Set([
|
|
|
245
351
|
"trailingComments"
|
|
246
352
|
]);
|
|
247
353
|
function syncLocales(config) {
|
|
248
|
-
|
|
354
|
+
const rule = builtinRules.syncLocales;
|
|
355
|
+
const ruleName = rule.id;
|
|
356
|
+
const task = async (common) => {
|
|
249
357
|
const options = {
|
|
250
358
|
...config,
|
|
251
359
|
repoRoot: common.projectRoot,
|
|
@@ -302,12 +410,16 @@ function syncLocales(config) {
|
|
|
302
410
|
}
|
|
303
411
|
if (hasUntranslatedKeys) howToFix.push("Translate the listed key(s) in non-default locale files, then run the check again.");
|
|
304
412
|
return {
|
|
305
|
-
name:
|
|
413
|
+
name: ruleName,
|
|
306
414
|
success,
|
|
307
415
|
messages: lines.join("\n"),
|
|
308
416
|
howToFix: howToFix.join(" ")
|
|
309
417
|
};
|
|
310
418
|
};
|
|
419
|
+
return Object.assign(task, {
|
|
420
|
+
...rule,
|
|
421
|
+
readme: { builtin: rule.id }
|
|
422
|
+
});
|
|
311
423
|
}
|
|
312
424
|
function mergeDefaultLocale(oldConfig, newLocale, metadataKey) {
|
|
313
425
|
const result = {};
|
|
@@ -448,7 +560,9 @@ const ESM_SOURCE_EXTENSIONS = {
|
|
|
448
560
|
".jsx": [".tsx"]
|
|
449
561
|
};
|
|
450
562
|
function sameDirImportOnly(config) {
|
|
451
|
-
|
|
563
|
+
const rule = builtinRules.sameDirImportOnly;
|
|
564
|
+
const ruleName = rule.id;
|
|
565
|
+
const task = async (common) => {
|
|
452
566
|
const marker = config.marker ?? "@import-scope same-dir";
|
|
453
567
|
const aliases = Object.entries(config.aliases ?? {}).sort(([a], [b]) => b.length - a.length).map(([prefix, target]) => [prefix, path.resolve(common.projectRoot, target)]);
|
|
454
568
|
const options = {
|
|
@@ -478,7 +592,7 @@ function sameDirImportOnly(config) {
|
|
|
478
592
|
if (violations.length === 0) {
|
|
479
593
|
lines.push("No cross-directory imports of protected files found.");
|
|
480
594
|
return {
|
|
481
|
-
name:
|
|
595
|
+
name: ruleName,
|
|
482
596
|
success: true,
|
|
483
597
|
messages: lines.join("\n"),
|
|
484
598
|
howToFix: ""
|
|
@@ -490,12 +604,16 @@ function sameDirImportOnly(config) {
|
|
|
490
604
|
lines.push(` protected file: ${path.relative(options.repoRoot, violation.target)}`);
|
|
491
605
|
}
|
|
492
606
|
return {
|
|
493
|
-
name:
|
|
607
|
+
name: ruleName,
|
|
494
608
|
success: false,
|
|
495
609
|
messages: lines.join("\n"),
|
|
496
610
|
howToFix: `Only import files marked with '${marker}' from files in the same directory, or move shared API into an unmarked file.`
|
|
497
611
|
};
|
|
498
612
|
};
|
|
613
|
+
return Object.assign(task, {
|
|
614
|
+
...rule,
|
|
615
|
+
readme: { builtin: rule.id }
|
|
616
|
+
});
|
|
499
617
|
}
|
|
500
618
|
async function collectSourceFiles(root, excludeDirs, skipDirNames = [
|
|
501
619
|
"node_modules",
|
|
@@ -722,7 +840,9 @@ function formatLocation$3(repoRoot, file, line) {
|
|
|
722
840
|
const CJK_PATTERN = /[\u4e00-\u9fff\u3400-\u4dbf\u3000-\u303f\uff00-\uffef]/;
|
|
723
841
|
/** 本地化调用在代码中的默认文案必须使用源语言(不匹配 pattern),翻译放在语言文件中。 */
|
|
724
842
|
function sourceLocaleDefaults(options) {
|
|
725
|
-
|
|
843
|
+
const rule = builtinRules.sourceLocaleDefaults;
|
|
844
|
+
const ruleName = rule.id;
|
|
845
|
+
const task = async (context) => {
|
|
726
846
|
const files = await collectFiles$3(context.projectRoot, options, [".ts", ".tsx"]);
|
|
727
847
|
const findings = [];
|
|
728
848
|
for (const file of files) {
|
|
@@ -741,7 +861,7 @@ function sourceLocaleDefaults(options) {
|
|
|
741
861
|
if (findings.length === 0) {
|
|
742
862
|
lines.push("未发现违规文案。");
|
|
743
863
|
return {
|
|
744
|
-
name:
|
|
864
|
+
name: ruleName,
|
|
745
865
|
success: true,
|
|
746
866
|
messages: lines.join("\n"),
|
|
747
867
|
howToFix: ""
|
|
@@ -749,12 +869,16 @@ function sourceLocaleDefaults(options) {
|
|
|
749
869
|
}
|
|
750
870
|
lines.push(`发现 ${findings.length} 处违规文案:`, ...findings);
|
|
751
871
|
return {
|
|
752
|
-
name:
|
|
872
|
+
name: ruleName,
|
|
753
873
|
success: false,
|
|
754
874
|
messages: lines.join("\n"),
|
|
755
875
|
howToFix: "默认文案改用源语言,其他语言的翻译写入语言文件。"
|
|
756
876
|
};
|
|
757
877
|
};
|
|
878
|
+
return Object.assign(task, {
|
|
879
|
+
...rule,
|
|
880
|
+
readme: { builtin: rule.id }
|
|
881
|
+
});
|
|
758
882
|
}
|
|
759
883
|
function matchCall(calls, callee) {
|
|
760
884
|
if (!callee) return void 0;
|
|
@@ -875,7 +999,9 @@ function formatLocation$2(repoRoot, file, line) {
|
|
|
875
999
|
// packages/conformance/rules/single-component-file/index.ts
|
|
876
1000
|
/** 每个 TSX 文件只定义一个返回 JSX 的组件。 */
|
|
877
1001
|
function singleComponentFile(options) {
|
|
878
|
-
|
|
1002
|
+
const rule = builtinRules.singleComponentFile;
|
|
1003
|
+
const ruleName = rule.id;
|
|
1004
|
+
const task = async (context) => {
|
|
879
1005
|
const wrappers = new Set(options.componentWrappers ?? ["memo", "forwardRef"]);
|
|
880
1006
|
const files = await collectFiles$2(context.projectRoot, options, [".tsx"]);
|
|
881
1007
|
const findings = [];
|
|
@@ -894,7 +1020,7 @@ function singleComponentFile(options) {
|
|
|
894
1020
|
if (findings.length === 0) {
|
|
895
1021
|
lines.push("未发现包含多个组件的 TSX 文件。");
|
|
896
1022
|
return {
|
|
897
|
-
name:
|
|
1023
|
+
name: ruleName,
|
|
898
1024
|
success: true,
|
|
899
1025
|
messages: lines.join("\n"),
|
|
900
1026
|
howToFix: ""
|
|
@@ -902,12 +1028,16 @@ function singleComponentFile(options) {
|
|
|
902
1028
|
}
|
|
903
1029
|
lines.push("以下 TSX 文件包含多个组件:", ...findings);
|
|
904
1030
|
return {
|
|
905
|
-
name:
|
|
1031
|
+
name: ruleName,
|
|
906
1032
|
success: false,
|
|
907
1033
|
messages: lines.join("\n"),
|
|
908
1034
|
howToFix: "把多出的组件移到各自的 TSX 文件,每个文件只保留一个组件。"
|
|
909
1035
|
};
|
|
910
1036
|
};
|
|
1037
|
+
return Object.assign(task, {
|
|
1038
|
+
...rule,
|
|
1039
|
+
readme: { builtin: rule.id }
|
|
1040
|
+
});
|
|
911
1041
|
}
|
|
912
1042
|
function readComponentName(node, wrappers) {
|
|
913
1043
|
if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") {
|
|
@@ -1052,12 +1182,13 @@ function formatLocation$1(repoRoot, file, line) {
|
|
|
1052
1182
|
* 且 shared 与 utils 互不引用。
|
|
1053
1183
|
*/
|
|
1054
1184
|
function e2eScenariosStructure(options) {
|
|
1055
|
-
|
|
1185
|
+
const rule = builtinRules.e2eScenariosStructure;
|
|
1186
|
+
const ruleName = options.name ?? rule.id;
|
|
1187
|
+
const task = async (context) => {
|
|
1056
1188
|
const repoRoot = context.projectRoot;
|
|
1057
1189
|
const entrySuffix = options.entrySuffix ?? ".spec.ts";
|
|
1058
1190
|
const strictRoot = options.strictRoot ?? false;
|
|
1059
1191
|
const root = path.resolve(repoRoot, options.root);
|
|
1060
|
-
const name = options.name ?? "e2e-scenarios-structure";
|
|
1061
1192
|
const sharedName = options.sharedDir ?? "shared";
|
|
1062
1193
|
const utilsName = options.utilsDir ?? "utils";
|
|
1063
1194
|
const threshold = options.sharedThreshold ?? 3;
|
|
@@ -1068,7 +1199,7 @@ function e2eScenariosStructure(options) {
|
|
|
1068
1199
|
const violations = [];
|
|
1069
1200
|
const entries = await readDirIfExists$1(root);
|
|
1070
1201
|
if (!entries) return {
|
|
1071
|
-
name,
|
|
1202
|
+
name: ruleName,
|
|
1072
1203
|
success: false,
|
|
1073
1204
|
messages: `场景根目录不存在:${path.relative(repoRoot, root)}`,
|
|
1074
1205
|
howToFix: "确认传入的场景根目录路径。"
|
|
@@ -1142,12 +1273,17 @@ function e2eScenariosStructure(options) {
|
|
|
1142
1273
|
if (success) lines.push("未发现结构违规。");
|
|
1143
1274
|
else lines.push(`发现 ${violations.filter((line) => line.startsWith(" - ")).length} 处违规:`, ...violations);
|
|
1144
1275
|
return {
|
|
1145
|
-
name,
|
|
1276
|
+
name: ruleName,
|
|
1146
1277
|
success,
|
|
1147
1278
|
messages: lines.join("\n"),
|
|
1148
1279
|
howToFix: success ? "" : `helper 移出入口文件:被 ${threshold} 个及以上入口使用的放到 ${sharedName},其余放到 ${utilsName}/<入口名>;${sharedName} 与 ${utilsName} 不要互相引用。`
|
|
1149
1280
|
};
|
|
1150
1281
|
};
|
|
1282
|
+
return Object.assign(task, {
|
|
1283
|
+
...rule,
|
|
1284
|
+
displayName: options.name ?? rule.displayName,
|
|
1285
|
+
readme: { builtin: rule.id }
|
|
1286
|
+
});
|
|
1151
1287
|
}
|
|
1152
1288
|
function readFunctionName$1(node) {
|
|
1153
1289
|
if (node.type === "FunctionDeclaration") return readName$1(node.id) ?? "匿名函数";
|
|
@@ -1287,13 +1423,14 @@ function formatLocation(repoRoot, file, line) {
|
|
|
1287
1423
|
* 且 shared 与 utils 互不引用。
|
|
1288
1424
|
*/
|
|
1289
1425
|
function uiScenariosStructure(options) {
|
|
1290
|
-
|
|
1426
|
+
const rule = builtinRules.uiScenariosStructure;
|
|
1427
|
+
const ruleName = options.name ?? rule.id;
|
|
1428
|
+
const task = async (context) => {
|
|
1291
1429
|
const repoRoot = context.projectRoot;
|
|
1292
1430
|
const entrySuffix = options.entrySuffix ?? ".ts";
|
|
1293
1431
|
const strictRoot = options.strictRoot ?? true;
|
|
1294
1432
|
const exportName = options.exportName ?? "lint";
|
|
1295
1433
|
const root = path.resolve(repoRoot, options.root);
|
|
1296
|
-
const name = options.name ?? "ui-scenarios-structure";
|
|
1297
1434
|
const sharedName = options.sharedDir ?? "shared";
|
|
1298
1435
|
const utilsName = options.utilsDir ?? "utils";
|
|
1299
1436
|
const threshold = options.sharedThreshold ?? 3;
|
|
@@ -1304,7 +1441,7 @@ function uiScenariosStructure(options) {
|
|
|
1304
1441
|
const violations = [];
|
|
1305
1442
|
const entries = await readDirIfExists(root);
|
|
1306
1443
|
if (!entries) return {
|
|
1307
|
-
name,
|
|
1444
|
+
name: ruleName,
|
|
1308
1445
|
success: false,
|
|
1309
1446
|
messages: `场景根目录不存在:${path.relative(repoRoot, root)}`,
|
|
1310
1447
|
howToFix: "确认传入的场景根目录路径。"
|
|
@@ -1380,12 +1517,17 @@ function uiScenariosStructure(options) {
|
|
|
1380
1517
|
if (success) lines.push("未发现结构违规。");
|
|
1381
1518
|
else lines.push(`发现 ${violations.filter((line) => line.startsWith(" - ")).length} 处违规:`, ...violations);
|
|
1382
1519
|
return {
|
|
1383
|
-
name,
|
|
1520
|
+
name: ruleName,
|
|
1384
1521
|
success,
|
|
1385
1522
|
messages: lines.join("\n"),
|
|
1386
1523
|
howToFix: success ? "" : `helper 移出入口文件:被 ${threshold} 个及以上入口使用的放到 ${sharedName},其余放到 ${utilsName}/<入口名>;${sharedName} 与 ${utilsName} 不要互相引用。`
|
|
1387
1524
|
};
|
|
1388
1525
|
};
|
|
1526
|
+
return Object.assign(task, {
|
|
1527
|
+
...rule,
|
|
1528
|
+
displayName: options.name ?? rule.displayName,
|
|
1529
|
+
readme: { builtin: rule.id }
|
|
1530
|
+
});
|
|
1389
1531
|
}
|
|
1390
1532
|
function readFunctionName(node) {
|
|
1391
1533
|
if (node.type === "FunctionDeclaration") return readName(node.id) ?? "匿名函数";
|
|
@@ -1451,4 +1593,4 @@ function collectImports(source, prefix) {
|
|
|
1451
1593
|
}
|
|
1452
1594
|
return imports;
|
|
1453
1595
|
}
|
|
1454
|
-
export { CJK_PATTERN, commitMessage, duplicateLocalization, e2eScenariosStructure, sameDirImportOnly, singleComponentFile, sourceLocaleDefaults, syncLocales, uiScenariosStructure };
|
|
1596
|
+
export { CJK_PATTERN, baselineMaxDiffPixels, commitMessage, duplicateLocalization, e2eScenariosStructure, sameDirImportOnly, singleComponentFile, sourceLocaleDefaults, syncLocales, uiScenariosStructure };
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as RuleResult, r as RuleTask, t as CommonConfig } from "./types
|
|
1
|
+
import { n as RuleResult, r as RuleTask, t as CommonConfig } from "./types--o0ku6ya.js";
|
|
2
2
|
/** evidra.conformance.ts 的默认导出。 */
|
|
3
3
|
interface Config {
|
|
4
4
|
/** 默认配置文件所在目录;相对路径也基于配置文件所在目录。 */
|
package/dist/sdk/rules.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import { r as RuleTask } from "./types
|
|
1
|
+
import { r as RuleTask } from "./types--o0ku6ya.js";
|
|
2
|
+
interface BaselineMaxDiffPixelsOptions {
|
|
3
|
+
/** 基线文件目录,支持绝对路径或相对 projectRoot 的路径。 */
|
|
4
|
+
baselineDir: string;
|
|
5
|
+
/** 每张基线图片允许配置的最大差异像素数。 */
|
|
6
|
+
maxDiffPixels: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function baselineMaxDiffPixels(options: BaselineMaxDiffPixelsOptions): RuleTask;
|
|
2
9
|
/** Git 提交标题检查配置。 */
|
|
3
10
|
interface CommitMessageOptions {
|
|
4
11
|
/** 禁止的提交标题前缀,默认 ["```"];传入空数组时不限制前缀。 */
|
|
@@ -146,4 +153,4 @@ interface UiScenariosStructureOptions {
|
|
|
146
153
|
* 且 shared 与 utils 互不引用。
|
|
147
154
|
*/
|
|
148
155
|
export declare function uiScenariosStructure(options: UiScenariosStructureOptions): RuleTask;
|
|
149
|
-
export type { CommitMessageOptions, DuplicateLocalizationOptions, E2eScenariosStructureOptions, LocalizationCall, SameDirImportOnlyOptions, SingleComponentFileOptions, SourceLocaleDefaultsOptions, SyncLocalesOptions, UiScenariosStructureOptions };
|
|
156
|
+
export type { BaselineMaxDiffPixelsOptions, CommitMessageOptions, DuplicateLocalizationOptions, E2eScenariosStructureOptions, LocalizationCall, SameDirImportOnlyOptions, SingleComponentFileOptions, SourceLocaleDefaultsOptions, SyncLocalesOptions, UiScenariosStructureOptions };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface RuleResult {
|
|
2
|
+
name: string;
|
|
3
|
+
success: boolean;
|
|
4
|
+
messages: string;
|
|
5
|
+
howToFix: string;
|
|
6
|
+
}
|
|
7
|
+
interface CommonConfig {
|
|
8
|
+
/** 已解析的项目绝对路径。 */
|
|
9
|
+
readonly projectRoot: string;
|
|
10
|
+
}
|
|
11
|
+
type RuleTask = ((commonConfig: CommonConfig) => Promise<RuleResult>) & {
|
|
12
|
+
/** 规约的稳定 ID,报告按此归并同一规约的配置。 */
|
|
13
|
+
readonly id?: string;
|
|
14
|
+
/** 用于在执行前展示规则名称。 */
|
|
15
|
+
readonly displayName?: string;
|
|
16
|
+
/** 相对于配置文件的 Markdown 路径,或内置规约文档的目录名。 */
|
|
17
|
+
readonly readme?: string | {
|
|
18
|
+
readonly builtin: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export { RuleResult as n, RuleTask as r, CommonConfig as t };
|