@akanjs/cli 3.2.0-rc.2 → 3.2.0-rc.21
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/.build-stamp +2 -1
- package/CodeAgent-faqv7t4g.js +11 -0
- package/{CodeTui-zyc7zaq6.js → CodeTui-vqck9tet.js} +822 -666
- package/README.ko.md +26 -1
- package/README.md +26 -1
- package/TunnelShare-bwe3ddv7.js +18 -0
- package/agent.command-p75jvgrd.js +56 -0
- package/akanCode.js +12 -12
- package/appExecutor-020cyesq.js +11 -0
- package/{application.command-vb278qnq.js → application.command-ta2knqxm.js} +72 -34
- package/{applicationBuildRunner-bqbyeg84.js → applicationBuildRunner-gkh82j2b.js} +18 -13
- package/buildBatch.proc.js +26 -11
- package/{cloud.command-ca777ee2.js → cloud.command-v3jhfvm5.js} +31 -28
- package/cloud.script-be9s1432.js +35 -0
- package/{code.command-j08txqcd.js → code.command-mh7dh1st.js} +14 -9
- package/{context.command-2fa6egp9.js → context.command-1ycfjkdd.js} +28 -23
- package/context.runner-333jkz86.js +34 -0
- package/{dependencyScanner-78sq8m4q.js → dependencyScanner-ge10gb52.js} +2 -2
- package/{devTui-w38ch13a.js → devTui-rf374y2w.js} +1 -1
- package/{fileSys-zpvt5gtf.js → fileSys-q22646yc.js} +1 -1
- package/{guideline.command-w6yqpdec.js → guideline.command-w1grfwh7.js} +9 -4
- package/guidelines/agentRule/agentRule.instruction.md +17 -5
- package/guidelines/akanApi/akanApi.instruction.md +5 -3
- package/guidelines/conventions/core.md +23 -5
- package/guidelines/conventions/rules/app.md +4 -1
- package/guidelines/conventions/rules/page.md +5 -0
- package/guidelines/errorCodes/errorCodes.instruction.md +158 -0
- package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
- package/guidelines/mcpRule/mcpRule.instruction.md +86 -2
- package/guidelines/pageRule/pageRule.instruction.md +11 -1
- package/guidelines/runtimeRule/runtimeRule.instruction.md +7 -2
- package/guidelines/transportRule/transportRule.instruction.md +8 -1
- package/incrementalBuilder.proc.js +574 -410
- package/{index-c5ymqb05.js → index-013n6z7m.js} +12 -12
- package/{index-w15mg3km.js → index-0dm25wvf.js} +1 -1
- package/{index-8nbx607g.js → index-0hj82f9w.js} +136 -48
- package/{index-ebwkh7bt.js → index-1c0mjc2b.js} +25 -7
- package/{index-6h775rv3.js → index-1jk52ffq.js} +53 -12
- package/{index-hj6w4ka1.js → index-1p81ecbz.js} +1 -1
- package/{index-ygrdw6jw.js → index-1pjwsh2g.js} +65 -8
- package/{index-cbcwxp5v.js → index-22g3jq43.js} +9 -7
- package/{index-466z5931.js → index-2d9nm03s.js} +580 -364
- package/{index-0fj9ra3q.js → index-2k6mve6a.js} +18 -11
- package/{index-qd7xn2bk.js → index-2ny1e95c.js} +2 -2
- package/{index-j7p0jgaq.js → index-52w4jb87.js} +6 -6
- package/{index-e22zedc2.js → index-5h888r6j.js} +3 -3
- package/{index-7kmbqp0b.js → index-6pxmcaq8.js} +1 -1
- package/{index-xa0289eg.js → index-6zb17wcm.js} +16 -9
- package/{index-qgazn58x.js → index-7a07tdap.js} +50 -38
- package/{index-m5sg5spm.js → index-7ehdht84.js} +565 -187
- package/{index-y725zb1a.js → index-7v7tvgt7.js} +196 -168
- package/{index-pq5rjkch.js → index-88s746ns.js} +7 -2
- package/{index-r0a604h4.js → index-99kjwyma.js} +1 -1
- package/{index-2mrn1mrg.js → index-9f3reh2y.js} +1 -1
- package/{index-386canwe.js → index-9rv2zt48.js} +186 -121
- package/{index-wr9magsr.js → index-9zswcze5.js} +3 -3
- package/{index-xq97me1h.js → index-a41vv4cy.js} +811 -697
- package/{index-yf9wc28h.js → index-bejy9zyc.js} +1 -1
- package/{index-bdmgqzb5.js → index-bket1068.js} +58 -29
- package/{index-bns3wcpc.js → index-by2tvsq6.js} +1 -1
- package/{index-1cb9apzn.js → index-czf94w8c.js} +2 -2
- package/{index-65b6ms4c.js → index-d3178asw.js} +15 -11
- package/index-dss3ds74.js +127 -0
- package/{index-annxfpgz.js → index-eyfty8kk.js} +9 -9
- package/{index-ny2k80mv.js → index-ffa52fwf.js} +1 -1
- package/{index-8jpc5fqv.js → index-g7jgd4xs.js} +2 -2
- package/{index-abfbf01s.js → index-gwsesvqc.js} +2 -2
- package/{index-kcpk2d20.js → index-h1w4wqgd.js} +1474 -1139
- package/{index-j1hjb477.js → index-hp2c7xc2.js} +1 -1
- package/index-j4yvgfhr.js +70 -0
- package/{index-84c2pgak.js → index-jx2jcw1r.js} +89 -78
- package/{index-j6eeh5d7.js → index-knpm8sdm.js} +5 -5
- package/{index-2gees180.js → index-mpp4aas6.js} +62 -33
- package/index-na8r4a27.js +30 -0
- package/{index-0mqga3h9.js → index-nmxszh6x.js} +525 -440
- package/{index-35j83zkd.js → index-p5zh7pmc.js} +2 -2
- package/{index-20wvskt8.js → index-pt0agdck.js} +1 -1
- package/{index-htxck0pn.js → index-q444k260.js} +15 -10
- package/{index-wfmpxke3.js → index-qssq2d41.js} +2775 -3677
- package/{index-23860fej.js → index-rwgqba9p.js} +24 -9
- package/{index-v50xjbbe.js → index-t4d0ckde.js} +1 -1
- package/index-va90m8nd.js +25 -0
- package/index-vjbne22r.js +80 -0
- package/{index-djc5nxpy.js → index-w23tf30e.js} +6 -6
- package/{index-mvwvxgtd.js → index-wa01phm9.js} +289 -210
- package/{index-h7hehkw6.js → index-xczjdng6.js} +3 -1
- package/{index-vbhx60x5.js → index-xwe7y0gf.js} +2140 -2165
- package/index-ze48c0vd.js +788 -0
- package/{index-dk4g0x0d.js → index-zttyg7tg.js} +27 -16
- package/{index-ygdbn9jn.js → index-zyb0ebm4.js} +1 -1
- package/index.js +29 -24
- package/libExecutor-tq994592.js +10 -0
- package/{library.command-8d03a0pq.js → library.command-x219mhcx.js} +9 -4
- package/{localRegistry.command-vyv5k6t0.js → localRegistry.command-4p17wa9t.js} +30 -24
- package/{module.command-vy3kg965.js → module.command-tjthnvvr.js} +17 -8
- package/{package.command-qjh13rs9.js → package.command-c6df2hxx.js} +13 -8
- package/package.json +2 -2
- package/{page.command-t0nx1jat.js → page.command-gf06paq2.js} +9 -4
- package/{pipeline.command-2yjeas7m.js → pipeline.command-y07dgj9b.js} +14 -8
- package/pkgExecutor-stde3yc3.js +10 -0
- package/{primitive.command-8vm49279.js → primitive.command-0enfygxn.js} +13 -8
- package/{projectTypecheck-s9hhe5sa.js → projectTypecheck-mk8wefvd.js} +2 -1
- package/{prompter-qrwx1p17.js → prompter-qyggfhqd.js} +2 -2
- package/{quality.command-v76fev72.js → quality.command-dkbdztad.js} +23 -16
- package/{recipeScanner-4b69ybe0.js → recipeScanner-rrx69awy.js} +1 -1
- package/{repair.command-fp4m3w03.js → repair.command-g5vd95ax.js} +13 -8
- package/{routeSourceValidator-4h947v7c.js → routeSourceValidator-8n6j1vn7.js} +4 -2
- package/{scalar.command-hxe6try8.js → scalar.command-7909pg0d.js} +11 -6
- package/skills/akan-debug/SKILL.md +10 -3
- package/skills/akan-err/SKILL.md +7 -0
- package/skills/akan-mcp/SKILL.md +13 -2
- package/skills/akan-scaffold/SKILL.md +2 -2
- package/skills/akan-transport/SKILL.md +2 -0
- package/skills/akan-validate/SKILL.md +1 -0
- package/{subspace.command-q42n1844.js → subspace.command-at4jt1fb.js} +29 -23
- package/templates/biomeForm.ts +1 -1
- package/templates/env/_env.server.type.ts +1 -1
- package/templates/facetIndex/index.ts +2 -37
- package/templates/lib/sig.ts +0 -4
- package/templates/lib/useClient.ts +1 -1
- package/templates/workspaceRoot/AGENTS.md.template +2 -1
- package/{tunnel.command-22g11n0x.js → tunnel.command-91h92dwr.js} +17 -12
- package/{typeChecker-s640r6c0.js → typeChecker-bfrd1n9n.js} +1 -1
- package/typecheck.proc.js +6 -3
- package/{verify.command-rx43bha1.js → verify.command-pzky05ts.js} +26 -20
- package/{workflow.command-yg0d8mmq.js → workflow.command-mqqe4n12.js} +37 -19
- package/{workspace.command-fcfztvn5.js → workspace.command-y4rznvhx.js} +64 -53
- package/CodeAgent-6cpjtj25.js +0 -11
- package/TunnelShare-zkfkrw8w.js +0 -14
- package/agent.command-kf1g3nh4.js +0 -51
- package/cloud.script-agpxzq6j.js +0 -30
- package/context.runner-ftv8373t.js +0 -29
|
@@ -2,26 +2,34 @@
|
|
|
2
2
|
import {
|
|
3
3
|
camelToKebabCase,
|
|
4
4
|
runner
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-9rv2zt48.js";
|
|
6
6
|
import {
|
|
7
|
-
FileSys2
|
|
8
|
-
} from "./index-bns3wcpc.js";
|
|
9
|
-
import {
|
|
10
|
-
extractAgentBlock,
|
|
11
|
-
collectScopeRecipeSources,
|
|
12
|
-
renderScopeAgentBlock,
|
|
13
|
-
Linter,
|
|
14
7
|
rootAllowedFiles,
|
|
15
8
|
rootAllowedDirs,
|
|
16
9
|
isAllowedLibFacetRootFile,
|
|
17
10
|
libFacetRootHintOf,
|
|
18
11
|
facetIndexShadowOf,
|
|
19
12
|
rootEntryHintOf,
|
|
20
|
-
|
|
13
|
+
Linter,
|
|
14
|
+
extractAgentBlock,
|
|
15
|
+
collectScopeRecipeSources,
|
|
16
|
+
renderScopeAgentBlock,
|
|
21
17
|
SysExecutor,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
WorkspaceExecutor
|
|
19
|
+
} from "./index-qssq2d41.js";
|
|
20
|
+
import {
|
|
21
|
+
FileSys2
|
|
22
|
+
} from "./index-by2tvsq6.js";
|
|
23
|
+
import {
|
|
24
|
+
LibExecutor2
|
|
25
|
+
} from "./index-na8r4a27.js";
|
|
26
|
+
import {
|
|
27
|
+
PkgExecutor2
|
|
28
|
+
} from "./index-dss3ds74.js";
|
|
29
|
+
import {
|
|
30
|
+
collectRecipeSources2,
|
|
31
|
+
scanRecipes2
|
|
32
|
+
} from "./index-1p81ecbz.js";
|
|
25
33
|
import {
|
|
26
34
|
countBlocking,
|
|
27
35
|
formatStyleContract,
|
|
@@ -29,53 +37,141 @@ import {
|
|
|
29
37
|
} from "./index-62md4dwy.js";
|
|
30
38
|
import {
|
|
31
39
|
GitRevision
|
|
32
|
-
} from "./index-
|
|
40
|
+
} from "./index-zyb0ebm4.js";
|
|
33
41
|
import {
|
|
34
42
|
MaintainabilityBaseline
|
|
35
|
-
} from "./index-
|
|
43
|
+
} from "./index-1pjwsh2g.js";
|
|
36
44
|
import {
|
|
37
45
|
createFactReader,
|
|
38
46
|
createAst
|
|
39
|
-
} from "./index-
|
|
40
|
-
import {
|
|
41
|
-
collectRecipeSources2,
|
|
42
|
-
scanRecipes2
|
|
43
|
-
} from "./index-hj6w4ka1.js";
|
|
47
|
+
} from "./index-7ehdht84.js";
|
|
44
48
|
import {
|
|
45
49
|
getNpmRegistryUrl,
|
|
46
50
|
getLatestPackageVersion
|
|
47
|
-
} from "./index-
|
|
51
|
+
} from "./index-ffa52fwf.js";
|
|
48
52
|
import {
|
|
49
53
|
sysInputs,
|
|
50
54
|
workflowSpecs
|
|
51
|
-
} from "./index-
|
|
55
|
+
} from "./index-t4d0ckde.js";
|
|
52
56
|
|
|
53
57
|
// pkgs/@akanjs/cli/workspace/workspace.runner.ts
|
|
54
58
|
import { mkdir, writeFile as writeFile2 } from "fs/promises";
|
|
55
59
|
import os from "os";
|
|
56
60
|
import path5 from "path";
|
|
57
61
|
|
|
58
|
-
// pkgs/@akanjs/devkit/biomeBase.ts
|
|
62
|
+
// pkgs/@akanjs/devkit/lint/biomeBase.ts
|
|
59
63
|
var biomeVersion = "2.5.14";
|
|
60
64
|
|
|
61
|
-
// pkgs/@akanjs/devkit/maintainabilityContract.ts
|
|
65
|
+
// pkgs/@akanjs/devkit/quality/maintainabilityContract.ts
|
|
62
66
|
import { existsSync } from "fs";
|
|
63
|
-
import { readFile, rm, writeFile } from "fs/promises";
|
|
67
|
+
import { copyFile, mkdtemp, readFile, rm, writeFile } from "fs/promises";
|
|
68
|
+
import { tmpdir } from "os";
|
|
64
69
|
import path4 from "path";
|
|
65
|
-
import
|
|
70
|
+
import ts13 from "typescript";
|
|
66
71
|
|
|
67
|
-
// pkgs/@akanjs/devkit/
|
|
72
|
+
// pkgs/@akanjs/devkit/quality/bareErrorScanner.ts
|
|
68
73
|
import ts from "typescript";
|
|
69
74
|
|
|
75
|
+
class BareErrorScanner {
|
|
76
|
+
static #builtins = new Set([
|
|
77
|
+
"Error",
|
|
78
|
+
"TypeError",
|
|
79
|
+
"RangeError",
|
|
80
|
+
"SyntaxError",
|
|
81
|
+
"ReferenceError",
|
|
82
|
+
"EvalError",
|
|
83
|
+
"URIError",
|
|
84
|
+
"AggregateError"
|
|
85
|
+
]);
|
|
86
|
+
static #globals = new Set(["globalThis", "window", "self"]);
|
|
87
|
+
static #options = { noLib: true, noResolve: true, noEmit: true, types: [] };
|
|
88
|
+
lines(sourceFile) {
|
|
89
|
+
const declared = BareErrorScanner.#declaredNamesOf(sourceFile);
|
|
90
|
+
const shadows = [...BareErrorScanner.#builtins, ...BareErrorScanner.#globals].some((name) => declared.has(name));
|
|
91
|
+
if (!shadows)
|
|
92
|
+
return BareErrorScanner.#scan(sourceFile, () => true);
|
|
93
|
+
const rootName = sourceFile.fileName.endsWith(".tsx") ? "/scan.tsx" : "/scan.ts";
|
|
94
|
+
const scope = ts.createSourceFile(rootName, sourceFile.text, ts.ScriptTarget.Latest, true, rootName.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
95
|
+
const checker = ts.createProgram({
|
|
96
|
+
rootNames: [rootName],
|
|
97
|
+
options: BareErrorScanner.#options,
|
|
98
|
+
host: BareErrorScanner.#hostOf(scope)
|
|
99
|
+
}).getTypeChecker();
|
|
100
|
+
return BareErrorScanner.#scan(scope, (identifier) => !checker.getSymbolAtLocation(identifier)?.declarations?.some((declaration) => declaration.getSourceFile() === scope));
|
|
101
|
+
}
|
|
102
|
+
static #scan(sourceFile, isGlobal) {
|
|
103
|
+
const lines = [];
|
|
104
|
+
const visit = (node) => {
|
|
105
|
+
const constructed = ts.isNewExpression(node) || ts.isCallExpression(node) ? node.expression : null;
|
|
106
|
+
const extended = ts.isClassDeclaration(node) || ts.isClassExpression(node) ? node.heritageClauses?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword)?.types[0]?.expression : null;
|
|
107
|
+
const target = constructed ?? extended;
|
|
108
|
+
if (target && BareErrorScanner.#namesBuiltin(target, isGlobal))
|
|
109
|
+
lines.push(sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1);
|
|
110
|
+
ts.forEachChild(node, visit);
|
|
111
|
+
};
|
|
112
|
+
ts.forEachChild(sourceFile, visit);
|
|
113
|
+
return lines;
|
|
114
|
+
}
|
|
115
|
+
static #declaredNamesOf(sourceFile) {
|
|
116
|
+
const names = new Set;
|
|
117
|
+
const visit = (node) => {
|
|
118
|
+
if (ts.isIdentifier(node) && BareErrorScanner.#declares(node.parent, node))
|
|
119
|
+
names.add(node.text);
|
|
120
|
+
ts.forEachChild(node, visit);
|
|
121
|
+
};
|
|
122
|
+
ts.forEachChild(sourceFile, visit);
|
|
123
|
+
return names;
|
|
124
|
+
}
|
|
125
|
+
static #declares(parent, identifier) {
|
|
126
|
+
return (ts.isVariableDeclaration(parent) || ts.isParameter(parent) || ts.isBindingElement(parent) || ts.isFunctionDeclaration(parent) || ts.isFunctionExpression(parent) || ts.isClassDeclaration(parent) || ts.isClassExpression(parent) || ts.isImportSpecifier(parent) || ts.isImportClause(parent) || ts.isNamespaceImport(parent) || ts.isImportEqualsDeclaration(parent) || ts.isEnumDeclaration(parent) || ts.isModuleDeclaration(parent)) && parent.name === identifier;
|
|
127
|
+
}
|
|
128
|
+
static #namesBuiltin(expression, isGlobal) {
|
|
129
|
+
const callee = BareErrorScanner.#unwrapped(expression);
|
|
130
|
+
if (ts.isIdentifier(callee))
|
|
131
|
+
return BareErrorScanner.#builtins.has(callee.text) && isGlobal(callee);
|
|
132
|
+
if (!ts.isPropertyAccessExpression(callee) || !BareErrorScanner.#builtins.has(callee.name.text))
|
|
133
|
+
return false;
|
|
134
|
+
const owner = BareErrorScanner.#unwrapped(callee.expression);
|
|
135
|
+
return ts.isIdentifier(owner) && BareErrorScanner.#globals.has(owner.text) && isGlobal(owner);
|
|
136
|
+
}
|
|
137
|
+
static #unwrapped(expression) {
|
|
138
|
+
let current = expression;
|
|
139
|
+
while (ts.isParenthesizedExpression(current) || ts.isAsExpression(current) || ts.isSatisfiesExpression(current) || ts.isNonNullExpression(current) || ts.isTypeAssertionExpression(current))
|
|
140
|
+
current = current.expression;
|
|
141
|
+
return current;
|
|
142
|
+
}
|
|
143
|
+
static #hostOf(scope) {
|
|
144
|
+
return {
|
|
145
|
+
getSourceFile: (fileName) => fileName === scope.fileName ? scope : undefined,
|
|
146
|
+
writeFile: () => {
|
|
147
|
+
return;
|
|
148
|
+
},
|
|
149
|
+
getDefaultLibFileName: () => "/lib.d.ts",
|
|
150
|
+
useCaseSensitiveFileNames: () => true,
|
|
151
|
+
getCanonicalFileName: (fileName) => fileName,
|
|
152
|
+
getCurrentDirectory: () => "/",
|
|
153
|
+
getNewLine: () => `
|
|
154
|
+
`,
|
|
155
|
+
fileExists: (fileName) => fileName === scope.fileName,
|
|
156
|
+
readFile: () => {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// pkgs/@akanjs/devkit/quality/componentSizeScanner.ts
|
|
164
|
+
import ts2 from "typescript";
|
|
165
|
+
|
|
70
166
|
class ComponentSizeScanner {
|
|
71
167
|
static #componentName = /^(?:[A-Z]|use[A-Z])[A-Za-z0-9]*$/;
|
|
72
168
|
static componentsAndHooksOf(sourceFile) {
|
|
73
169
|
return sourceFile.statements.flatMap((statement) => {
|
|
74
|
-
if (
|
|
170
|
+
if (ts2.isFunctionDeclaration(statement))
|
|
75
171
|
return statement.name && statement.body && ComponentSizeScanner.#componentName.test(statement.name.text) ? [{ name: statement.name.text, node: statement }] : [];
|
|
76
|
-
if (!
|
|
172
|
+
if (!ts2.isVariableStatement(statement))
|
|
77
173
|
return [];
|
|
78
|
-
return statement.declarationList.declarations.flatMap((declaration) =>
|
|
174
|
+
return statement.declarationList.declarations.flatMap((declaration) => ts2.isIdentifier(declaration.name) && ComponentSizeScanner.#componentName.test(declaration.name.text) && declaration.initializer && ComponentSizeScanner.#holdsFunction(declaration.initializer) ? [{ name: declaration.name.text, node: declaration }] : []);
|
|
79
175
|
});
|
|
80
176
|
}
|
|
81
177
|
measure(sourceFile) {
|
|
@@ -87,21 +183,30 @@ class ComponentSizeScanner {
|
|
|
87
183
|
}
|
|
88
184
|
static #holdsFunction(expression) {
|
|
89
185
|
let current = expression;
|
|
90
|
-
while (
|
|
186
|
+
while (ts2.isParenthesizedExpression(current) || ts2.isAsExpression(current) || ts2.isSatisfiesExpression(current))
|
|
91
187
|
current = current.expression;
|
|
92
|
-
if (
|
|
188
|
+
if (ts2.isArrowFunction(current) || ts2.isFunctionExpression(current))
|
|
93
189
|
return true;
|
|
94
|
-
return
|
|
190
|
+
return ts2.isCallExpression(current) && current.arguments.some((arg) => ComponentSizeScanner.#holdsFunction(arg));
|
|
95
191
|
}
|
|
96
192
|
}
|
|
97
193
|
|
|
98
|
-
// pkgs/@akanjs/devkit/componentWriteChainScanner.ts
|
|
99
|
-
import
|
|
194
|
+
// pkgs/@akanjs/devkit/quality/componentWriteChainScanner.ts
|
|
195
|
+
import ts5 from "typescript";
|
|
196
|
+
|
|
197
|
+
// pkgs/@akanjs/devkit/quality/storeAccessScanner.ts
|
|
198
|
+
import ts3 from "typescript";
|
|
199
|
+
var formSetterPrefixes = ["set", "add", "sub", "addOrSub", "upload"];
|
|
200
|
+
var startsUpper = (text) => /^[A-Z]/.test(text);
|
|
201
|
+
var isFormSetterName = (name) => {
|
|
202
|
+
if (!/^\w+$/.test(name))
|
|
203
|
+
return false;
|
|
204
|
+
if (name.startsWith("writeOn"))
|
|
205
|
+
return startsUpper(name.slice("writeOn".length));
|
|
206
|
+
return formSetterPrefixes.some((prefix) => name.startsWith(prefix) && startsUpper(name.slice(prefix.length)) && /On[A-Z]/.test(name.slice(prefix.length + 1)));
|
|
207
|
+
};
|
|
100
208
|
|
|
101
|
-
// pkgs/@akanjs/devkit/storeAccessScanner.ts
|
|
102
|
-
import ts2 from "typescript";
|
|
103
209
|
class StoreAccessScanner {
|
|
104
|
-
static #formSetter = /^(?:(?:set|add|sub|addOrSub|upload)[A-Z]\w*On|writeOn)[A-Z]\w*$/;
|
|
105
210
|
#index;
|
|
106
211
|
constructor(index) {
|
|
107
212
|
this.#index = index;
|
|
@@ -112,10 +217,10 @@ class StoreAccessScanner {
|
|
|
112
217
|
static localNamesOf(sourceFile, imported) {
|
|
113
218
|
const names = new Set;
|
|
114
219
|
for (const statement of sourceFile.statements) {
|
|
115
|
-
if (!
|
|
220
|
+
if (!ts3.isImportDeclaration(statement) || statement.importClause?.isTypeOnly)
|
|
116
221
|
continue;
|
|
117
222
|
const bindings = statement.importClause?.namedBindings;
|
|
118
|
-
if (!bindings || !
|
|
223
|
+
if (!bindings || !ts3.isNamedImports(bindings))
|
|
119
224
|
continue;
|
|
120
225
|
for (const element of bindings.elements)
|
|
121
226
|
if (!element.isTypeOnly && (element.propertyName ?? element.name).text === imported)
|
|
@@ -130,9 +235,9 @@ class StoreAccessScanner {
|
|
|
130
235
|
return ComponentSizeScanner.componentsAndHooksOf(sourceFile).map(({ name, node }) => {
|
|
131
236
|
let accessCount = 0;
|
|
132
237
|
const visit = (child) => {
|
|
133
|
-
if (
|
|
238
|
+
if (ts3.isPropertyAccessExpression(child) && ts3.isIdentifier(child.expression) && stNames.has(child.expression.text) && !this.#isFormSetter(child))
|
|
134
239
|
accessCount += 1;
|
|
135
|
-
|
|
240
|
+
ts3.forEachChild(child, visit);
|
|
136
241
|
};
|
|
137
242
|
visit(node);
|
|
138
243
|
return {
|
|
@@ -144,12 +249,12 @@ class StoreAccessScanner {
|
|
|
144
249
|
}
|
|
145
250
|
#isFormSetter(access) {
|
|
146
251
|
const action = access.parent;
|
|
147
|
-
return access.name.text === "do" &&
|
|
252
|
+
return access.name.text === "do" && ts3.isPropertyAccessExpression(action) && action.expression === access && isFormSetterName(action.name.text) && !this.#index.isWritingAction(action.name.text);
|
|
148
253
|
}
|
|
149
254
|
}
|
|
150
255
|
|
|
151
|
-
// pkgs/@akanjs/devkit/writePath.ts
|
|
152
|
-
import
|
|
256
|
+
// pkgs/@akanjs/devkit/quality/writePath.ts
|
|
257
|
+
import ts4 from "typescript";
|
|
153
258
|
|
|
154
259
|
class WritePath {
|
|
155
260
|
static #perElement = new Set([
|
|
@@ -171,15 +276,15 @@ class WritePath {
|
|
|
171
276
|
this.#enters = enters;
|
|
172
277
|
}
|
|
173
278
|
along(node) {
|
|
174
|
-
if (
|
|
279
|
+
if (ts4.isFunctionLike(node) && !this.#enters(node))
|
|
175
280
|
return [];
|
|
176
281
|
if (WritePath.isPerElementCallback(node))
|
|
177
282
|
return this.#repeat(this.#children(node));
|
|
178
283
|
if (WritePath.#isFlowStatement(node))
|
|
179
284
|
return this.#busiestOf(this.#flowOf(node));
|
|
180
|
-
if (
|
|
285
|
+
if (ts4.isConditionalExpression(node))
|
|
181
286
|
return [...this.along(node.condition), ...this.#busier(this.along(node.whenTrue), this.along(node.whenFalse))];
|
|
182
|
-
const own =
|
|
287
|
+
const own = ts4.isCallExpression(node) && this.#matches(node) ? [node] : [];
|
|
183
288
|
return [...own, ...this.#children(node)];
|
|
184
289
|
}
|
|
185
290
|
isRepeated(call) {
|
|
@@ -194,11 +299,11 @@ class WritePath {
|
|
|
194
299
|
}
|
|
195
300
|
static isPerElementCallback(node) {
|
|
196
301
|
const call = node.parent;
|
|
197
|
-
return (
|
|
302
|
+
return (ts4.isArrowFunction(node) || ts4.isFunctionExpression(node)) && !!call && ts4.isCallExpression(call) && call.arguments.some((arg) => arg === node) && ts4.isPropertyAccessExpression(call.expression) && WritePath.#perElement.has(call.expression.name.text);
|
|
198
303
|
}
|
|
199
304
|
#children(node) {
|
|
200
305
|
const children = [];
|
|
201
|
-
|
|
306
|
+
ts4.forEachChild(node, (child) => {
|
|
202
307
|
children.push(child);
|
|
203
308
|
});
|
|
204
309
|
return children.flatMap((child) => this.along(child));
|
|
@@ -209,25 +314,25 @@ class WritePath {
|
|
|
209
314
|
return calls;
|
|
210
315
|
}
|
|
211
316
|
#flowOf(node) {
|
|
212
|
-
if (
|
|
317
|
+
if (ts4.isBlock(node))
|
|
213
318
|
return this.#sequenceOf(node.statements);
|
|
214
|
-
if (
|
|
319
|
+
if (ts4.isReturnStatement(node) || ts4.isThrowStatement(node))
|
|
215
320
|
return { through: null, exit: node.expression ? this.along(node.expression) : [], jump: null };
|
|
216
|
-
if (
|
|
321
|
+
if (ts4.isBreakStatement(node) || ts4.isContinueStatement(node))
|
|
217
322
|
return { through: null, exit: null, jump: [] };
|
|
218
|
-
if (
|
|
323
|
+
if (ts4.isLabeledStatement(node))
|
|
219
324
|
return this.#flowOf(node.statement);
|
|
220
|
-
if (
|
|
325
|
+
if (ts4.isIfStatement(node))
|
|
221
326
|
return WritePath.#prefixed(this.along(node.expression), this.#merged(this.#flowOf(node.thenStatement), node.elseStatement ? this.#flowOf(node.elseStatement) : WritePath.#onward([])));
|
|
222
|
-
if (
|
|
327
|
+
if (ts4.isSwitchStatement(node))
|
|
223
328
|
return WritePath.#prefixed(this.along(node.expression), this.#switchOf(node));
|
|
224
|
-
if (
|
|
329
|
+
if (ts4.isTryStatement(node))
|
|
225
330
|
return this.#tryOf(node);
|
|
226
|
-
if (
|
|
331
|
+
if (ts4.isForOfStatement(node) || ts4.isForInStatement(node))
|
|
227
332
|
return this.#loopOf(this.along(node.expression), [], node.statement, true);
|
|
228
|
-
if (
|
|
333
|
+
if (ts4.isForStatement(node))
|
|
229
334
|
return this.#loopOf(node.initializer ? this.along(node.initializer) : [], [node.condition, node.incrementor].flatMap((part) => part ? this.along(part) : []), node.statement, WritePath.#walksItems(node.condition));
|
|
230
|
-
if (
|
|
335
|
+
if (ts4.isWhileStatement(node) || ts4.isDoStatement(node))
|
|
231
336
|
return this.#loopOf([], this.along(node.expression), node.statement, WritePath.#walksItems(node.expression));
|
|
232
337
|
return WritePath.#onward(this.along(node));
|
|
233
338
|
}
|
|
@@ -248,7 +353,7 @@ class WritePath {
|
|
|
248
353
|
return { through, exit, jump };
|
|
249
354
|
}
|
|
250
355
|
#switchOf(node) {
|
|
251
|
-
const hasDefault = node.caseBlock.clauses.some(
|
|
356
|
+
const hasDefault = node.caseBlock.clauses.some(ts4.isDefaultClause);
|
|
252
357
|
let flow = { through: hasDefault ? null : [], exit: null, jump: null };
|
|
253
358
|
let fallen = null;
|
|
254
359
|
for (const clause of node.caseBlock.clauses) {
|
|
@@ -303,21 +408,21 @@ class WritePath {
|
|
|
303
408
|
};
|
|
304
409
|
}
|
|
305
410
|
static #isFlowStatement(node) {
|
|
306
|
-
return
|
|
411
|
+
return ts4.isBlock(node) || ts4.isIfStatement(node) || ts4.isSwitchStatement(node) || ts4.isTryStatement(node) || ts4.isLabeledStatement(node) || ts4.isReturnStatement(node) || ts4.isThrowStatement(node) || ts4.isBreakStatement(node) || ts4.isContinueStatement(node) || ts4.isIterationStatement(node, false);
|
|
307
412
|
}
|
|
308
413
|
static #walksItems(node) {
|
|
309
414
|
if (!node)
|
|
310
415
|
return false;
|
|
311
|
-
if (
|
|
416
|
+
if (ts4.isCallExpression(node))
|
|
312
417
|
return true;
|
|
313
|
-
if (
|
|
418
|
+
if (ts4.isPropertyAccessExpression(node) && ["length", "size"].includes(node.name.text))
|
|
314
419
|
return true;
|
|
315
|
-
return !!
|
|
420
|
+
return !!ts4.forEachChild(node, (child) => WritePath.#walksItems(child) || undefined);
|
|
316
421
|
}
|
|
317
422
|
#busier = (a, b) => this.countOf(b) > this.countOf(a) ? b : a;
|
|
318
423
|
}
|
|
319
424
|
|
|
320
|
-
// pkgs/@akanjs/devkit/componentWriteChainScanner.ts
|
|
425
|
+
// pkgs/@akanjs/devkit/quality/componentWriteChainScanner.ts
|
|
321
426
|
class ComponentWriteChainScanner {
|
|
322
427
|
static #inlineCallers = new Set([
|
|
323
428
|
"map",
|
|
@@ -366,29 +471,29 @@ class ComponentWriteChainScanner {
|
|
|
366
471
|
const visit = (node) => {
|
|
367
472
|
if (ComponentWriteChainScanner.#isFunction(node) && node.body && !ComponentWriteChainScanner.#isInlineCallback(node))
|
|
368
473
|
bodies.push(node.body);
|
|
369
|
-
|
|
474
|
+
ts5.forEachChild(node, visit);
|
|
370
475
|
};
|
|
371
476
|
visit(component);
|
|
372
477
|
return bodies;
|
|
373
478
|
}
|
|
374
479
|
static #isFunction(node) {
|
|
375
|
-
return
|
|
480
|
+
return ts5.isArrowFunction(node) || ts5.isFunctionExpression(node) || ts5.isFunctionDeclaration(node) || ts5.isMethodDeclaration(node);
|
|
376
481
|
}
|
|
377
482
|
static #isInlineCallback(fn) {
|
|
378
483
|
const call = fn.parent;
|
|
379
|
-
return !!call &&
|
|
484
|
+
return !!call && ts5.isCallExpression(call) && call.arguments.some((arg) => arg === fn) && ts5.isPropertyAccessExpression(call.expression) && ComponentWriteChainScanner.#inlineCallers.has(call.expression.name.text);
|
|
380
485
|
}
|
|
381
486
|
static #actionOf(callee, stNames) {
|
|
382
|
-
if (!
|
|
487
|
+
if (!ts5.isPropertyAccessExpression(callee) || !ts5.isPropertyAccessExpression(callee.expression))
|
|
383
488
|
return null;
|
|
384
489
|
const { expression: st, name } = callee.expression;
|
|
385
|
-
return
|
|
490
|
+
return ts5.isIdentifier(st) && stNames.has(st.text) && name.text === "do" ? callee.name.text : null;
|
|
386
491
|
}
|
|
387
492
|
}
|
|
388
493
|
|
|
389
|
-
// pkgs/@akanjs/devkit/endpointReach.ts
|
|
494
|
+
// pkgs/@akanjs/devkit/quality/endpointReach.ts
|
|
390
495
|
import path from "path";
|
|
391
|
-
import
|
|
496
|
+
import ts6 from "typescript";
|
|
392
497
|
|
|
393
498
|
class EndpointReach {
|
|
394
499
|
static #requestBuilders = new Set(["endpoint", "slice"]);
|
|
@@ -397,9 +502,9 @@ class EndpointReach {
|
|
|
397
502
|
const methodsByService = new Map;
|
|
398
503
|
for (const { file, sourceFile } of serviceFiles) {
|
|
399
504
|
const methods = methodsByService.get(EndpointReach.serviceOf(file)) ?? new Map;
|
|
400
|
-
for (const cls of sourceFile.statements.filter(
|
|
505
|
+
for (const cls of sourceFile.statements.filter(ts6.isClassDeclaration))
|
|
401
506
|
for (const member of cls.members)
|
|
402
|
-
if (
|
|
507
|
+
if (ts6.isMethodDeclaration(member) && member.body && (ts6.isIdentifier(member.name) || ts6.isPrivateIdentifier(member.name)))
|
|
403
508
|
methods.set(member.name.text, member);
|
|
404
509
|
methodsByService.set(EndpointReach.serviceOf(file), methods);
|
|
405
510
|
}
|
|
@@ -412,9 +517,9 @@ class EndpointReach {
|
|
|
412
517
|
pending.push([service, method]);
|
|
413
518
|
};
|
|
414
519
|
for (const { sourceFile } of signalFiles)
|
|
415
|
-
for (const cls of sourceFile.statements.filter(
|
|
520
|
+
for (const cls of sourceFile.statements.filter(ts6.isClassDeclaration)) {
|
|
416
521
|
const base = cls.heritageClauses?.[0]?.types[0]?.expression;
|
|
417
|
-
if (base &&
|
|
522
|
+
if (base && ts6.isCallExpression(base) && ts6.isIdentifier(base.expression) && EndpointReach.#requestBuilders.has(base.expression.text))
|
|
418
523
|
EndpointReach.#serviceCallsIn(base, null).forEach(reach);
|
|
419
524
|
}
|
|
420
525
|
for (let next = pending.pop();next; next = pending.pop()) {
|
|
@@ -433,28 +538,28 @@ class EndpointReach {
|
|
|
433
538
|
static #serviceCallsIn(node, ownService) {
|
|
434
539
|
const calls = [];
|
|
435
540
|
const visit = (child) => {
|
|
436
|
-
if (
|
|
541
|
+
if (ts6.isCallExpression(child) && ts6.isPropertyAccessExpression(child.expression)) {
|
|
437
542
|
const { expression: owner, name } = child.expression;
|
|
438
|
-
if (owner.kind ===
|
|
543
|
+
if (owner.kind === ts6.SyntaxKind.ThisKeyword && ownService)
|
|
439
544
|
calls.push([ownService, name.text]);
|
|
440
|
-
else if (
|
|
545
|
+
else if (ts6.isPropertyAccessExpression(owner) && owner.expression.kind === ts6.SyntaxKind.ThisKeyword) {
|
|
441
546
|
const field = owner.name.text;
|
|
442
547
|
if (field.length > "Service".length && field.endsWith("Service"))
|
|
443
548
|
calls.push([field.slice(0, -"Service".length), name.text]);
|
|
444
549
|
}
|
|
445
550
|
}
|
|
446
|
-
|
|
551
|
+
ts6.forEachChild(child, visit);
|
|
447
552
|
};
|
|
448
553
|
visit(node);
|
|
449
554
|
return calls;
|
|
450
555
|
}
|
|
451
556
|
}
|
|
452
557
|
|
|
453
|
-
// pkgs/@akanjs/devkit/maintainabilityLimits.ts
|
|
558
|
+
// pkgs/@akanjs/devkit/quality/maintainabilityLimits.ts
|
|
454
559
|
import path3 from "path";
|
|
455
|
-
import
|
|
560
|
+
import ts7 from "typescript";
|
|
456
561
|
|
|
457
|
-
// pkgs/@akanjs/devkit/abstractDoc.ts
|
|
562
|
+
// pkgs/@akanjs/devkit/quality/abstractDoc.ts
|
|
458
563
|
import path2 from "path";
|
|
459
564
|
|
|
460
565
|
class AbstractDoc {
|
|
@@ -519,7 +624,7 @@ class AbstractDoc {
|
|
|
519
624
|
}
|
|
520
625
|
}
|
|
521
626
|
|
|
522
|
-
// pkgs/@akanjs/devkit/maintainabilityLimits.ts
|
|
627
|
+
// pkgs/@akanjs/devkit/quality/maintainabilityLimits.ts
|
|
523
628
|
class MaintainabilityLimits {
|
|
524
629
|
static fileMaxLines = {
|
|
525
630
|
".Template.tsx": 400,
|
|
@@ -539,6 +644,14 @@ class MaintainabilityLimits {
|
|
|
539
644
|
static packageFileMaxLines = 800;
|
|
540
645
|
static functionMaxLines = 150;
|
|
541
646
|
static classMaxMembers = 60;
|
|
647
|
+
static bareErrorRoots = new Map([
|
|
648
|
+
["akanjs", ["server/", "service/", "signal/"]]
|
|
649
|
+
]);
|
|
650
|
+
static repoOnlyRules = new Set(["akan.error.bare-error"]);
|
|
651
|
+
static holdsBareErrors(pkgName, pkgRelativePath) {
|
|
652
|
+
const roots = pkgName === null ? undefined : MaintainabilityLimits.bareErrorRoots.get(pkgName);
|
|
653
|
+
return (roots ?? []).some((root) => pkgRelativePath.startsWith(root));
|
|
654
|
+
}
|
|
542
655
|
static fileKindOf(sysRelativePath) {
|
|
543
656
|
const kinds = Object.keys(MaintainabilityLimits.#maxLinesByKind);
|
|
544
657
|
const suffix = kinds.find((kind) => sysRelativePath.endsWith(kind));
|
|
@@ -555,7 +668,7 @@ class MaintainabilityLimits {
|
|
|
555
668
|
static isReexportBarrel(file, content) {
|
|
556
669
|
if (path3.posix.basename(file) !== "index.ts")
|
|
557
670
|
return false;
|
|
558
|
-
return
|
|
671
|
+
return ts7.createSourceFile(file, content, ts7.ScriptTarget.Latest, false, ts7.ScriptKind.TS).statements.every((statement) => ts7.isExportDeclaration(statement));
|
|
559
672
|
}
|
|
560
673
|
static lineCountOf(content) {
|
|
561
674
|
return AbstractDoc.lineCountOf(content);
|
|
@@ -575,7 +688,7 @@ class MaintainabilityLimits {
|
|
|
575
688
|
}
|
|
576
689
|
}
|
|
577
690
|
|
|
578
|
-
// pkgs/@akanjs/devkit/maintainabilityReport.ts
|
|
691
|
+
// pkgs/@akanjs/devkit/quality/maintainabilityReport.ts
|
|
579
692
|
class MaintainabilityReport {
|
|
580
693
|
static #clientSplitFix = 'Split it, in this order: a mode/kind table `{ [kind in cnst.X["value"]]: \u2026 }` in place of mode flags, each entry a component of the module owning the data of that kind; an interaction hook in `webkit/use<X>.tsx` with its pure logic in `common/` (`akan workflow plan create-interaction`); the writes behind one endpoint (`akan workflow plan add-mutation`); last, a sub-concept in its own module (`lib/<sub>` or `lib/_<feature>`), never model-bound code moved into `ui/`.';
|
|
581
694
|
static #serverMarkupFix = "Move model-independent pieces into ui/ components and display logic onto Light<Model>.";
|
|
@@ -602,7 +715,9 @@ class MaintainabilityReport {
|
|
|
602
715
|
"akan.component.store-access": MaintainabilityReport.#clientSplitFix,
|
|
603
716
|
"akan.write.placement": "A server write leaves the browser through one store action, started by one module component. Move a `fetch.<mutation>` into a store action, and hand `ui/` and `webkit/` code the write as an `onX` prop or hook argument from the module's `Zone` or `Util`: they stay free of any one model, and an agent or another screen reaches the write through the store.",
|
|
604
717
|
"akan.service.call-in-loop": "Load the set once (`load<Model>Many(ids)`, one filter query) or write it once (`create<Model>Many(rows)`, one batch method), then loop in memory: a call per item is a round trip per item, so the endpoint slows as its input grows.",
|
|
605
|
-
"akan.
|
|
718
|
+
"akan.error.bare-error": "Construct an `AkanError` subclass from `akanjs/base` with a code the caller can branch on, and a `statusCode` when it answers a request: an existing class whose code fits, or a new one beside the code that fails; a class extending a built-in Error extends `AkanError` instead. A failure another process reported travels as itself. The package's total is what is held, so moving a bare Error between files passes and `akan lint` rewrites the entries.",
|
|
719
|
+
"akan.baseline.growth": "Restore the entry from the default branch, then split the file or move the writes instead: `akan lint` lowers an entry as the code shrinks and never raises one.",
|
|
720
|
+
staleTotal: "Run `akan verify <package>`, which lowers the section, and commit `akan.baseline.json` in this change: a recorded total above the code is room for a new failure anywhere. A bare `akan verify` covers only uncommitted files."
|
|
606
721
|
};
|
|
607
722
|
static #labels = {
|
|
608
723
|
"ui/": "ui/**",
|
|
@@ -617,7 +732,9 @@ class MaintainabilityReport {
|
|
|
617
732
|
"akan.component.store-access": "component or hook reaching the store often",
|
|
618
733
|
"akan.write.placement": "write sent outside a store action or module component",
|
|
619
734
|
"akan.service.call-in-loop": "service call per item",
|
|
620
|
-
"akan.
|
|
735
|
+
"akan.error.bare-error": "bare Error",
|
|
736
|
+
"akan.baseline.growth": "baseline entry",
|
|
737
|
+
staleTotal: "baseline total"
|
|
621
738
|
};
|
|
622
739
|
static #units = {
|
|
623
740
|
"akan.size.file": "lines",
|
|
@@ -629,7 +746,8 @@ class MaintainabilityReport {
|
|
|
629
746
|
"akan.store.root-write-chain": "writes",
|
|
630
747
|
"akan.component.write-chain": "writes",
|
|
631
748
|
"akan.write.placement": "writes",
|
|
632
|
-
"akan.service.call-in-loop": "calls per item"
|
|
749
|
+
"akan.service.call-in-loop": "calls per item",
|
|
750
|
+
"akan.error.bare-error": "bare Errors"
|
|
633
751
|
};
|
|
634
752
|
static describe(sysPath, failures, commands = {}) {
|
|
635
753
|
const groups = new Map;
|
|
@@ -665,11 +783,15 @@ class MaintainabilityReport {
|
|
|
665
783
|
}));
|
|
666
784
|
}
|
|
667
785
|
static #problemOf(failure) {
|
|
786
|
+
if (failure.kind === "staleTotal")
|
|
787
|
+
return `records ${failure.recorded} ${MaintainabilityReport.#units[failure.rule]} in all, above the ${failure.count} the code holds`;
|
|
668
788
|
if (failure.kind === "baselineGrowth") {
|
|
669
789
|
const entry = `entry "${failure.key}" under ${failure.debtRule}`;
|
|
670
790
|
const units = MaintainabilityReport.#units[failure.debtRule];
|
|
791
|
+
if (failure.key === MaintainabilityBaseline.totalKey)
|
|
792
|
+
return `${failure.debtRule} allows ${failure.count} ${units} in all, above the ${failure.committed ?? 0} ${failure.measured ? `the code at ${failure.reference} holds with no entry for its rule recorded there` : `at ${failure.reference}`}; the baseline may only shrink`;
|
|
671
793
|
if (failure.measured)
|
|
672
|
-
return failure.committed === undefined ? `${entry} is debt the code at ${failure.reference} does not hold, and with no
|
|
794
|
+
return failure.committed === undefined ? `${entry} is debt the code at ${failure.reference} does not hold, and with no entry for its rule recorded there the baseline may only shrink from that code` : `${entry} allows ${failure.count} ${units}, above the ${failure.committed} the code at ${failure.reference} holds with no entry for its rule recorded there; the baseline may only shrink`;
|
|
673
795
|
return failure.committed === undefined ? `${entry} is not in the baseline at ${failure.reference}, which may only shrink` : `${entry} allows ${failure.count} ${units}, above the ${failure.committed} at ${failure.reference}; the baseline may only shrink`;
|
|
674
796
|
}
|
|
675
797
|
const grown = failure.recorded === undefined ? "" : `, more than the ${failure.recorded} recorded`;
|
|
@@ -684,6 +806,10 @@ class MaintainabilityReport {
|
|
|
684
806
|
}
|
|
685
807
|
if (failure.kind === "writePlacement")
|
|
686
808
|
return `sends ${failure.writes.length} server write(s) from outside a store action or a module component: ${failure.writes.join(", ")}${grown}`;
|
|
809
|
+
if (failure.kind === "bareError") {
|
|
810
|
+
const plural = failure.lines.length === 1 ? "" : "s";
|
|
811
|
+
return `constructs or extends ${failure.lines.length} bare Error${plural}, on line${plural} ${failure.lines.join(", ")}${grown}, and the package's total grew`;
|
|
812
|
+
}
|
|
687
813
|
if (failure.kind === "loopCall")
|
|
688
814
|
return `service method ${failure.owner} calls once per item: ${failure.calls.join(", ")}${grown}`;
|
|
689
815
|
if (failure.kind === "classSize")
|
|
@@ -698,6 +824,8 @@ class MaintainabilityReport {
|
|
|
698
824
|
return /^use[A-Z]/.test(name) ? "hook" : "component";
|
|
699
825
|
}
|
|
700
826
|
static #fixKeyOf(sysPath, failure) {
|
|
827
|
+
if (failure.kind === "staleTotal")
|
|
828
|
+
return "staleTotal";
|
|
701
829
|
if (failure.rule !== "akan.size.file")
|
|
702
830
|
return failure.rule;
|
|
703
831
|
if (sysPath.startsWith("pkgs/"))
|
|
@@ -709,14 +837,14 @@ class MaintainabilityReport {
|
|
|
709
837
|
}
|
|
710
838
|
}
|
|
711
839
|
|
|
712
|
-
// pkgs/@akanjs/devkit/serviceLoopCallScanner.ts
|
|
713
|
-
import
|
|
840
|
+
// pkgs/@akanjs/devkit/quality/serviceLoopCallScanner.ts
|
|
841
|
+
import ts8 from "typescript";
|
|
714
842
|
class ServiceLoopCallScanner {
|
|
715
843
|
static #reachingField = /(?:Service|Model)$/;
|
|
716
844
|
static #generatedQuery = /^_*(?:get|load|list|find|pick|exists|count|insight|create|update|remove|search)[A-Z]/;
|
|
717
845
|
scan(sourceFile, answersCaller) {
|
|
718
|
-
return sourceFile.statements.filter(
|
|
719
|
-
const methods = cls.members.filter((member) =>
|
|
846
|
+
return sourceFile.statements.filter(ts8.isClassDeclaration).flatMap((cls) => {
|
|
847
|
+
const methods = cls.members.filter((member) => ts8.isMethodDeclaration(member) && !!member.body && (ts8.isIdentifier(member.name) || ts8.isPrivateIdentifier(member.name)));
|
|
720
848
|
const declared = new Set(methods.map((method) => method.name.text));
|
|
721
849
|
const reaching = ServiceLoopCallScanner.#reachingMethodsOf(methods, declared);
|
|
722
850
|
const reaches = (call) => ServiceLoopCallScanner.#reaches(call, declared, reaching);
|
|
@@ -726,14 +854,14 @@ class ServiceLoopCallScanner {
|
|
|
726
854
|
return [];
|
|
727
855
|
const calls = [];
|
|
728
856
|
const visit = (node, perItem) => {
|
|
729
|
-
if (perItem &&
|
|
857
|
+
if (perItem && ts8.isCallExpression(node) && reaches(node) && !(perItem === "callback" && ServiceLoopCallScanner.#isBatchedLoad(node, declared, ownModel)))
|
|
730
858
|
calls.push(node);
|
|
731
|
-
if (
|
|
859
|
+
if (ts8.isForOfStatement(node) || ts8.isForInStatement(node)) {
|
|
732
860
|
visit(node.expression, perItem);
|
|
733
861
|
visit(node.statement, "loop");
|
|
734
862
|
return;
|
|
735
863
|
}
|
|
736
|
-
|
|
864
|
+
ts8.forEachChild(node, (child) => visit(child, perItem === "loop" || !WritePath.isPerElementCallback(child) ? perItem : "callback"));
|
|
737
865
|
};
|
|
738
866
|
visit(method, false);
|
|
739
867
|
const first = calls[0];
|
|
@@ -762,10 +890,10 @@ class ServiceLoopCallScanner {
|
|
|
762
890
|
const visit = (node) => {
|
|
763
891
|
if (found)
|
|
764
892
|
return;
|
|
765
|
-
if (
|
|
893
|
+
if (ts8.isCallExpression(node) && ServiceLoopCallScanner.#reaches(node, declared, reaching))
|
|
766
894
|
found = true;
|
|
767
895
|
else
|
|
768
|
-
|
|
896
|
+
ts8.forEachChild(node, visit);
|
|
769
897
|
};
|
|
770
898
|
visit(method);
|
|
771
899
|
if (found) {
|
|
@@ -778,7 +906,7 @@ class ServiceLoopCallScanner {
|
|
|
778
906
|
}
|
|
779
907
|
static #isBatchedLoad(call, declared, ownModel) {
|
|
780
908
|
const callee = call.expression;
|
|
781
|
-
if (!
|
|
909
|
+
if (!ts8.isPropertyAccessExpression(callee))
|
|
782
910
|
return false;
|
|
783
911
|
const model = ServiceLoopCallScanner.#loadedModelOf(callee, declared, ownModel);
|
|
784
912
|
if (!model)
|
|
@@ -788,28 +916,28 @@ class ServiceLoopCallScanner {
|
|
|
788
916
|
}
|
|
789
917
|
static #loadedModelOf(callee, declared, ownModel) {
|
|
790
918
|
const owner = callee.expression;
|
|
791
|
-
if (owner.kind ===
|
|
919
|
+
if (owner.kind === ts8.SyntaxKind.ThisKeyword)
|
|
792
920
|
return declared.has(callee.name.text) ? null : ownModel;
|
|
793
|
-
if (!
|
|
921
|
+
if (!ts8.isPropertyAccessExpression(owner) || owner.expression.kind !== ts8.SyntaxKind.ThisKeyword)
|
|
794
922
|
return null;
|
|
795
923
|
return owner.name.text.match(/^(\w+)Model$/)?.[1] ?? null;
|
|
796
924
|
}
|
|
797
925
|
static #reaches(call, declared, reaching) {
|
|
798
926
|
const callee = call.expression;
|
|
799
|
-
if (!
|
|
927
|
+
if (!ts8.isPropertyAccessExpression(callee))
|
|
800
928
|
return false;
|
|
801
929
|
const owner = callee.expression;
|
|
802
|
-
if (owner.kind ===
|
|
930
|
+
if (owner.kind === ts8.SyntaxKind.ThisKeyword) {
|
|
803
931
|
const name = callee.name.text;
|
|
804
932
|
return declared.has(name) ? reaching.has(name) : ServiceLoopCallScanner.#generatedQuery.test(name);
|
|
805
933
|
}
|
|
806
|
-
return
|
|
934
|
+
return ts8.isPropertyAccessExpression(owner) && owner.expression.kind === ts8.SyntaxKind.ThisKeyword && ServiceLoopCallScanner.#reachingField.test(owner.name.text);
|
|
807
935
|
}
|
|
808
936
|
}
|
|
809
937
|
|
|
810
|
-
// pkgs/@akanjs/devkit/signalMutationIndex.ts
|
|
938
|
+
// pkgs/@akanjs/devkit/quality/signalMutationIndex.ts
|
|
811
939
|
import { modelNames } from "akanjs/common";
|
|
812
|
-
import
|
|
940
|
+
import ts9 from "typescript";
|
|
813
941
|
|
|
814
942
|
class SignalMutationIndex {
|
|
815
943
|
static #generatedArgCounts = [
|
|
@@ -819,7 +947,7 @@ class SignalMutationIndex {
|
|
|
819
947
|
["mergeModel", 2],
|
|
820
948
|
["addModelFiles", 2]
|
|
821
949
|
];
|
|
822
|
-
static #reader = createFactReader(
|
|
950
|
+
static #reader = createFactReader(ts9, createAst(ts9));
|
|
823
951
|
#shapesByOwner = new Map;
|
|
824
952
|
constructor(sourceFiles) {
|
|
825
953
|
for (const { file, sourceFile } of sourceFiles) {
|
|
@@ -867,9 +995,9 @@ class SignalMutationIndex {
|
|
|
867
995
|
}
|
|
868
996
|
}
|
|
869
997
|
|
|
870
|
-
// pkgs/@akanjs/devkit/storeSource.ts
|
|
998
|
+
// pkgs/@akanjs/devkit/quality/storeSource.ts
|
|
871
999
|
import { modelNames as modelNames2 } from "akanjs/common";
|
|
872
|
-
import
|
|
1000
|
+
import ts10 from "typescript";
|
|
873
1001
|
|
|
874
1002
|
class StoreSource {
|
|
875
1003
|
file;
|
|
@@ -894,7 +1022,7 @@ class StoreSource {
|
|
|
894
1022
|
this.file = file;
|
|
895
1023
|
this.#fetchNames = StoreSource.#fetchBindingsOf(sourceFile);
|
|
896
1024
|
for (const statement of sourceFile.statements) {
|
|
897
|
-
if (!
|
|
1025
|
+
if (!ts10.isClassDeclaration(statement) || !statement.name)
|
|
898
1026
|
continue;
|
|
899
1027
|
const refName = StoreSource.#refNameOf(statement);
|
|
900
1028
|
if (refName === undefined)
|
|
@@ -903,9 +1031,9 @@ class StoreSource {
|
|
|
903
1031
|
this.stores.push({ name: store, refName });
|
|
904
1032
|
const ownActions = new Set(refName ? StoreSource.generatedWritesOf(refName) : []);
|
|
905
1033
|
for (const member of statement.members) {
|
|
906
|
-
if (!
|
|
1034
|
+
if (!ts10.isMethodDeclaration(member) || !member.body)
|
|
907
1035
|
continue;
|
|
908
|
-
const isStatic = !!
|
|
1036
|
+
const isStatic = !!ts10.getModifiers(member)?.some(({ kind }) => kind === ts10.SyntaxKind.StaticKeyword);
|
|
909
1037
|
const name = member.name.getText(sourceFile);
|
|
910
1038
|
if (!isStatic)
|
|
911
1039
|
ownActions.add(name);
|
|
@@ -919,65 +1047,65 @@ class StoreSource {
|
|
|
919
1047
|
targetsIn(method) {
|
|
920
1048
|
const targets = [];
|
|
921
1049
|
const visit = (node) => {
|
|
922
|
-
const target =
|
|
1050
|
+
const target = ts10.isCallExpression(node) ? this.targetOf(method, node) : null;
|
|
923
1051
|
if (target)
|
|
924
1052
|
targets.push(target);
|
|
925
|
-
|
|
1053
|
+
ts10.forEachChild(node, visit);
|
|
926
1054
|
};
|
|
927
1055
|
visit(method.body);
|
|
928
1056
|
return targets;
|
|
929
1057
|
}
|
|
930
1058
|
targetOf(method, call) {
|
|
931
1059
|
const callee = call.expression;
|
|
932
|
-
if (!
|
|
1060
|
+
if (!ts10.isPropertyAccessExpression(callee) && !ts10.isElementAccessExpression(callee))
|
|
933
1061
|
return null;
|
|
934
|
-
const name =
|
|
1062
|
+
const name = ts10.isPropertyAccessExpression(callee) ? callee.name.text : ts10.isStringLiteralLike(callee.argumentExpression) ? callee.argumentExpression.text : null;
|
|
935
1063
|
if (name === null)
|
|
936
1064
|
return null;
|
|
937
1065
|
const receiver = StoreSource.#unwrap(callee.expression);
|
|
938
|
-
const isThis = receiver.kind ===
|
|
1066
|
+
const isThis = receiver.kind === ts10.SyntaxKind.ThisKeyword;
|
|
939
1067
|
if (isThis && method.isStatic)
|
|
940
1068
|
return { kind: "static", store: method.store, name };
|
|
941
|
-
if (!isThis && !
|
|
1069
|
+
if (!isThis && !ts10.isIdentifier(receiver))
|
|
942
1070
|
return null;
|
|
943
|
-
if (
|
|
1071
|
+
if (ts10.isIdentifier(receiver) && this.#fetchNames.has(receiver.text))
|
|
944
1072
|
return { kind: "fetch", name };
|
|
945
|
-
if (isThis ||
|
|
1073
|
+
if (isThis || ts10.isIdentifier(receiver) && this.#rootAliasesByMethod.get(method)?.has(receiver.text))
|
|
946
1074
|
return { kind: "action", name, isOwn: !!this.#ownActionsByStore.get(method.store)?.has(name) };
|
|
947
|
-
return
|
|
1075
|
+
return ts10.isIdentifier(receiver) ? { kind: "static", store: receiver.text, name } : null;
|
|
948
1076
|
}
|
|
949
1077
|
static #rootAliasesIn(method) {
|
|
950
1078
|
const aliases = new Set;
|
|
951
1079
|
const visit = (node) => {
|
|
952
|
-
if (
|
|
1080
|
+
if (ts10.isParameter(node) && ts10.isIdentifier(node.name) && StoreSource.#isRootStoreType(node.type))
|
|
953
1081
|
aliases.add(node.name.text);
|
|
954
|
-
if (
|
|
1082
|
+
if (ts10.isVariableDeclaration(node) && ts10.isIdentifier(node.name) && node.initializer && StoreSource.#unwrap(node.initializer).kind === ts10.SyntaxKind.ThisKeyword)
|
|
955
1083
|
aliases.add(node.name.text);
|
|
956
|
-
|
|
1084
|
+
ts10.forEachChild(node, visit);
|
|
957
1085
|
};
|
|
958
1086
|
visit(method);
|
|
959
1087
|
return aliases;
|
|
960
1088
|
}
|
|
961
1089
|
static #isRootStoreType(type) {
|
|
962
|
-
return !!type &&
|
|
1090
|
+
return !!type && ts10.isTypeReferenceNode(type) && ts10.isIdentifier(type.typeName) && type.typeName.text === "RootStore";
|
|
963
1091
|
}
|
|
964
1092
|
static #unwrap(expression) {
|
|
965
1093
|
let current = expression;
|
|
966
|
-
while (
|
|
1094
|
+
while (ts10.isParenthesizedExpression(current) || ts10.isAsExpression(current) || ts10.isTypeAssertionExpression(current) || ts10.isSatisfiesExpression(current) || ts10.isNonNullExpression(current))
|
|
967
1095
|
current = current.expression;
|
|
968
1096
|
return current;
|
|
969
1097
|
}
|
|
970
1098
|
static #refNameOf(statement) {
|
|
971
1099
|
for (const clause of statement.heritageClauses ?? []) {
|
|
972
|
-
if (clause.token !==
|
|
1100
|
+
if (clause.token !== ts10.SyntaxKind.ExtendsKeyword)
|
|
973
1101
|
continue;
|
|
974
1102
|
for (const { expression } of clause.types) {
|
|
975
|
-
if (!
|
|
1103
|
+
if (!ts10.isCallExpression(expression) || !ts10.isIdentifier(expression.expression))
|
|
976
1104
|
continue;
|
|
977
1105
|
if (expression.expression.text !== "store")
|
|
978
1106
|
continue;
|
|
979
1107
|
const sig = expression.arguments[0];
|
|
980
|
-
return sig &&
|
|
1108
|
+
return sig && ts10.isPropertyAccessExpression(sig) ? sig.name.text : null;
|
|
981
1109
|
}
|
|
982
1110
|
}
|
|
983
1111
|
return;
|
|
@@ -985,10 +1113,10 @@ class StoreSource {
|
|
|
985
1113
|
static #fetchBindingsOf(sourceFile) {
|
|
986
1114
|
const names = new Set;
|
|
987
1115
|
for (const statement of sourceFile.statements) {
|
|
988
|
-
if (!
|
|
1116
|
+
if (!ts10.isImportDeclaration(statement) || statement.importClause?.isTypeOnly)
|
|
989
1117
|
continue;
|
|
990
1118
|
const bindings = statement.importClause?.namedBindings;
|
|
991
|
-
if (!bindings || !
|
|
1119
|
+
if (!bindings || !ts10.isNamedImports(bindings))
|
|
992
1120
|
continue;
|
|
993
1121
|
for (const element of bindings.elements)
|
|
994
1122
|
if (!element.isTypeOnly && (element.propertyName ?? element.name).text === "fetch")
|
|
@@ -998,7 +1126,7 @@ class StoreSource {
|
|
|
998
1126
|
}
|
|
999
1127
|
}
|
|
1000
1128
|
|
|
1001
|
-
// pkgs/@akanjs/devkit/storeWriteScanner.ts
|
|
1129
|
+
// pkgs/@akanjs/devkit/quality/storeWriteScanner.ts
|
|
1002
1130
|
class StoreWriteScanner {
|
|
1003
1131
|
#index;
|
|
1004
1132
|
constructor(index) {
|
|
@@ -1035,8 +1163,8 @@ class StoreWriteScanner {
|
|
|
1035
1163
|
}
|
|
1036
1164
|
}
|
|
1037
1165
|
|
|
1038
|
-
// pkgs/@akanjs/devkit/structureScanner.ts
|
|
1039
|
-
import
|
|
1166
|
+
// pkgs/@akanjs/devkit/quality/structureScanner.ts
|
|
1167
|
+
import ts11 from "typescript";
|
|
1040
1168
|
|
|
1041
1169
|
class StructureScanner {
|
|
1042
1170
|
measure(sourceFile) {
|
|
@@ -1044,14 +1172,14 @@ class StructureScanner {
|
|
|
1044
1172
|
const classes = [];
|
|
1045
1173
|
const lineOf = (pos) => sourceFile.getLineAndCharacterOfPosition(pos).line + 1;
|
|
1046
1174
|
const visit = (node, owners) => {
|
|
1047
|
-
if (
|
|
1175
|
+
if (ts11.isClassDeclaration(node) || ts11.isClassExpression(node)) {
|
|
1048
1176
|
const name = StructureScanner.#classNameOf(node);
|
|
1049
1177
|
classes.push({
|
|
1050
1178
|
name: [...owners, name].join("."),
|
|
1051
1179
|
line: lineOf(node.getStart(sourceFile)),
|
|
1052
1180
|
memberCount: StructureScanner.#memberCountOf(node)
|
|
1053
1181
|
});
|
|
1054
|
-
|
|
1182
|
+
ts11.forEachChild(node, (child) => visit(child, [...owners, name]));
|
|
1055
1183
|
return;
|
|
1056
1184
|
}
|
|
1057
1185
|
if (StructureScanner.#isFunction(node)) {
|
|
@@ -1062,28 +1190,28 @@ class StructureScanner {
|
|
|
1062
1190
|
line,
|
|
1063
1191
|
lineCount: lineOf(node.getEnd()) - line + 1
|
|
1064
1192
|
});
|
|
1065
|
-
|
|
1193
|
+
ts11.forEachChild(node, (child) => visit(child, [...owners, name]));
|
|
1066
1194
|
return;
|
|
1067
1195
|
}
|
|
1068
|
-
if (
|
|
1196
|
+
if (ts11.isObjectLiteralExpression(node)) {
|
|
1069
1197
|
const name = StructureScanner.#boundNameOf(node);
|
|
1070
|
-
|
|
1198
|
+
ts11.forEachChild(node, (child) => visit(child, name === "<anonymous>" ? owners : [...owners, name]));
|
|
1071
1199
|
return;
|
|
1072
1200
|
}
|
|
1073
|
-
|
|
1201
|
+
ts11.forEachChild(node, (child) => visit(child, owners));
|
|
1074
1202
|
};
|
|
1075
|
-
|
|
1203
|
+
ts11.forEachChild(sourceFile, (child) => visit(child, []));
|
|
1076
1204
|
return { functions, classes };
|
|
1077
1205
|
}
|
|
1078
1206
|
static #memberCountOf(node) {
|
|
1079
1207
|
const methods = new Set;
|
|
1080
1208
|
return node.members.filter((member) => {
|
|
1081
|
-
if (
|
|
1209
|
+
if (ts11.isSemicolonClassElement(member) || ts11.isIndexSignatureDeclaration(member) || ts11.isClassStaticBlockDeclaration(member))
|
|
1082
1210
|
return false;
|
|
1083
|
-
if (!
|
|
1211
|
+
if (!ts11.isMethodDeclaration(member) && !ts11.isConstructorDeclaration(member))
|
|
1084
1212
|
return true;
|
|
1085
|
-
const isStatic =
|
|
1086
|
-
const key = `${isStatic ? "static " : ""}${
|
|
1213
|
+
const isStatic = ts11.getModifiers(member)?.some((modifier) => modifier.kind === ts11.SyntaxKind.StaticKeyword);
|
|
1214
|
+
const key = `${isStatic ? "static " : ""}${ts11.isConstructorDeclaration(member) ? "constructor" : StructureScanner.#textOf(member.name)}`;
|
|
1087
1215
|
if (methods.has(key))
|
|
1088
1216
|
return false;
|
|
1089
1217
|
methods.add(key);
|
|
@@ -1091,64 +1219,64 @@ class StructureScanner {
|
|
|
1091
1219
|
}).length;
|
|
1092
1220
|
}
|
|
1093
1221
|
static #isFunction(node) {
|
|
1094
|
-
return (
|
|
1222
|
+
return (ts11.isFunctionDeclaration(node) || ts11.isMethodDeclaration(node) || ts11.isConstructorDeclaration(node) || ts11.isGetAccessorDeclaration(node) || ts11.isSetAccessorDeclaration(node) || ts11.isFunctionExpression(node) || ts11.isArrowFunction(node)) && node.body !== undefined;
|
|
1095
1223
|
}
|
|
1096
1224
|
static #functionNameOf(node) {
|
|
1097
|
-
if (
|
|
1225
|
+
if (ts11.isConstructorDeclaration(node))
|
|
1098
1226
|
return "constructor";
|
|
1099
|
-
if (
|
|
1227
|
+
if (ts11.isGetAccessorDeclaration(node))
|
|
1100
1228
|
return `get ${StructureScanner.#textOf(node.name)}`;
|
|
1101
|
-
if (
|
|
1229
|
+
if (ts11.isSetAccessorDeclaration(node))
|
|
1102
1230
|
return `set ${StructureScanner.#textOf(node.name)}`;
|
|
1103
1231
|
if (node.name)
|
|
1104
1232
|
return StructureScanner.#textOf(node.name);
|
|
1105
|
-
return
|
|
1233
|
+
return ts11.isFunctionDeclaration(node) ? "default" : StructureScanner.#boundNameOf(node);
|
|
1106
1234
|
}
|
|
1107
1235
|
static #classNameOf(node) {
|
|
1108
1236
|
if (node.name)
|
|
1109
1237
|
return node.name.text;
|
|
1110
|
-
return
|
|
1238
|
+
return ts11.isClassDeclaration(node) ? "default" : StructureScanner.#boundNameOf(node);
|
|
1111
1239
|
}
|
|
1112
1240
|
static #boundNameOf(node) {
|
|
1113
1241
|
let current = StructureScanner.#outerOf(node);
|
|
1114
1242
|
let call = null;
|
|
1115
|
-
while (
|
|
1243
|
+
while (ts11.isCallExpression(current.parent) || ts11.isNewExpression(current.parent)) {
|
|
1116
1244
|
const callee = current.parent.expression;
|
|
1117
1245
|
if (current === callee)
|
|
1118
1246
|
break;
|
|
1119
|
-
call ??= `${
|
|
1247
|
+
call ??= `${ts11.isPropertyAccessExpression(callee) ? callee.name.text : ts11.isIdentifier(callee) ? callee.text : "call"}()`;
|
|
1120
1248
|
current = StructureScanner.#outerOf(current.parent);
|
|
1121
1249
|
}
|
|
1122
1250
|
const { parent } = current;
|
|
1123
|
-
if ((
|
|
1251
|
+
if ((ts11.isVariableDeclaration(parent) || ts11.isPropertyAssignment(parent) || ts11.isPropertyDeclaration(parent) || ts11.isParameter(parent) || ts11.isBindingElement(parent)) && parent.name && !ts11.isObjectBindingPattern(parent.name) && !ts11.isArrayBindingPattern(parent.name))
|
|
1124
1252
|
return StructureScanner.#textOf(parent.name);
|
|
1125
|
-
if (
|
|
1126
|
-
return
|
|
1127
|
-
if (
|
|
1253
|
+
if (ts11.isBinaryExpression(parent) && parent.operatorToken.kind === ts11.SyntaxKind.EqualsToken)
|
|
1254
|
+
return ts11.isPropertyAccessExpression(parent.left) ? parent.left.name.text : ts11.isIdentifier(parent.left) ? parent.left.text : "assigned";
|
|
1255
|
+
if (ts11.isExportAssignment(parent))
|
|
1128
1256
|
return "default";
|
|
1129
|
-
if (
|
|
1130
|
-
return
|
|
1257
|
+
if (ts11.isJsxExpression(parent))
|
|
1258
|
+
return ts11.isJsxAttribute(parent.parent) ? ts11.isIdentifier(parent.parent.name) ? parent.parent.name.text : parent.parent.name.getText() : "children";
|
|
1131
1259
|
return call ?? "<anonymous>";
|
|
1132
1260
|
}
|
|
1133
1261
|
static #outerOf(node) {
|
|
1134
1262
|
let current = node;
|
|
1135
|
-
while (
|
|
1263
|
+
while (ts11.isParenthesizedExpression(current.parent) || ts11.isAsExpression(current.parent) || ts11.isSatisfiesExpression(current.parent) || ts11.isNonNullExpression(current.parent) || ts11.isTypeAssertionExpression(current.parent) || ts11.isPropertyAccessExpression(current.parent) && current.parent.expression === current || ts11.isCallExpression(current.parent) && current.parent.expression === current)
|
|
1136
1264
|
current = current.parent;
|
|
1137
1265
|
return current;
|
|
1138
1266
|
}
|
|
1139
1267
|
static #textOf(name) {
|
|
1140
|
-
if (
|
|
1268
|
+
if (ts11.isIdentifier(name) || ts11.isPrivateIdentifier(name) || ts11.isStringLiteral(name))
|
|
1141
1269
|
return name.text;
|
|
1142
|
-
if (
|
|
1270
|
+
if (ts11.isNumericLiteral(name) || ts11.isNoSubstitutionTemplateLiteral(name))
|
|
1143
1271
|
return name.text;
|
|
1144
|
-
if (
|
|
1272
|
+
if (ts11.isComputedPropertyName(name))
|
|
1145
1273
|
return `[${name.expression.getText()}]`;
|
|
1146
1274
|
return "<pattern>";
|
|
1147
1275
|
}
|
|
1148
1276
|
}
|
|
1149
1277
|
|
|
1150
|
-
// pkgs/@akanjs/devkit/writePlacementScanner.ts
|
|
1151
|
-
import
|
|
1278
|
+
// pkgs/@akanjs/devkit/quality/writePlacementScanner.ts
|
|
1279
|
+
import ts12 from "typescript";
|
|
1152
1280
|
class WritePlacementScanner {
|
|
1153
1281
|
#index;
|
|
1154
1282
|
constructor(index) {
|
|
@@ -1161,9 +1289,9 @@ class WritePlacementScanner {
|
|
|
1161
1289
|
return null;
|
|
1162
1290
|
const sites = [];
|
|
1163
1291
|
const visit = (node) => {
|
|
1164
|
-
if (
|
|
1292
|
+
if (ts12.isPropertyAccessExpression(node) && this.#isWrite(node, workspaceFile, fetchNames, stNames))
|
|
1165
1293
|
sites.push(node);
|
|
1166
|
-
|
|
1294
|
+
ts12.forEachChild(node, visit);
|
|
1167
1295
|
};
|
|
1168
1296
|
visit(sourceFile);
|
|
1169
1297
|
const first = sites[0];
|
|
@@ -1176,13 +1304,13 @@ class WritePlacementScanner {
|
|
|
1176
1304
|
}
|
|
1177
1305
|
#isWrite(access, workspaceFile, fetchNames, stNames) {
|
|
1178
1306
|
const owner = access.expression;
|
|
1179
|
-
if (
|
|
1307
|
+
if (ts12.isIdentifier(owner) && fetchNames.has(owner.text))
|
|
1180
1308
|
return this.#index.isMutation(workspaceFile, access.name.text);
|
|
1181
|
-
return
|
|
1309
|
+
return ts12.isPropertyAccessExpression(owner) && owner.name.text === "do" && ts12.isIdentifier(owner.expression) && stNames.has(owner.expression.text) && this.#index.isWritingAction(access.name.text);
|
|
1182
1310
|
}
|
|
1183
1311
|
}
|
|
1184
1312
|
|
|
1185
|
-
// pkgs/@akanjs/devkit/writingActionIndex.ts
|
|
1313
|
+
// pkgs/@akanjs/devkit/quality/writingActionIndex.ts
|
|
1186
1314
|
class WritingActionIndex {
|
|
1187
1315
|
#mutations;
|
|
1188
1316
|
#actions = new Set;
|
|
@@ -1237,7 +1365,7 @@ class WritingActionIndex {
|
|
|
1237
1365
|
}
|
|
1238
1366
|
}
|
|
1239
1367
|
|
|
1240
|
-
// pkgs/@akanjs/devkit/maintainabilityContract.ts
|
|
1368
|
+
// pkgs/@akanjs/devkit/quality/maintainabilityContract.ts
|
|
1241
1369
|
class MaintainabilityContract {
|
|
1242
1370
|
static ruleIds = [
|
|
1243
1371
|
"akan.size.file",
|
|
@@ -1250,6 +1378,7 @@ class MaintainabilityContract {
|
|
|
1250
1378
|
"akan.component.store-access",
|
|
1251
1379
|
"akan.write.placement",
|
|
1252
1380
|
"akan.service.call-in-loop",
|
|
1381
|
+
"akan.error.bare-error",
|
|
1253
1382
|
"akan.baseline.growth"
|
|
1254
1383
|
];
|
|
1255
1384
|
static #measuredFiles = "{lib,ui,webkit,srvkit,common,plugin}/**/*.{ts,tsx,md}";
|
|
@@ -1289,28 +1418,44 @@ class MaintainabilityContract {
|
|
|
1289
1418
|
this.#readBaseline(),
|
|
1290
1419
|
this.#readReferenceBaseline()
|
|
1291
1420
|
]);
|
|
1292
|
-
const
|
|
1421
|
+
const moves = await this.#movesSince(reference.ref);
|
|
1422
|
+
const onDisk = existing === null ? new MaintainabilityBaseline : MaintainabilityBaseline.parse(existing, this.baselinePath);
|
|
1423
|
+
const baseline = fix ? onDisk.movedBy(moves) : onDisk;
|
|
1293
1424
|
const tightened = baseline.tightenedBy(violations);
|
|
1294
1425
|
if (fix && existing !== null)
|
|
1295
|
-
await this.#tighten(
|
|
1296
|
-
const failures = violations.filter((violation) => !baseline.allows(violation)).map((violation) => {
|
|
1297
|
-
const recorded = baseline.recordedOf(violation);
|
|
1298
|
-
return recorded === undefined ? violation : { ...violation, recorded };
|
|
1299
|
-
});
|
|
1426
|
+
await this.#tighten(onDisk, tightened);
|
|
1300
1427
|
const working = fix ? tightened : baseline;
|
|
1428
|
+
const lines = (await this.#readBaseline() ?? "").split(/\r?\n/);
|
|
1429
|
+
const failures = [
|
|
1430
|
+
...working.staleTotals(violations).map(({ rule, count, recorded }) => ({
|
|
1431
|
+
kind: "staleTotal",
|
|
1432
|
+
rule,
|
|
1433
|
+
key: MaintainabilityBaseline.totalKey,
|
|
1434
|
+
file: MaintainabilityBaseline.fileName,
|
|
1435
|
+
line: MaintainabilityContract.#lineOf(lines, rule, MaintainabilityBaseline.totalKey),
|
|
1436
|
+
count,
|
|
1437
|
+
recorded
|
|
1438
|
+
})),
|
|
1439
|
+
...baseline.unallowed(violations).map((violation) => {
|
|
1440
|
+
const recorded = baseline.recordedOf(violation);
|
|
1441
|
+
return recorded === undefined ? violation : { ...violation, recorded };
|
|
1442
|
+
})
|
|
1443
|
+
];
|
|
1301
1444
|
const source = `${reference.label}:${this.sysPath}/${MaintainabilityBaseline.fileName}`;
|
|
1302
|
-
const
|
|
1303
|
-
|
|
1445
|
+
const recorded = reference.text !== null ? MaintainabilityBaseline.parse(reference.text, source, { lenient: true }) : null;
|
|
1446
|
+
const unrecorded = new Set(working.rulesOutside(recorded));
|
|
1447
|
+
const measured = unrecorded.size ? await this.#measuredAt(reference.ref) : null;
|
|
1448
|
+
if (recorded === null && measured === null)
|
|
1304
1449
|
return failures;
|
|
1305
|
-
const
|
|
1306
|
-
const growths = working.grownFrom(committed).map(({ rule, ...growth }) => ({
|
|
1450
|
+
const committed = (recorded ?? new MaintainabilityBaseline).withSectionsOf(measured, unrecorded).movedBy(moves);
|
|
1451
|
+
const growths = (fix ? working : working.movedBy(moves)).grownFrom(committed).map(({ rule, ...growth }) => ({
|
|
1307
1452
|
kind: "baselineGrowth",
|
|
1308
1453
|
rule: "akan.baseline.growth",
|
|
1309
1454
|
file: MaintainabilityBaseline.fileName,
|
|
1310
1455
|
line: MaintainabilityContract.#lineOf(lines, rule, growth.key),
|
|
1311
1456
|
debtRule: rule,
|
|
1312
1457
|
reference: reference.label,
|
|
1313
|
-
...
|
|
1458
|
+
...unrecorded.has(rule) ? { measured: true } : {},
|
|
1314
1459
|
...growth
|
|
1315
1460
|
})).sort((a, b) => a.line - b.line);
|
|
1316
1461
|
return [...growths, ...failures];
|
|
@@ -1332,14 +1477,25 @@ class MaintainabilityContract {
|
|
|
1332
1477
|
}
|
|
1333
1478
|
async#measurePackage() {
|
|
1334
1479
|
const files = (await this.#packageFiles()).filter(MaintainabilityLimits.isPackageSource);
|
|
1480
|
+
const packageName = await this.#packageName();
|
|
1335
1481
|
const violations = await Promise.all(files.map(async (file) => {
|
|
1336
1482
|
const workspaceFile = `${this.sysPath}/${file}`;
|
|
1337
1483
|
const content = await this.#read(workspaceFile);
|
|
1338
|
-
return MaintainabilityContract.#measurePackageFile(file, this.#sourceOf(workspaceFile, content).sourceFile);
|
|
1484
|
+
return MaintainabilityContract.#measurePackageFile(file, this.#sourceOf(workspaceFile, content).sourceFile, MaintainabilityLimits.holdsBareErrors(packageName, file));
|
|
1339
1485
|
}));
|
|
1340
1486
|
return violations.flat();
|
|
1341
1487
|
}
|
|
1342
|
-
|
|
1488
|
+
async#packageName() {
|
|
1489
|
+
const manifest = `${this.sysPath}/package.json`;
|
|
1490
|
+
const text = this.#tree ? this.#tree.get(manifest) : existsSync(path4.join(this.#workspaceRoot, manifest)) ? await this.#read(manifest) : undefined;
|
|
1491
|
+
try {
|
|
1492
|
+
const { name } = JSON.parse(text ?? "{}");
|
|
1493
|
+
return typeof name === "string" ? name : null;
|
|
1494
|
+
} catch {
|
|
1495
|
+
return null;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
static #measurePackageFile(file, sourceFile, holdsBareErrors) {
|
|
1343
1499
|
const violations = [];
|
|
1344
1500
|
const maxLines = MaintainabilityLimits.packageFileMaxLines;
|
|
1345
1501
|
const lineCount = MaintainabilityLimits.lineCountOf(sourceFile.text);
|
|
@@ -1370,6 +1526,16 @@ class MaintainabilityContract {
|
|
|
1370
1526
|
memberCount,
|
|
1371
1527
|
maxMembers: MaintainabilityLimits.classMaxMembers
|
|
1372
1528
|
});
|
|
1529
|
+
const bareErrors = holdsBareErrors ? new BareErrorScanner().lines(sourceFile) : [];
|
|
1530
|
+
if (bareErrors.length)
|
|
1531
|
+
violations.push({
|
|
1532
|
+
kind: "bareError",
|
|
1533
|
+
rule: "akan.error.bare-error",
|
|
1534
|
+
key: file,
|
|
1535
|
+
file,
|
|
1536
|
+
line: bareErrors[0] ?? 1,
|
|
1537
|
+
lines: bareErrors
|
|
1538
|
+
});
|
|
1373
1539
|
return violations;
|
|
1374
1540
|
}
|
|
1375
1541
|
static #numbered(items) {
|
|
@@ -1478,12 +1644,12 @@ class MaintainabilityContract {
|
|
|
1478
1644
|
return await Promise.all(files.flat().map(async (file) => this.#sourceOf(file, await this.#read(file))));
|
|
1479
1645
|
}
|
|
1480
1646
|
#sourceOf(file, content) {
|
|
1481
|
-
const scriptKind = file.endsWith(".tsx") ?
|
|
1647
|
+
const scriptKind = file.endsWith(".tsx") ? ts13.ScriptKind.TSX : ts13.ScriptKind.TS;
|
|
1482
1648
|
return {
|
|
1483
1649
|
file,
|
|
1484
1650
|
absolutePath: path4.join(this.#workspaceRoot, file),
|
|
1485
1651
|
content,
|
|
1486
|
-
sourceFile:
|
|
1652
|
+
sourceFile: ts13.createSourceFile(file, content, ts13.ScriptTarget.Latest, true, scriptKind)
|
|
1487
1653
|
};
|
|
1488
1654
|
}
|
|
1489
1655
|
async#readBaseline() {
|
|
@@ -1499,7 +1665,7 @@ class MaintainabilityContract {
|
|
|
1499
1665
|
return null;
|
|
1500
1666
|
const roots = [this.sysPath, ...this.#libNames.map((libName) => `libs/${libName}`)];
|
|
1501
1667
|
const contract = new MaintainabilityContract(this.#workspaceRoot, this.#scope, this.#libNames);
|
|
1502
|
-
contract.#tree = await new GitRevision(this.#workspaceRoot).filesAt(ref, (file) => /\.(tsx?|md)$/.test(file)
|
|
1668
|
+
contract.#tree = await new GitRevision(this.#workspaceRoot).filesAt(ref, (file) => /\.(tsx?|md)$/.test(file) || file === `${this.sysPath}/package.json`, roots);
|
|
1503
1669
|
return MaintainabilityBaseline.of(await contract.measure());
|
|
1504
1670
|
}
|
|
1505
1671
|
async#referenceRef() {
|
|
@@ -1515,12 +1681,58 @@ class MaintainabilityContract {
|
|
|
1515
1681
|
throw new Error(MaintainabilityContract.#missingHistory(this.sysPath, "this is a shallow clone"));
|
|
1516
1682
|
return "HEAD";
|
|
1517
1683
|
}
|
|
1684
|
+
async#movesSince(ref) {
|
|
1685
|
+
const staged = await this.#stagedScope();
|
|
1686
|
+
try {
|
|
1687
|
+
const diff = ["diff", ...staged ? ["--cached"] : [], "--relative", "--name-status", "-z", "-M", ref];
|
|
1688
|
+
const fields = (await this.#git([...diff, "--", this.sysPath], staged?.env))?.split("\x00") ?? [];
|
|
1689
|
+
const prefix = `${this.sysPath}/`;
|
|
1690
|
+
const moves = new Map;
|
|
1691
|
+
for (let idx = 0;idx < fields.length; idx += fields[idx]?.startsWith("R") ? 3 : 2) {
|
|
1692
|
+
const [from, to] = [fields[idx + 1], fields[idx + 2]];
|
|
1693
|
+
if (!fields[idx]?.startsWith("R") || !from?.startsWith(prefix) || !to?.startsWith(prefix))
|
|
1694
|
+
continue;
|
|
1695
|
+
moves.set(from.slice(prefix.length), to.slice(prefix.length));
|
|
1696
|
+
}
|
|
1697
|
+
return moves;
|
|
1698
|
+
} finally {
|
|
1699
|
+
if (staged)
|
|
1700
|
+
await rm(staged.dir, { recursive: true, force: true });
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
async#stagedScope() {
|
|
1704
|
+
const indexPath = (await this.#git(["rev-parse", "--git-path", "index"]))?.trim();
|
|
1705
|
+
const untracked = (await this.#git(["ls-files", "-o", "--exclude-standard", "-z", "--", this.sysPath]))?.split("\x00").filter((file) => /\.(tsx?|md)$/.test(file));
|
|
1706
|
+
if (!indexPath || !untracked)
|
|
1707
|
+
return null;
|
|
1708
|
+
const dir = await mkdtemp(path4.join(tmpdir(), "akan-moves-")).catch(() => null);
|
|
1709
|
+
if (!dir)
|
|
1710
|
+
return null;
|
|
1711
|
+
const env = { GIT_INDEX_FILE: path4.join(dir, "index") };
|
|
1712
|
+
const listPath = path4.join(dir, "untracked");
|
|
1713
|
+
try {
|
|
1714
|
+
const indexFile = path4.resolve(this.#workspaceRoot, indexPath);
|
|
1715
|
+
if (existsSync(indexFile))
|
|
1716
|
+
await copyFile(indexFile, env.GIT_INDEX_FILE);
|
|
1717
|
+
await writeFile(listPath, untracked.join("\x00"));
|
|
1718
|
+
const added = await this.#git(["add", "-u", "--", this.sysPath], env) !== null && (!untracked.length || await this.#git(["add", "--pathspec-from-file", listPath, "--pathspec-file-nul"], env) !== null);
|
|
1719
|
+
if (added)
|
|
1720
|
+
return { dir, env };
|
|
1721
|
+
} catch {}
|
|
1722
|
+
await rm(dir, { recursive: true, force: true });
|
|
1723
|
+
return null;
|
|
1724
|
+
}
|
|
1518
1725
|
static #missingHistory(sysPath, cause) {
|
|
1519
1726
|
return `${sysPath}/${MaintainabilityBaseline.fileName} is compared with its copy where this branch forked from the default branch, ` + `but ${cause}. Fetch the default branch with its history (in GitHub Actions, actions/checkout with fetch-depth: 0).`;
|
|
1520
1727
|
}
|
|
1521
|
-
async#git(args) {
|
|
1728
|
+
async#git(args, env = {}) {
|
|
1522
1729
|
try {
|
|
1523
|
-
const proc = Bun.spawn(["git", ...args], {
|
|
1730
|
+
const proc = Bun.spawn(["git", ...args], {
|
|
1731
|
+
cwd: this.#workspaceRoot,
|
|
1732
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0", ...env },
|
|
1733
|
+
stdout: "pipe",
|
|
1734
|
+
stderr: "ignore"
|
|
1735
|
+
});
|
|
1524
1736
|
const [text, exitCode] = await Promise.all([new Response(proc.stdout).text(), proc.exited]);
|
|
1525
1737
|
return exitCode === 0 ? text : null;
|
|
1526
1738
|
} catch {
|
|
@@ -1544,6 +1756,8 @@ class MaintainabilityContract {
|
|
|
1544
1756
|
}
|
|
1545
1757
|
static #lineOf(lines, rule, key) {
|
|
1546
1758
|
const from = Math.max(lines.findIndex((line) => line.includes(`${JSON.stringify(rule)}:`)), 0);
|
|
1759
|
+
if (key === MaintainabilityBaseline.totalKey)
|
|
1760
|
+
return from + 1;
|
|
1547
1761
|
const idx = lines.findIndex((line, lineIdx) => lineIdx >= from && line.includes(`${JSON.stringify(key)}:`));
|
|
1548
1762
|
return Math.max(idx + 1, 1);
|
|
1549
1763
|
}
|
|
@@ -1574,6 +1788,7 @@ class MaintainabilityPaths {
|
|
|
1574
1788
|
"akan.size.function",
|
|
1575
1789
|
"akan.size.class",
|
|
1576
1790
|
"akan.service.call-in-loop",
|
|
1791
|
+
"akan.error.bare-error",
|
|
1577
1792
|
"akan.baseline.growth"
|
|
1578
1793
|
]);
|
|
1579
1794
|
#specs;
|
|
@@ -1833,7 +2048,7 @@ class WorkspaceRunner extends runner("workspace") {
|
|
|
1833
2048
|
() => this.#enforceAgentsIndex(exec)
|
|
1834
2049
|
])
|
|
1835
2050
|
await gate().catch((error) => messages.push(error instanceof Error ? error.message : String(error)));
|
|
1836
|
-
if (!(exec instanceof SysExecutor) && !(exec instanceof
|
|
2051
|
+
if (!(exec instanceof SysExecutor) && !(exec instanceof PkgExecutor2))
|
|
1837
2052
|
return { messages, maintainability: [] };
|
|
1838
2053
|
const contract = await this.maintainabilityContractOf(exec);
|
|
1839
2054
|
const failures = await contract.enforce({ fix });
|
|
@@ -1841,7 +2056,7 @@ class WorkspaceRunner extends runner("workspace") {
|
|
|
1841
2056
|
return { messages, maintainability };
|
|
1842
2057
|
}
|
|
1843
2058
|
async maintainabilityContractOf(exec) {
|
|
1844
|
-
if (exec instanceof
|
|
2059
|
+
if (exec instanceof PkgExecutor2)
|
|
1845
2060
|
return new MaintainabilityContract(exec.workspace.workspaceRoot, { type: "pkg", name: exec.name });
|
|
1846
2061
|
const libNames = new Set;
|
|
1847
2062
|
const visit = async (sys) => {
|
|
@@ -1849,7 +2064,7 @@ class WorkspaceRunner extends runner("workspace") {
|
|
|
1849
2064
|
if (libNames.has(libName))
|
|
1850
2065
|
continue;
|
|
1851
2066
|
libNames.add(libName);
|
|
1852
|
-
await visit(
|
|
2067
|
+
await visit(LibExecutor2.from(exec, libName));
|
|
1853
2068
|
}
|
|
1854
2069
|
};
|
|
1855
2070
|
await visit(exec);
|
|
@@ -1879,7 +2094,7 @@ class WorkspaceRunner extends runner("workspace") {
|
|
|
1879
2094
|
throw new Error(`[agentsIndex] The recipe index in ${scope.type}s/${scope.name}/AGENTS.md is stale: it differs from the recipe ` + `sources. Run \`akan sync ${scope.name}\` to regenerate it.`);
|
|
1880
2095
|
}
|
|
1881
2096
|
async#enforceMaintainability(exec, fix) {
|
|
1882
|
-
if (!(exec instanceof SysExecutor) && !(exec instanceof
|
|
2097
|
+
if (!(exec instanceof SysExecutor) && !(exec instanceof PkgExecutor2))
|
|
1883
2098
|
return;
|
|
1884
2099
|
const contract = await this.maintainabilityContractOf(exec);
|
|
1885
2100
|
const failures = await contract.enforce({ fix });
|
|
@@ -1887,7 +2102,7 @@ class WorkspaceRunner extends runner("workspace") {
|
|
|
1887
2102
|
throw new Error(contract.describe(failures, WorkspaceRunner.#maintainabilityCommandsOf(exec)));
|
|
1888
2103
|
}
|
|
1889
2104
|
static #maintainabilityCommandsOf(exec) {
|
|
1890
|
-
return exec instanceof
|
|
2105
|
+
return exec instanceof PkgExecutor2 ? {} : new MaintainabilityPaths().commandsOf(exec.name);
|
|
1891
2106
|
}
|
|
1892
2107
|
async#enforceRecipeGate(exec) {
|
|
1893
2108
|
const cwdPath = exec.cwdPath;
|
|
@@ -1945,23 +2160,23 @@ AKAN_PUBLIC_LOG_LEVEL=debug
|
|
|
1945
2160
|
}
|
|
1946
2161
|
}
|
|
1947
2162
|
|
|
1948
|
-
// pkgs/@akanjs/devkit/qualityScanner.ts
|
|
2163
|
+
// pkgs/@akanjs/devkit/quality/qualityScanner.ts
|
|
1949
2164
|
import { createHash } from "crypto";
|
|
1950
2165
|
import { readdir as readdir2, readFile as readFile3, stat } from "fs/promises";
|
|
1951
2166
|
import path9 from "path";
|
|
1952
2167
|
import { RESERVED_ROUTE_CONFIG_EXPORTS } from "akanjs/common";
|
|
1953
2168
|
import ignore from "ignore";
|
|
1954
|
-
import
|
|
2169
|
+
import ts21 from "typescript";
|
|
1955
2170
|
|
|
1956
|
-
// pkgs/@akanjs/devkit/commentDensityScanner.ts
|
|
2171
|
+
// pkgs/@akanjs/devkit/quality/commentDensityScanner.ts
|
|
1957
2172
|
import path6 from "path";
|
|
1958
|
-
import
|
|
2173
|
+
import ts15 from "typescript";
|
|
1959
2174
|
|
|
1960
|
-
// pkgs/@akanjs/devkit/sourceComments.ts
|
|
1961
|
-
import
|
|
2175
|
+
// pkgs/@akanjs/devkit/quality/sourceComments.ts
|
|
2176
|
+
import ts14 from "typescript";
|
|
1962
2177
|
|
|
1963
2178
|
class SourceComments {
|
|
1964
|
-
static #scanner =
|
|
2179
|
+
static #scanner = ts14.createScanner(ts14.ScriptTarget.Latest, false);
|
|
1965
2180
|
static of(sourceFile) {
|
|
1966
2181
|
const comments = [];
|
|
1967
2182
|
const scanGap = (start, end) => {
|
|
@@ -1969,22 +2184,22 @@ class SourceComments {
|
|
|
1969
2184
|
return;
|
|
1970
2185
|
const scanner = SourceComments.#scanner;
|
|
1971
2186
|
scanner.setText(sourceFile.text, start, end - start);
|
|
1972
|
-
for (let kind = scanner.scan();kind !==
|
|
1973
|
-
if (kind !==
|
|
2187
|
+
for (let kind = scanner.scan();kind !== ts14.SyntaxKind.EndOfFileToken; kind = scanner.scan()) {
|
|
2188
|
+
if (kind !== ts14.SyntaxKind.SingleLineCommentTrivia && kind !== ts14.SyntaxKind.MultiLineCommentTrivia)
|
|
1974
2189
|
continue;
|
|
1975
2190
|
comments.push(SourceComments.#commentOf(sourceFile, scanner.getTokenStart(), scanner.getTokenText()));
|
|
1976
2191
|
}
|
|
1977
2192
|
scanner.setText(undefined);
|
|
1978
2193
|
};
|
|
1979
2194
|
const visit = (node) => {
|
|
1980
|
-
if (node.kind ===
|
|
2195
|
+
if (node.kind === ts14.SyntaxKind.JsxText)
|
|
1981
2196
|
return;
|
|
1982
|
-
if (
|
|
2197
|
+
if (ts14.isToken(node)) {
|
|
1983
2198
|
scanGap(node.pos, node.getStart(sourceFile));
|
|
1984
2199
|
return;
|
|
1985
2200
|
}
|
|
1986
2201
|
const children = [];
|
|
1987
|
-
|
|
2202
|
+
ts14.forEachChild(node, (child) => {
|
|
1988
2203
|
children.push(child);
|
|
1989
2204
|
}, (nodes) => {
|
|
1990
2205
|
children.push(...nodes);
|
|
@@ -2015,7 +2230,7 @@ class SourceComments {
|
|
|
2015
2230
|
}
|
|
2016
2231
|
}
|
|
2017
2232
|
|
|
2018
|
-
// pkgs/@akanjs/devkit/commentDensityScanner.ts
|
|
2233
|
+
// pkgs/@akanjs/devkit/quality/commentDensityScanner.ts
|
|
2019
2234
|
class CommentDensityScanner {
|
|
2020
2235
|
static rule = "akan.comment.density";
|
|
2021
2236
|
static maxShare = 0.01;
|
|
@@ -2087,11 +2302,11 @@ class CommentDensityScanner {
|
|
|
2087
2302
|
static #isMeasured({ file, sourceFile }) {
|
|
2088
2303
|
if (/\.(test|spec)\.tsx?$/.test(file) || path6.basename(file) === "guards.ts")
|
|
2089
2304
|
return false;
|
|
2090
|
-
return !sourceFile.statements.every((statement) =>
|
|
2305
|
+
return !sourceFile.statements.every((statement) => ts15.isExportDeclaration(statement) || ts15.isExpressionStatement(statement) && ts15.isStringLiteral(statement.expression));
|
|
2091
2306
|
}
|
|
2092
2307
|
}
|
|
2093
2308
|
|
|
2094
|
-
// pkgs/@akanjs/devkit/deprecatedCommentScanner.ts
|
|
2309
|
+
// pkgs/@akanjs/devkit/quality/deprecatedCommentScanner.ts
|
|
2095
2310
|
class DeprecatedCommentScanner {
|
|
2096
2311
|
static rule = "akan.comment.deprecated-marker";
|
|
2097
2312
|
static #marker = /^[!?*\s]*(?:(?:TODO|FIXME|XXX|NOTE)\b\s*:?\s*)?@?deprecated\b/i;
|
|
@@ -2113,9 +2328,9 @@ class DeprecatedCommentScanner {
|
|
|
2113
2328
|
}
|
|
2114
2329
|
}
|
|
2115
2330
|
|
|
2116
|
-
// pkgs/@akanjs/devkit/formSetterScanner.ts
|
|
2331
|
+
// pkgs/@akanjs/devkit/quality/formSetterScanner.ts
|
|
2117
2332
|
import { capitalize, formSetterNames } from "akanjs/common";
|
|
2118
|
-
import
|
|
2333
|
+
import ts16 from "typescript";
|
|
2119
2334
|
|
|
2120
2335
|
class FormSetterScanner {
|
|
2121
2336
|
static #constantPath = /(?:^|\/)lib\/([^_/][^/]*)\/\1\.constant\.ts$/;
|
|
@@ -2134,7 +2349,7 @@ class FormSetterScanner {
|
|
|
2134
2349
|
const fullModelClasses = new Set([`${className}Input`, `${className}Object`, `Light${className}`, className]);
|
|
2135
2350
|
const keys = new Set(FormSetterScanner.#baseFields);
|
|
2136
2351
|
for (const statement of sourceFile.statements)
|
|
2137
|
-
if (
|
|
2352
|
+
if (ts16.isClassDeclaration(statement) && statement.name && fullModelClasses.has(statement.name.text))
|
|
2138
2353
|
for (const key of FormSetterScanner.#viaFieldKeysOf(statement))
|
|
2139
2354
|
keys.add(key);
|
|
2140
2355
|
for (const key of keys)
|
|
@@ -2143,33 +2358,33 @@ class FormSetterScanner {
|
|
|
2143
2358
|
return setters;
|
|
2144
2359
|
}
|
|
2145
2360
|
static #viaFieldKeysOf(declaration) {
|
|
2146
|
-
const via = declaration.heritageClauses?.find((clause) => clause.token ===
|
|
2147
|
-
if (!via || !
|
|
2361
|
+
const via = declaration.heritageClauses?.find((clause) => clause.token === ts16.SyntaxKind.ExtendsKeyword)?.types[0]?.expression;
|
|
2362
|
+
if (!via || !ts16.isCallExpression(via))
|
|
2148
2363
|
return [];
|
|
2149
2364
|
return via.arguments.flatMap((argument) => {
|
|
2150
|
-
if (!
|
|
2365
|
+
if (!ts16.isArrowFunction(argument) && !ts16.isFunctionExpression(argument))
|
|
2151
2366
|
return [];
|
|
2152
2367
|
const fields = FormSetterScanner.#returnedObjectOf(argument.body);
|
|
2153
|
-
return (fields?.properties ?? []).flatMap((property) => property.name && (
|
|
2368
|
+
return (fields?.properties ?? []).flatMap((property) => property.name && (ts16.isIdentifier(property.name) || ts16.isStringLiteral(property.name)) ? [property.name.text] : []);
|
|
2154
2369
|
});
|
|
2155
2370
|
}
|
|
2156
2371
|
static #returnedObjectOf(body) {
|
|
2157
2372
|
let expression = body;
|
|
2158
|
-
if (
|
|
2159
|
-
expression = body.statements.find(
|
|
2160
|
-
while (expression && (
|
|
2373
|
+
if (ts16.isBlock(body))
|
|
2374
|
+
expression = body.statements.find(ts16.isReturnStatement)?.expression;
|
|
2375
|
+
while (expression && (ts16.isParenthesizedExpression(expression) || ts16.isAsExpression(expression)))
|
|
2161
2376
|
expression = expression.expression;
|
|
2162
|
-
return expression &&
|
|
2377
|
+
return expression && ts16.isObjectLiteralExpression(expression) ? expression : null;
|
|
2163
2378
|
}
|
|
2164
2379
|
#scanFile({ file, sourceFile }, fieldSetters) {
|
|
2165
2380
|
const wrapped = [];
|
|
2166
2381
|
const visit = (node) => {
|
|
2167
|
-
if (
|
|
2382
|
+
if (ts16.isJsxAttribute(node)) {
|
|
2168
2383
|
const setter = FormSetterScanner.#wrappedSetterOf(node, fieldSetters);
|
|
2169
2384
|
if (setter)
|
|
2170
2385
|
wrapped.push({ setter, line: FormSetterScanner.#lineOf(sourceFile, node) });
|
|
2171
2386
|
}
|
|
2172
|
-
|
|
2387
|
+
ts16.forEachChild(node, visit);
|
|
2173
2388
|
};
|
|
2174
2389
|
visit(sourceFile);
|
|
2175
2390
|
if (!wrapped.length)
|
|
@@ -2188,13 +2403,13 @@ class FormSetterScanner {
|
|
|
2188
2403
|
];
|
|
2189
2404
|
}
|
|
2190
2405
|
static #wrappedSetterOf(attribute, fieldSetters) {
|
|
2191
|
-
if (!
|
|
2406
|
+
if (!ts16.isIdentifier(attribute.name) || !/^on[A-Z]/.test(attribute.name.text))
|
|
2192
2407
|
return null;
|
|
2193
2408
|
const initializer = attribute.initializer;
|
|
2194
|
-
if (!initializer || !
|
|
2409
|
+
if (!initializer || !ts16.isJsxExpression(initializer) || !initializer.expression)
|
|
2195
2410
|
return null;
|
|
2196
2411
|
const handler = initializer.expression;
|
|
2197
|
-
if (!
|
|
2412
|
+
if (!ts16.isArrowFunction(handler) && !ts16.isFunctionExpression(handler))
|
|
2198
2413
|
return null;
|
|
2199
2414
|
if (!handler.parameters.length)
|
|
2200
2415
|
return null;
|
|
@@ -2205,14 +2420,14 @@ class FormSetterScanner {
|
|
|
2205
2420
|
const visit = (current) => {
|
|
2206
2421
|
if (found)
|
|
2207
2422
|
return;
|
|
2208
|
-
if (
|
|
2423
|
+
if (ts16.isCallExpression(current) && ts16.isPropertyAccessExpression(current.expression)) {
|
|
2209
2424
|
const { expression, name } = current.expression;
|
|
2210
|
-
if (
|
|
2425
|
+
if (ts16.isPropertyAccessExpression(expression) && ts16.isIdentifier(expression.expression) && expression.expression.text === "st" && expression.name.text === "do" && fieldSetters.has(name.text)) {
|
|
2211
2426
|
found = name.text;
|
|
2212
2427
|
return;
|
|
2213
2428
|
}
|
|
2214
2429
|
}
|
|
2215
|
-
|
|
2430
|
+
ts16.forEachChild(current, visit);
|
|
2216
2431
|
};
|
|
2217
2432
|
visit(node);
|
|
2218
2433
|
return found;
|
|
@@ -2222,9 +2437,9 @@ class FormSetterScanner {
|
|
|
2222
2437
|
}
|
|
2223
2438
|
}
|
|
2224
2439
|
|
|
2225
|
-
// pkgs/@akanjs/devkit/kindBranchScanner.ts
|
|
2440
|
+
// pkgs/@akanjs/devkit/quality/kindBranchScanner.ts
|
|
2226
2441
|
import path7 from "path";
|
|
2227
|
-
import
|
|
2442
|
+
import ts17 from "typescript";
|
|
2228
2443
|
|
|
2229
2444
|
class KindBranchScanner {
|
|
2230
2445
|
static rule = "akan.global.kind-branch";
|
|
@@ -2232,10 +2447,10 @@ class KindBranchScanner {
|
|
|
2232
2447
|
static #kindName = /(Kind|Type|Mode)$/;
|
|
2233
2448
|
static #kindSubject = /^(kind|type|mode)$|[a-z](Kind|Type|Mode)$/;
|
|
2234
2449
|
static #equalities = new Set([
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2450
|
+
ts17.SyntaxKind.EqualsEqualsEqualsToken,
|
|
2451
|
+
ts17.SyntaxKind.ExclamationEqualsEqualsToken,
|
|
2452
|
+
ts17.SyntaxKind.EqualsEqualsToken,
|
|
2453
|
+
ts17.SyntaxKind.ExclamationEqualsToken
|
|
2239
2454
|
]);
|
|
2240
2455
|
scan(sourceFiles) {
|
|
2241
2456
|
const enums = sourceFiles.flatMap((sourceFile) => KindBranchScanner.#enumsOf(sourceFile));
|
|
@@ -2287,7 +2502,7 @@ class KindBranchScanner {
|
|
|
2287
2502
|
static #sitesIn({ file, sourceFile }, ownersByValue) {
|
|
2288
2503
|
const sites = [];
|
|
2289
2504
|
const record = (literal, subject) => {
|
|
2290
|
-
if (!
|
|
2505
|
+
if (!ts17.isStringLiteralLike(literal) || !ownersByValue.has(literal.text))
|
|
2291
2506
|
return;
|
|
2292
2507
|
if (!KindBranchScanner.#isKindSubject(subject))
|
|
2293
2508
|
return;
|
|
@@ -2298,28 +2513,28 @@ class KindBranchScanner {
|
|
|
2298
2513
|
});
|
|
2299
2514
|
};
|
|
2300
2515
|
const visit = (node) => {
|
|
2301
|
-
if (
|
|
2516
|
+
if (ts17.isBinaryExpression(node) && KindBranchScanner.#equalities.has(node.operatorToken.kind)) {
|
|
2302
2517
|
record(node.left, node.right);
|
|
2303
2518
|
record(node.right, node.left);
|
|
2304
|
-
} else if (
|
|
2519
|
+
} else if (ts17.isCaseClause(node) && ts17.isSwitchStatement(node.parent.parent))
|
|
2305
2520
|
record(node.expression, node.parent.parent.expression);
|
|
2306
|
-
|
|
2521
|
+
ts17.forEachChild(node, visit);
|
|
2307
2522
|
};
|
|
2308
2523
|
visit(sourceFile);
|
|
2309
2524
|
return sites;
|
|
2310
2525
|
}
|
|
2311
2526
|
static #isKindSubject(subject) {
|
|
2312
2527
|
let current = subject;
|
|
2313
|
-
while (
|
|
2528
|
+
while (ts17.isParenthesizedExpression(current) || ts17.isAsExpression(current) || ts17.isNonNullExpression(current))
|
|
2314
2529
|
current = current.expression;
|
|
2315
|
-
const name =
|
|
2530
|
+
const name = ts17.isIdentifier(current) ? current.text : ts17.isPropertyAccessExpression(current) ? current.name.text : ts17.isElementAccessExpression(current) && ts17.isStringLiteralLike(current.argumentExpression) ? current.argumentExpression.text : "";
|
|
2316
2531
|
return KindBranchScanner.#kindSubject.test(name);
|
|
2317
2532
|
}
|
|
2318
2533
|
static #enumsOf({ file, sourceFile }) {
|
|
2319
2534
|
if (!/^(apps|libs)\/[^/]+\/lib\/.+\.constant\.ts$/.test(file))
|
|
2320
2535
|
return [];
|
|
2321
2536
|
return sourceFile.statements.flatMap((statement) => {
|
|
2322
|
-
if (!
|
|
2537
|
+
if (!ts17.isClassDeclaration(statement) || !statement.name)
|
|
2323
2538
|
return [];
|
|
2324
2539
|
if (!KindBranchScanner.#kindName.test(statement.name.text))
|
|
2325
2540
|
return [];
|
|
@@ -2344,22 +2559,22 @@ class KindBranchScanner {
|
|
|
2344
2559
|
static #enumValuesOf(statement) {
|
|
2345
2560
|
for (const clause of statement.heritageClauses ?? [])
|
|
2346
2561
|
for (const { expression } of clause.types) {
|
|
2347
|
-
if (!
|
|
2562
|
+
if (!ts17.isCallExpression(expression) || !ts17.isIdentifier(expression.expression))
|
|
2348
2563
|
continue;
|
|
2349
2564
|
if (expression.expression.text !== "enumOf")
|
|
2350
2565
|
continue;
|
|
2351
2566
|
let list = expression.arguments[1];
|
|
2352
|
-
while (list && (
|
|
2567
|
+
while (list && (ts17.isAsExpression(list) || ts17.isParenthesizedExpression(list)))
|
|
2353
2568
|
list = list.expression;
|
|
2354
|
-
if (!list || !
|
|
2569
|
+
if (!list || !ts17.isArrayLiteralExpression(list))
|
|
2355
2570
|
return null;
|
|
2356
|
-
return list.elements.filter(
|
|
2571
|
+
return list.elements.filter(ts17.isStringLiteralLike).map(({ text }) => text);
|
|
2357
2572
|
}
|
|
2358
2573
|
return null;
|
|
2359
2574
|
}
|
|
2360
2575
|
}
|
|
2361
2576
|
|
|
2362
|
-
// pkgs/@akanjs/devkit/maintainabilityExceptionScanner.ts
|
|
2577
|
+
// pkgs/@akanjs/devkit/quality/maintainabilityExceptionScanner.ts
|
|
2363
2578
|
import { existsSync as existsSync2 } from "fs";
|
|
2364
2579
|
import { readdir, readFile as readFile2 } from "fs/promises";
|
|
2365
2580
|
import path8 from "path";
|
|
@@ -2367,6 +2582,7 @@ class MaintainabilityExceptionScanner {
|
|
|
2367
2582
|
static rule = "akan.baseline.exceptions";
|
|
2368
2583
|
static #shapeFix = "Many reasoned exceptions under one rule mean its threshold is wrong: fix the limit in MaintainabilityLimits rather than record another. Otherwise shrink the code, and `akan lint` lowers each entry and drops it once it passes.";
|
|
2369
2584
|
static #correctnessFix = "A write rule takes no exception: send the writes through one store action and one endpoint (`akan workflow plan add-mutation`), and `akan lint` drops the entry.";
|
|
2585
|
+
static #bareErrorFix = "A bare Error takes no exception: construct an `AkanError` subclass with a code, and `akan lint` lowers the entries as they go.";
|
|
2370
2586
|
async scan(workspaceRoot) {
|
|
2371
2587
|
const sysPaths = await Promise.all(["apps", "libs", "pkgs"].map((sysRoot) => MaintainabilityExceptionScanner.#dirsIn(workspaceRoot, sysRoot)));
|
|
2372
2588
|
const warnings = await Promise.all(sysPaths.flat().map((sysPath) => MaintainabilityExceptionScanner.#scanSys(workspaceRoot, sysPath)));
|
|
@@ -2412,7 +2628,7 @@ class MaintainabilityExceptionScanner {
|
|
|
2412
2628
|
line: locations[0]?.line ?? 1,
|
|
2413
2629
|
message: `${sysPath} carries ${reasonedNum} reasoned exception${reasonedNum === 1 ? "" : "s"} and ${adoptedNum} adopted-debt entr${adoptedNum === 1 ? "y" : "ies"} for ${rule}: ${listed.join(", ")}.`,
|
|
2414
2630
|
locations,
|
|
2415
|
-
fix: MaintainabilityBaseline.reasonedRules.has(rule) ? MaintainabilityExceptionScanner.#shapeFix : MaintainabilityExceptionScanner.#correctnessFix
|
|
2631
|
+
fix: MaintainabilityBaseline.reasonedRules.has(rule) ? MaintainabilityExceptionScanner.#shapeFix : rule === "akan.error.bare-error" ? MaintainabilityExceptionScanner.#bareErrorFix : MaintainabilityExceptionScanner.#correctnessFix
|
|
2416
2632
|
};
|
|
2417
2633
|
}
|
|
2418
2634
|
static #lineOf(lines, rule, key) {
|
|
@@ -2421,11 +2637,11 @@ class MaintainabilityExceptionScanner {
|
|
|
2421
2637
|
}
|
|
2422
2638
|
}
|
|
2423
2639
|
|
|
2424
|
-
// pkgs/@akanjs/devkit/ssrScanner.ts
|
|
2425
|
-
import
|
|
2640
|
+
// pkgs/@akanjs/devkit/quality/ssrScanner.ts
|
|
2641
|
+
import ts19 from "typescript";
|
|
2426
2642
|
|
|
2427
|
-
// pkgs/@akanjs/devkit/renderMutationScanner.ts
|
|
2428
|
-
import
|
|
2643
|
+
// pkgs/@akanjs/devkit/quality/renderMutationScanner.ts
|
|
2644
|
+
import ts18 from "typescript";
|
|
2429
2645
|
|
|
2430
2646
|
class RenderMutationScanner {
|
|
2431
2647
|
static rule = "akan.ssr.render-mutation";
|
|
@@ -2454,7 +2670,7 @@ class RenderMutationScanner {
|
|
|
2454
2670
|
const helper = follow ? RenderMutationScanner.#helperOf(node, functions) : undefined;
|
|
2455
2671
|
if (helper)
|
|
2456
2672
|
helpers.add(helper);
|
|
2457
|
-
|
|
2673
|
+
ts18.forEachChild(node, (child) => visit(child, follow));
|
|
2458
2674
|
};
|
|
2459
2675
|
for (const body of RenderMutationScanner.#renderBodiesOf(sourceFile, functions))
|
|
2460
2676
|
visit(body, true);
|
|
@@ -2471,7 +2687,7 @@ class RenderMutationScanner {
|
|
|
2471
2687
|
}));
|
|
2472
2688
|
}
|
|
2473
2689
|
#isRenderMutation(file, node, fetchNames) {
|
|
2474
|
-
if (!
|
|
2690
|
+
if (!ts18.isCallExpression(node))
|
|
2475
2691
|
return false;
|
|
2476
2692
|
const name = RenderMutationScanner.#endpointOf(node.expression, fetchNames);
|
|
2477
2693
|
if (!name || !this.#mutations.isMutation(file, name))
|
|
@@ -2479,64 +2695,64 @@ class RenderMutationScanner {
|
|
|
2479
2695
|
return !RenderMutationScanner.#optsIn(node, this.#mutations.policyIndexOf(file, name));
|
|
2480
2696
|
}
|
|
2481
2697
|
static #isEventHandler(node) {
|
|
2482
|
-
return
|
|
2698
|
+
return ts18.isJsxAttribute(node) && ts18.isIdentifier(node.name) && /^on[A-Z]/.test(node.name.text);
|
|
2483
2699
|
}
|
|
2484
2700
|
static #endpointOf(callee, fetchNames) {
|
|
2485
|
-
if (
|
|
2701
|
+
if (ts18.isPropertyAccessExpression(callee))
|
|
2486
2702
|
return RenderMutationScanner.#isFetch(callee.expression, fetchNames) ? callee.name.text : null;
|
|
2487
|
-
if (
|
|
2703
|
+
if (ts18.isElementAccessExpression(callee) && ts18.isStringLiteralLike(callee.argumentExpression))
|
|
2488
2704
|
return RenderMutationScanner.#isFetch(callee.expression, fetchNames) ? callee.argumentExpression.text : null;
|
|
2489
2705
|
return null;
|
|
2490
2706
|
}
|
|
2491
2707
|
static #isFetch(expression, fetchNames) {
|
|
2492
|
-
return
|
|
2708
|
+
return ts18.isIdentifier(expression) && fetchNames.has(expression.text);
|
|
2493
2709
|
}
|
|
2494
2710
|
static #optsIn(call, policyIndex) {
|
|
2495
2711
|
if (policyIndex === null)
|
|
2496
2712
|
return false;
|
|
2497
2713
|
const leading = call.arguments.slice(0, policyIndex + 1);
|
|
2498
|
-
if (leading.some((argument) =>
|
|
2714
|
+
if (leading.some((argument) => ts18.isSpreadElement(argument)))
|
|
2499
2715
|
return true;
|
|
2500
2716
|
const policy = leading[policyIndex];
|
|
2501
2717
|
return policy ? RenderMutationScanner.#policyOptsIn(policy) : false;
|
|
2502
2718
|
}
|
|
2503
2719
|
static #policyOptsIn(argument) {
|
|
2504
2720
|
const policy = RenderMutationScanner.#unwrap(argument);
|
|
2505
|
-
if (!
|
|
2721
|
+
if (!ts18.isObjectLiteralExpression(policy))
|
|
2506
2722
|
return !RenderMutationScanner.#cannotBePolicy(policy);
|
|
2507
2723
|
return policy.properties.some((property) => {
|
|
2508
|
-
if (
|
|
2724
|
+
if (ts18.isSpreadAssignment(property))
|
|
2509
2725
|
return true;
|
|
2510
|
-
if (!
|
|
2726
|
+
if (!ts18.isPropertyAssignment(property) && !ts18.isShorthandPropertyAssignment(property))
|
|
2511
2727
|
return false;
|
|
2512
|
-
if (!(
|
|
2728
|
+
if (!(ts18.isIdentifier(property.name) || ts18.isStringLiteral(property.name)))
|
|
2513
2729
|
return false;
|
|
2514
2730
|
if (property.name.text !== "duringRender")
|
|
2515
2731
|
return false;
|
|
2516
|
-
if (
|
|
2732
|
+
if (ts18.isShorthandPropertyAssignment(property))
|
|
2517
2733
|
return true;
|
|
2518
2734
|
const value = RenderMutationScanner.#unwrap(property.initializer);
|
|
2519
|
-
return value.kind !==
|
|
2735
|
+
return value.kind !== ts18.SyntaxKind.FalseKeyword && !(ts18.isIdentifier(value) && value.text === "undefined");
|
|
2520
2736
|
});
|
|
2521
2737
|
}
|
|
2522
2738
|
static #unwrap(expression) {
|
|
2523
2739
|
let current = expression;
|
|
2524
|
-
while (
|
|
2740
|
+
while (ts18.isParenthesizedExpression(current) || ts18.isAsExpression(current) || ts18.isSatisfiesExpression(current) || ts18.isNonNullExpression(current) || ts18.isTypeAssertionExpression(current))
|
|
2525
2741
|
current = current.expression;
|
|
2526
2742
|
return current;
|
|
2527
2743
|
}
|
|
2528
2744
|
static #cannotBePolicy(expression) {
|
|
2529
|
-
if (
|
|
2745
|
+
if (ts18.isIdentifier(expression))
|
|
2530
2746
|
return expression.text === "undefined";
|
|
2531
|
-
return
|
|
2747
|
+
return ts18.isLiteralExpression(expression) || ts18.isNoSubstitutionTemplateLiteral(expression) || ts18.isTemplateExpression(expression) || ts18.isArrayLiteralExpression(expression) || ts18.isArrowFunction(expression) || ts18.isFunctionExpression(expression) || ts18.isVoidExpression(expression) || ts18.isPrefixUnaryExpression(expression) || [ts18.SyntaxKind.NullKeyword, ts18.SyntaxKind.TrueKeyword, ts18.SyntaxKind.FalseKeyword].includes(expression.kind);
|
|
2532
2748
|
}
|
|
2533
2749
|
static #fetchBindingsOf(sourceFile) {
|
|
2534
2750
|
const names = new Set;
|
|
2535
2751
|
for (const statement of sourceFile.statements) {
|
|
2536
|
-
if (!
|
|
2752
|
+
if (!ts18.isImportDeclaration(statement) || statement.importClause?.isTypeOnly)
|
|
2537
2753
|
continue;
|
|
2538
2754
|
const bindings = statement.importClause?.namedBindings;
|
|
2539
|
-
if (!bindings || !
|
|
2755
|
+
if (!bindings || !ts18.isNamedImports(bindings))
|
|
2540
2756
|
continue;
|
|
2541
2757
|
for (const element of bindings.elements)
|
|
2542
2758
|
if (!element.isTypeOnly && (element.propertyName ?? element.name).text === "fetch")
|
|
@@ -2547,35 +2763,35 @@ class RenderMutationScanner {
|
|
|
2547
2763
|
static #functionsOf(sourceFile) {
|
|
2548
2764
|
const functions = new Map;
|
|
2549
2765
|
for (const statement of sourceFile.statements) {
|
|
2550
|
-
if (
|
|
2766
|
+
if (ts18.isFunctionDeclaration(statement) && statement.name && statement.body)
|
|
2551
2767
|
functions.set(statement.name.text, statement.body);
|
|
2552
|
-
if (!
|
|
2768
|
+
if (!ts18.isVariableStatement(statement))
|
|
2553
2769
|
continue;
|
|
2554
2770
|
for (const declaration of statement.declarationList.declarations) {
|
|
2555
2771
|
const initializer = declaration.initializer && RenderMutationScanner.#unwrap(declaration.initializer);
|
|
2556
|
-
if (!
|
|
2772
|
+
if (!ts18.isIdentifier(declaration.name) || !initializer)
|
|
2557
2773
|
continue;
|
|
2558
|
-
if (
|
|
2774
|
+
if (ts18.isArrowFunction(initializer) || ts18.isFunctionExpression(initializer))
|
|
2559
2775
|
functions.set(declaration.name.text, initializer.body);
|
|
2560
2776
|
}
|
|
2561
2777
|
}
|
|
2562
2778
|
return functions;
|
|
2563
2779
|
}
|
|
2564
2780
|
static #helperOf(node, functions) {
|
|
2565
|
-
const callee =
|
|
2566
|
-
return callee &&
|
|
2781
|
+
const callee = ts18.isCallExpression(node) ? node.expression : ts18.isJsxSelfClosingElement(node) || ts18.isJsxOpeningElement(node) ? node.tagName : undefined;
|
|
2782
|
+
return callee && ts18.isIdentifier(callee) ? functions.get(callee.text) : undefined;
|
|
2567
2783
|
}
|
|
2568
2784
|
static #renderBodiesOf(sourceFile, functions) {
|
|
2569
2785
|
const bodies = [];
|
|
2570
|
-
const bodyOf = (node) =>
|
|
2786
|
+
const bodyOf = (node) => ts18.isIdentifier(node) ? functions.get(node.text) : node;
|
|
2571
2787
|
const visit = (node) => {
|
|
2572
|
-
if (
|
|
2788
|
+
if (ts18.isCallExpression(node) && ts18.isPropertyAccessExpression(node.expression) && RenderMutationScanner.#stages.has(node.expression.name.text) && RenderMutationScanner.#isRouteChain(node.expression.expression))
|
|
2573
2789
|
for (const argument of node.arguments) {
|
|
2574
2790
|
const body = bodyOf(argument);
|
|
2575
2791
|
if (body)
|
|
2576
2792
|
bodies.push(body);
|
|
2577
2793
|
}
|
|
2578
|
-
|
|
2794
|
+
ts18.forEachChild(node, visit);
|
|
2579
2795
|
};
|
|
2580
2796
|
visit(sourceFile);
|
|
2581
2797
|
for (const statement of sourceFile.statements) {
|
|
@@ -2587,28 +2803,28 @@ class RenderMutationScanner {
|
|
|
2587
2803
|
}
|
|
2588
2804
|
static #isRouteChain(expression) {
|
|
2589
2805
|
let current = expression;
|
|
2590
|
-
while (
|
|
2591
|
-
if (
|
|
2806
|
+
while (ts18.isCallExpression(current)) {
|
|
2807
|
+
if (ts18.isIdentifier(current.expression))
|
|
2592
2808
|
return RenderMutationScanner.#builders.has(current.expression.text);
|
|
2593
|
-
if (!
|
|
2809
|
+
if (!ts18.isPropertyAccessExpression(current.expression))
|
|
2594
2810
|
return false;
|
|
2595
2811
|
current = current.expression.expression;
|
|
2596
2812
|
}
|
|
2597
2813
|
return false;
|
|
2598
2814
|
}
|
|
2599
2815
|
static #legacyPageOf(statement, functions) {
|
|
2600
|
-
if (
|
|
2601
|
-
return statement.modifiers?.some((modifier) => modifier.kind ===
|
|
2602
|
-
if (!
|
|
2816
|
+
if (ts18.isFunctionDeclaration(statement))
|
|
2817
|
+
return statement.modifiers?.some((modifier) => modifier.kind === ts18.SyntaxKind.DefaultKeyword) ? statement.body : undefined;
|
|
2818
|
+
if (!ts18.isExportAssignment(statement))
|
|
2603
2819
|
return;
|
|
2604
2820
|
const expression = RenderMutationScanner.#unwrap(statement.expression);
|
|
2605
|
-
if (
|
|
2821
|
+
if (ts18.isIdentifier(expression))
|
|
2606
2822
|
return functions.get(expression.text);
|
|
2607
|
-
return
|
|
2823
|
+
return ts18.isArrowFunction(expression) || ts18.isFunctionExpression(expression) ? expression.body : undefined;
|
|
2608
2824
|
}
|
|
2609
2825
|
}
|
|
2610
2826
|
|
|
2611
|
-
// pkgs/@akanjs/devkit/ssrScanner.ts
|
|
2827
|
+
// pkgs/@akanjs/devkit/quality/ssrScanner.ts
|
|
2612
2828
|
var STATIC_COMPONENT_MIN_MASS = 4;
|
|
2613
2829
|
var MIXED_COMPONENT_MIN_MASS = 10;
|
|
2614
2830
|
var MIXED_COMPONENT_MAX_TOUCHES = 2;
|
|
@@ -2689,18 +2905,18 @@ class SsrScanner {
|
|
|
2689
2905
|
return warnings;
|
|
2690
2906
|
}
|
|
2691
2907
|
#isMountEffect(sourceFile, node) {
|
|
2692
|
-
if (!
|
|
2908
|
+
if (!ts19.isCallExpression(node))
|
|
2693
2909
|
return false;
|
|
2694
2910
|
const callee = node.expression.getText(sourceFile);
|
|
2695
2911
|
if (callee !== "useEffect" && callee !== "useLayoutEffect")
|
|
2696
2912
|
return false;
|
|
2697
2913
|
const deps = node.arguments[1];
|
|
2698
|
-
return !!deps &&
|
|
2914
|
+
return !!deps && ts19.isArrayLiteralExpression(deps) && deps.elements.length === 0;
|
|
2699
2915
|
}
|
|
2700
2916
|
#getLoadCalls(sourceFile, node) {
|
|
2701
2917
|
const calls = [];
|
|
2702
2918
|
SsrScanner.#walk(node, (child) => {
|
|
2703
|
-
if (!
|
|
2919
|
+
if (!ts19.isCallExpression(child))
|
|
2704
2920
|
return;
|
|
2705
2921
|
const callee = child.expression.getText(sourceFile);
|
|
2706
2922
|
if (/^fetch\.[a-z]/.test(callee) || /^st\.do\.(init|get|view|load|list|count|insight)[A-Z]/.test(callee))
|
|
@@ -2713,7 +2929,7 @@ class SsrScanner {
|
|
|
2713
2929
|
return [];
|
|
2714
2930
|
const warnings = [];
|
|
2715
2931
|
SsrScanner.#walk(sourceFile.sourceFile, (node) => {
|
|
2716
|
-
if (
|
|
2932
|
+
if (ts19.isCallExpression(node) && node.expression.getText(sourceFile.sourceFile) === "useState")
|
|
2717
2933
|
warnings.push(fileWarning("akan.ssr.template-client-state", "ssr", sourceFile.file, "Template holds form state in useState. Templates are store-driven and carry no local state.", this.#getLine(sourceFile.sourceFile, node)));
|
|
2718
2934
|
});
|
|
2719
2935
|
return warnings;
|
|
@@ -2756,14 +2972,14 @@ class SsrScanner {
|
|
|
2756
2972
|
return components;
|
|
2757
2973
|
}
|
|
2758
2974
|
#getComponentNodes(statement) {
|
|
2759
|
-
if (
|
|
2975
|
+
if (ts19.isFunctionDeclaration(statement) && statement.body)
|
|
2760
2976
|
return [{ name: statement.name?.text ?? "default", node: statement.body }];
|
|
2761
|
-
if (!
|
|
2977
|
+
if (!ts19.isVariableStatement(statement))
|
|
2762
2978
|
return [];
|
|
2763
2979
|
return statement.declarationList.declarations.flatMap((declaration) => {
|
|
2764
|
-
if (!
|
|
2980
|
+
if (!ts19.isIdentifier(declaration.name) || !declaration.initializer)
|
|
2765
2981
|
return [];
|
|
2766
|
-
if (!
|
|
2982
|
+
if (!ts19.isArrowFunction(declaration.initializer) && !ts19.isFunctionExpression(declaration.initializer))
|
|
2767
2983
|
return [];
|
|
2768
2984
|
return [{ name: declaration.name.text, node: declaration.initializer }];
|
|
2769
2985
|
});
|
|
@@ -2771,7 +2987,7 @@ class SsrScanner {
|
|
|
2771
2987
|
#getTouches(sourceFile, node) {
|
|
2772
2988
|
const touches = [];
|
|
2773
2989
|
SsrScanner.#walk(node, (child) => {
|
|
2774
|
-
if (
|
|
2990
|
+
if (ts19.isCallExpression(child)) {
|
|
2775
2991
|
const callee = child.expression.getText(sourceFile);
|
|
2776
2992
|
const bareName = callee.split(".").pop() ?? callee;
|
|
2777
2993
|
if (callee === "createContext" || callee === "lazy")
|
|
@@ -2779,9 +2995,9 @@ class SsrScanner {
|
|
|
2779
2995
|
else if (/^use[A-Z]/.test(bareName) && !SsrScanner.#serverSafeCalls.has(bareName))
|
|
2780
2996
|
touches.push(bareName);
|
|
2781
2997
|
}
|
|
2782
|
-
if (
|
|
2998
|
+
if (ts19.isJsxAttribute(child) && /^on[A-Z]/.test(child.name.getText(sourceFile)))
|
|
2783
2999
|
touches.push(child.name.getText(sourceFile));
|
|
2784
|
-
if (
|
|
3000
|
+
if (ts19.isPropertyAccessExpression(child)) {
|
|
2785
3001
|
const root = getAccessRoot(child);
|
|
2786
3002
|
if (root === "st")
|
|
2787
3003
|
touches.push("st");
|
|
@@ -2794,7 +3010,7 @@ class SsrScanner {
|
|
|
2794
3010
|
#getTagNames(sourceFile, node) {
|
|
2795
3011
|
const tags = new Set;
|
|
2796
3012
|
SsrScanner.#walk(node, (child) => {
|
|
2797
|
-
if (
|
|
3013
|
+
if (ts19.isJsxOpeningElement(child) || ts19.isJsxSelfClosingElement(child))
|
|
2798
3014
|
tags.add(child.tagName.getText(sourceFile).split(".")[0]);
|
|
2799
3015
|
});
|
|
2800
3016
|
return tags;
|
|
@@ -2802,7 +3018,7 @@ class SsrScanner {
|
|
|
2802
3018
|
#getMass(node) {
|
|
2803
3019
|
let mass = 0;
|
|
2804
3020
|
SsrScanner.#walk(node, (child) => {
|
|
2805
|
-
if (
|
|
3021
|
+
if (ts19.isJsxOpeningElement(child) || ts19.isJsxSelfClosingElement(child))
|
|
2806
3022
|
mass += 1;
|
|
2807
3023
|
});
|
|
2808
3024
|
return mass;
|
|
@@ -2810,30 +3026,30 @@ class SsrScanner {
|
|
|
2810
3026
|
static #walk(node, visit) {
|
|
2811
3027
|
const walk = (child) => {
|
|
2812
3028
|
visit(child);
|
|
2813
|
-
|
|
3029
|
+
ts19.forEachChild(child, walk);
|
|
2814
3030
|
};
|
|
2815
|
-
|
|
3031
|
+
ts19.forEachChild(node, walk);
|
|
2816
3032
|
}
|
|
2817
3033
|
#hasUseClient(sourceFile) {
|
|
2818
3034
|
const first = sourceFile.statements[0];
|
|
2819
|
-
if (!first || !
|
|
3035
|
+
if (!first || !ts19.isExpressionStatement(first) || !ts19.isStringLiteral(first.expression))
|
|
2820
3036
|
return false;
|
|
2821
3037
|
return first.expression.text === "use client";
|
|
2822
3038
|
}
|
|
2823
3039
|
#hasVendorImport(sourceFile) {
|
|
2824
|
-
return sourceFile.statements.some((statement) =>
|
|
3040
|
+
return sourceFile.statements.some((statement) => ts19.isImportDeclaration(statement) && isVendorSpecifier(getSpecifier(statement)));
|
|
2825
3041
|
}
|
|
2826
3042
|
#getVendorNames(sourceFile) {
|
|
2827
3043
|
const names = new Set;
|
|
2828
3044
|
for (const statement of sourceFile.statements) {
|
|
2829
|
-
if (!
|
|
3045
|
+
if (!ts19.isImportDeclaration(statement) || !isVendorSpecifier(getSpecifier(statement)))
|
|
2830
3046
|
continue;
|
|
2831
3047
|
const clause = statement.importClause;
|
|
2832
3048
|
if (clause?.name)
|
|
2833
3049
|
names.add(clause.name.text);
|
|
2834
|
-
if (clause?.namedBindings &&
|
|
3050
|
+
if (clause?.namedBindings && ts19.isNamespaceImport(clause.namedBindings))
|
|
2835
3051
|
names.add(clause.namedBindings.name.text);
|
|
2836
|
-
if (clause?.namedBindings &&
|
|
3052
|
+
if (clause?.namedBindings && ts19.isNamedImports(clause.namedBindings))
|
|
2837
3053
|
for (const element of clause.namedBindings.elements)
|
|
2838
3054
|
names.add(element.name.text);
|
|
2839
3055
|
}
|
|
@@ -2841,10 +3057,10 @@ class SsrScanner {
|
|
|
2841
3057
|
}
|
|
2842
3058
|
#importsClientRuntime(sourceFile) {
|
|
2843
3059
|
for (const statement of sourceFile.statements) {
|
|
2844
|
-
if (!
|
|
3060
|
+
if (!ts19.isImportDeclaration(statement))
|
|
2845
3061
|
continue;
|
|
2846
3062
|
const bindings = statement.importClause?.namedBindings;
|
|
2847
|
-
if (!bindings || !
|
|
3063
|
+
if (!bindings || !ts19.isNamedImports(bindings))
|
|
2848
3064
|
continue;
|
|
2849
3065
|
if (bindings.elements.some((element) => SsrScanner.#clientRuntimeImports.has(element.name.text)))
|
|
2850
3066
|
return true;
|
|
@@ -2895,7 +3111,7 @@ function getShare(serverMass, clientMass) {
|
|
|
2895
3111
|
return total === 0 ? 1 : serverMass / total;
|
|
2896
3112
|
}
|
|
2897
3113
|
function getSpecifier(statement) {
|
|
2898
|
-
return
|
|
3114
|
+
return ts19.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : "";
|
|
2899
3115
|
}
|
|
2900
3116
|
function isVendorSpecifier(specifier) {
|
|
2901
3117
|
if (specifier === "" || specifier.startsWith(".") || specifier.startsWith("/"))
|
|
@@ -2908,13 +3124,13 @@ function isVendorSpecifier(specifier) {
|
|
|
2908
3124
|
}
|
|
2909
3125
|
function getAccessRoot(node) {
|
|
2910
3126
|
let current = node;
|
|
2911
|
-
while (
|
|
3127
|
+
while (ts19.isPropertyAccessExpression(current))
|
|
2912
3128
|
current = current.expression;
|
|
2913
|
-
return
|
|
3129
|
+
return ts19.isIdentifier(current) ? current.text : "";
|
|
2914
3130
|
}
|
|
2915
3131
|
|
|
2916
|
-
// pkgs/@akanjs/devkit/testOnlyExportScanner.ts
|
|
2917
|
-
import
|
|
3132
|
+
// pkgs/@akanjs/devkit/quality/testOnlyExportScanner.ts
|
|
3133
|
+
import ts20 from "typescript";
|
|
2918
3134
|
|
|
2919
3135
|
class TestOnlyExportScanner {
|
|
2920
3136
|
static rule = "akan.global.test-only-export";
|
|
@@ -2965,9 +3181,9 @@ class TestOnlyExportScanner {
|
|
|
2965
3181
|
static #identifierLinesOf(sourceFile) {
|
|
2966
3182
|
const lines = new Map;
|
|
2967
3183
|
const visit = (node) => {
|
|
2968
|
-
if (
|
|
3184
|
+
if (ts20.isIdentifier(node) && !lines.has(node.text))
|
|
2969
3185
|
lines.set(node.text, sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1);
|
|
2970
|
-
|
|
3186
|
+
ts20.forEachChild(node, visit);
|
|
2971
3187
|
};
|
|
2972
3188
|
visit(sourceFile);
|
|
2973
3189
|
return lines;
|
|
@@ -2984,15 +3200,15 @@ class TestOnlyExportScanner {
|
|
|
2984
3200
|
});
|
|
2985
3201
|
}
|
|
2986
3202
|
static #isNamedExport(statement) {
|
|
2987
|
-
if (!
|
|
3203
|
+
if (!ts20.canHaveModifiers(statement))
|
|
2988
3204
|
return false;
|
|
2989
|
-
const modifiers =
|
|
2990
|
-
return modifiers.some((modifier) => modifier.kind ===
|
|
3205
|
+
const modifiers = ts20.getModifiers(statement) ?? [];
|
|
3206
|
+
return modifiers.some((modifier) => modifier.kind === ts20.SyntaxKind.ExportKeyword) && !modifiers.some((modifier) => modifier.kind === ts20.SyntaxKind.DefaultKeyword);
|
|
2991
3207
|
}
|
|
2992
3208
|
static #declaredNamesOf(statement) {
|
|
2993
|
-
if (
|
|
2994
|
-
return statement.declarationList.declarations.map((declaration) => declaration.name).filter((name) =>
|
|
2995
|
-
if (
|
|
3209
|
+
if (ts20.isVariableStatement(statement))
|
|
3210
|
+
return statement.declarationList.declarations.map((declaration) => declaration.name).filter((name) => ts20.isIdentifier(name));
|
|
3211
|
+
if (ts20.isFunctionDeclaration(statement) || ts20.isClassDeclaration(statement) || ts20.isInterfaceDeclaration(statement) || ts20.isTypeAliasDeclaration(statement) || ts20.isEnumDeclaration(statement))
|
|
2996
3212
|
return statement.name ? [statement.name] : [];
|
|
2997
3213
|
return [];
|
|
2998
3214
|
}
|
|
@@ -3002,17 +3218,17 @@ class TestOnlyExportScanner {
|
|
|
3002
3218
|
const visit = (node) => {
|
|
3003
3219
|
if (used || ownStatements.has(node))
|
|
3004
3220
|
return;
|
|
3005
|
-
if (
|
|
3221
|
+
if (ts20.isIdentifier(node) && node.text === name)
|
|
3006
3222
|
used = true;
|
|
3007
3223
|
else
|
|
3008
|
-
|
|
3224
|
+
ts20.forEachChild(node, visit);
|
|
3009
3225
|
};
|
|
3010
3226
|
visit(sourceFile);
|
|
3011
3227
|
return used;
|
|
3012
3228
|
}
|
|
3013
3229
|
}
|
|
3014
3230
|
|
|
3015
|
-
// pkgs/@akanjs/devkit/qualityScanner.ts
|
|
3231
|
+
// pkgs/@akanjs/devkit/quality/qualityScanner.ts
|
|
3016
3232
|
var MAX_FILE_LINES = 2000;
|
|
3017
3233
|
var PLACEHOLDER_EXPORT_NAMES = new Set([
|
|
3018
3234
|
"aa",
|
|
@@ -3153,7 +3369,7 @@ class AkanQualityScanner {
|
|
|
3153
3369
|
file,
|
|
3154
3370
|
absolutePath,
|
|
3155
3371
|
content,
|
|
3156
|
-
sourceFile:
|
|
3372
|
+
sourceFile: ts21.createSourceFile(file, content, ts21.ScriptTarget.Latest, true, getScriptKind(file))
|
|
3157
3373
|
};
|
|
3158
3374
|
}
|
|
3159
3375
|
async#readTextFile(workspaceRoot, file) {
|
|
@@ -3352,13 +3568,13 @@ function getExportedFunctionLikes(sourceFile) {
|
|
|
3352
3568
|
duplicateNameExempt: nameExempt || isConventionDuplicateNameExempt(sourceFile.file, isEnumClass)
|
|
3353
3569
|
});
|
|
3354
3570
|
for (const statement of sourceFile.sourceFile.statements) {
|
|
3355
|
-
if (
|
|
3571
|
+
if (ts21.isFunctionDeclaration(statement) && statement.name && isExported(statement))
|
|
3356
3572
|
add(statement.name.text, "function", statement, statement.body);
|
|
3357
|
-
if (
|
|
3573
|
+
if (ts21.isClassDeclaration(statement) && statement.name && isExported(statement))
|
|
3358
3574
|
add(statement.name.text, "class", statement, statement, isEnumClassStatement(sourceFile.sourceFile, statement));
|
|
3359
|
-
if (
|
|
3575
|
+
if (ts21.isVariableStatement(statement) && isExported(statement)) {
|
|
3360
3576
|
for (const declaration of statement.declarationList.declarations) {
|
|
3361
|
-
if (!
|
|
3577
|
+
if (!ts21.isIdentifier(declaration.name) || !isFunctionLikeInitializer(declaration.initializer))
|
|
3362
3578
|
continue;
|
|
3363
3579
|
add(declaration.name.text, "function-variable", declaration, declaration.initializer);
|
|
3364
3580
|
}
|
|
@@ -3386,14 +3602,14 @@ function isConventionDuplicateNameExempt(file, isEnumClass) {
|
|
|
3386
3602
|
return false;
|
|
3387
3603
|
}
|
|
3388
3604
|
function isEnumClassStatement(sourceFile, statement) {
|
|
3389
|
-
if (!
|
|
3605
|
+
if (!ts21.isClassDeclaration(statement))
|
|
3390
3606
|
return false;
|
|
3391
|
-
const heritageClause = statement.heritageClauses?.find((clause) => clause.token ===
|
|
3607
|
+
const heritageClause = statement.heritageClauses?.find((clause) => clause.token === ts21.SyntaxKind.ExtendsKeyword);
|
|
3392
3608
|
const expression = heritageClause?.types[0]?.expression;
|
|
3393
3609
|
return !!expression && expression.getText(sourceFile).startsWith("enumOf(");
|
|
3394
3610
|
}
|
|
3395
3611
|
function getExportedClassNames(sourceFile) {
|
|
3396
|
-
return sourceFile.statements.filter((statement) =>
|
|
3612
|
+
return sourceFile.statements.filter((statement) => ts21.isClassDeclaration(statement)).filter((statement) => isExported(statement)).map((statement) => statement.name?.text).filter((name) => !!name);
|
|
3397
3613
|
}
|
|
3398
3614
|
function isComponentDeclarationFile(file) {
|
|
3399
3615
|
if (!file.endsWith(".tsx"))
|
|
@@ -3409,7 +3625,7 @@ function isComponentDeclarationFile(file) {
|
|
|
3409
3625
|
function getComponentFileDeclarations(sourceFile) {
|
|
3410
3626
|
const reExportedNames = new Set;
|
|
3411
3627
|
for (const statement of sourceFile.statements) {
|
|
3412
|
-
if (
|
|
3628
|
+
if (ts21.isExportDeclaration(statement) && statement.exportClause && ts21.isNamedExports(statement.exportClause)) {
|
|
3413
3629
|
for (const element of statement.exportClause.elements)
|
|
3414
3630
|
reExportedNames.add((element.propertyName ?? element.name).text);
|
|
3415
3631
|
}
|
|
@@ -3419,19 +3635,19 @@ function getComponentFileDeclarations(sourceFile) {
|
|
|
3419
3635
|
const isDefaultExport = isDefaultExportStatement(statement);
|
|
3420
3636
|
const inlineExported = isExported(statement);
|
|
3421
3637
|
const add = (name, kind, line) => declarations.push({ name, kind, line, exported: inlineExported || reExportedNames.has(name), isDefaultExport });
|
|
3422
|
-
if (
|
|
3638
|
+
if (ts21.isInterfaceDeclaration(statement))
|
|
3423
3639
|
add(statement.name.text, "interface", getLine(sourceFile, statement));
|
|
3424
|
-
else if (
|
|
3640
|
+
else if (ts21.isTypeAliasDeclaration(statement))
|
|
3425
3641
|
add(statement.name.text, "type", getLine(sourceFile, statement));
|
|
3426
|
-
else if (
|
|
3642
|
+
else if (ts21.isEnumDeclaration(statement))
|
|
3427
3643
|
add(statement.name.text, "enum", getLine(sourceFile, statement));
|
|
3428
|
-
else if (
|
|
3644
|
+
else if (ts21.isFunctionDeclaration(statement) && statement.name)
|
|
3429
3645
|
add(statement.name.text, "function", getLine(sourceFile, statement));
|
|
3430
|
-
else if (
|
|
3646
|
+
else if (ts21.isClassDeclaration(statement) && statement.name)
|
|
3431
3647
|
add(statement.name.text, "class", getLine(sourceFile, statement));
|
|
3432
|
-
else if (
|
|
3648
|
+
else if (ts21.isVariableStatement(statement)) {
|
|
3433
3649
|
for (const declaration of statement.declarationList.declarations) {
|
|
3434
|
-
if (!
|
|
3650
|
+
if (!ts21.isIdentifier(declaration.name))
|
|
3435
3651
|
continue;
|
|
3436
3652
|
const kind = isFunctionLikeInitializer(declaration.initializer) ? "function" : "variable";
|
|
3437
3653
|
add(declaration.name.text, kind, getLine(sourceFile, declaration));
|
|
@@ -3443,15 +3659,15 @@ function getComponentFileDeclarations(sourceFile) {
|
|
|
3443
3659
|
function getCompoundComponentNames(sourceFile) {
|
|
3444
3660
|
const names = new Set;
|
|
3445
3661
|
for (const statement of sourceFile.statements) {
|
|
3446
|
-
if (!
|
|
3662
|
+
if (!ts21.isExpressionStatement(statement))
|
|
3447
3663
|
continue;
|
|
3448
3664
|
const { expression } = statement;
|
|
3449
|
-
if (!
|
|
3665
|
+
if (!ts21.isBinaryExpression(expression) || expression.operatorToken.kind !== ts21.SyntaxKind.EqualsToken)
|
|
3450
3666
|
continue;
|
|
3451
|
-
if (!
|
|
3667
|
+
if (!ts21.isPropertyAccessExpression(expression.left) || !isPascalCaseName(expression.left.name.text))
|
|
3452
3668
|
continue;
|
|
3453
3669
|
names.add(expression.left.name.text);
|
|
3454
|
-
if (
|
|
3670
|
+
if (ts21.isIdentifier(expression.right) && isPascalCaseName(expression.right.text))
|
|
3455
3671
|
names.add(expression.right.text);
|
|
3456
3672
|
}
|
|
3457
3673
|
return names;
|
|
@@ -3471,11 +3687,11 @@ function isPascalCaseName(name) {
|
|
|
3471
3687
|
return /^[A-Z]/.test(name) && !/^[A-Z0-9_]+$/.test(name);
|
|
3472
3688
|
}
|
|
3473
3689
|
function isDefaultExportStatement(statement) {
|
|
3474
|
-
if (
|
|
3690
|
+
if (ts21.isExportAssignment(statement))
|
|
3475
3691
|
return !statement.isExportEquals;
|
|
3476
|
-
if (!
|
|
3692
|
+
if (!ts21.canHaveModifiers(statement))
|
|
3477
3693
|
return false;
|
|
3478
|
-
return !!
|
|
3694
|
+
return !!ts21.getModifiers(statement)?.some((modifier) => modifier.kind === ts21.SyntaxKind.DefaultKeyword);
|
|
3479
3695
|
}
|
|
3480
3696
|
function getBangCommentWarnings(sourceFile) {
|
|
3481
3697
|
if (!isClientReachableFile(sourceFile.file))
|
|
@@ -3511,11 +3727,11 @@ function getGlobalMutationWarnings(sourceFile) {
|
|
|
3511
3727
|
const warnings = [];
|
|
3512
3728
|
for (const statement of sourceFile.sourceFile.statements) {
|
|
3513
3729
|
const warn = (rule, message) => warnings.push(fileWarning(rule, "file", sourceFile.file, message, getLine(sourceFile.sourceFile, statement)));
|
|
3514
|
-
if (
|
|
3730
|
+
if (ts21.isModuleDeclaration(statement) && statement.name.getText(sourceFile.sourceFile) === "global")
|
|
3515
3731
|
warn("akan.file.global-declaration", "Global declarations require an explicit low-level integration allowlist.");
|
|
3516
|
-
if (
|
|
3732
|
+
if (ts21.isInterfaceDeclaration(statement) && statement.name.text === "Window")
|
|
3517
3733
|
warn("akan.file.window-augmentation", "Window augmentation should be isolated to approved browser integration files.");
|
|
3518
|
-
if (
|
|
3734
|
+
if (ts21.isExpressionStatement(statement) && statement.expression.getText(sourceFile.sourceFile).includes(".prototype."))
|
|
3519
3735
|
warn("akan.file.prototype-mutation", "Prototype mutation should be avoided or isolated to approved low-level integration files.");
|
|
3520
3736
|
}
|
|
3521
3737
|
return warnings;
|
|
@@ -3532,19 +3748,19 @@ function getTopLevelDeclaration(sourceFile, statement) {
|
|
|
3532
3748
|
exported: isExported(statement),
|
|
3533
3749
|
node: statement
|
|
3534
3750
|
});
|
|
3535
|
-
if (
|
|
3751
|
+
if (ts21.isClassDeclaration(statement) && statement.name)
|
|
3536
3752
|
return [declared(statement.name.text, "class")];
|
|
3537
|
-
if (
|
|
3753
|
+
if (ts21.isFunctionDeclaration(statement) && statement.name)
|
|
3538
3754
|
return [declared(statement.name.text, "function")];
|
|
3539
|
-
if (
|
|
3755
|
+
if (ts21.isInterfaceDeclaration(statement))
|
|
3540
3756
|
return [declared(statement.name.text, "interface")];
|
|
3541
|
-
if (
|
|
3757
|
+
if (ts21.isTypeAliasDeclaration(statement))
|
|
3542
3758
|
return [declared(statement.name.text, "type")];
|
|
3543
|
-
if (
|
|
3759
|
+
if (ts21.isEnumDeclaration(statement))
|
|
3544
3760
|
return [declared(statement.name.text, "enum")];
|
|
3545
|
-
if (
|
|
3546
|
-
return statement.declarationList.declarations.filter((declaration) =>
|
|
3547
|
-
if (
|
|
3761
|
+
if (ts21.isVariableStatement(statement))
|
|
3762
|
+
return statement.declarationList.declarations.filter((declaration) => ts21.isIdentifier(declaration.name)).map((declaration) => declared(declaration.name.text, "variable", getLine(sourceFile, declaration)));
|
|
3763
|
+
if (ts21.isExportDeclaration(statement))
|
|
3548
3764
|
return [{ name: "export declaration", kind: "export", line, exported: true, node: statement }];
|
|
3549
3765
|
return [];
|
|
3550
3766
|
}
|
|
@@ -3632,13 +3848,13 @@ function getModuleInfo(file) {
|
|
|
3632
3848
|
return { moduleName, fileName, kind: "database" };
|
|
3633
3849
|
}
|
|
3634
3850
|
function isExportedConst(declaration) {
|
|
3635
|
-
return declaration.exported &&
|
|
3851
|
+
return declaration.exported && ts21.isVariableStatement(declaration.node) && (declaration.node.declarationList.flags & ts21.NodeFlags.Const) !== 0;
|
|
3636
3852
|
}
|
|
3637
3853
|
function isExported(node) {
|
|
3638
|
-
return !!(
|
|
3854
|
+
return !!(ts21.getCombinedModifierFlags(node) & ts21.ModifierFlags.Export);
|
|
3639
3855
|
}
|
|
3640
3856
|
function isFunctionLikeInitializer(node) {
|
|
3641
|
-
return !!node && (
|
|
3857
|
+
return !!node && (ts21.isArrowFunction(node) || ts21.isFunctionExpression(node));
|
|
3642
3858
|
}
|
|
3643
3859
|
function getBodyFingerprint(sourceFile, node) {
|
|
3644
3860
|
if (!node)
|
|
@@ -3660,7 +3876,7 @@ async function isDirectory(absolutePath) {
|
|
|
3660
3876
|
}
|
|
3661
3877
|
}
|
|
3662
3878
|
function getScriptKind(file) {
|
|
3663
|
-
return file.endsWith(".tsx") ?
|
|
3879
|
+
return file.endsWith(".tsx") ? ts21.ScriptKind.TSX : ts21.ScriptKind.TS;
|
|
3664
3880
|
}
|
|
3665
3881
|
function getLine(sourceFile, node) {
|
|
3666
3882
|
return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
|