@akanjs/cli 3.2.0-rc.9 → 3.2.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.build-stamp +2 -2
- package/CodeAgent-xdw73nbz.js +11 -0
- package/{CodeTui-qstk5vpj.js → CodeTui-0gewm71c.js} +822 -666
- package/README.ko.md +7 -0
- package/README.md +7 -0
- package/TunnelShare-cccfdgbm.js +16 -0
- package/agent.command-g1mj34wz.js +59 -0
- package/akanCode.js +12 -12
- package/appExecutor-rrx10jya.js +11 -0
- package/{application.command-m4rq4wc2.js → application.command-3w4v7t40.js} +84 -40
- package/{applicationBuildRunner-df7rx3ra.js → applicationBuildRunner-y5xbetyz.js} +51 -20
- package/buildBatch.proc.js +31 -16
- package/{cloud.command-a0gy0qq2.js → cloud.command-ph0rz6sw.js} +28 -29
- package/cloud.script-8bs9tp4j.js +30 -0
- package/{code.command-5rsdqw8s.js → code.command-9b967qpg.js} +13 -9
- package/context.command-ndzs5rbf.js +62 -0
- package/context.runner-bmstpng2.js +32 -0
- package/csrArtifactBuilder-gtvff6k7.js +10 -0
- package/{index-qd7xn2bk.js → dependencyScanner-93g8tk0r.js} +7 -6
- package/{devTui-h77zrjv5.js → devTui-rf374y2w.js} +1 -1
- package/{fileSys-zpvt5gtf.js → fileSys-e5mwt73x.js} +1 -1
- package/frameworkGraph-aneq2nwy.js +8 -0
- package/{guideline.command-mffxknbr.js → guideline.command-y8qz9kxy.js} +9 -5
- package/guidelines/agentRule/agentRule.instruction.md +25 -9
- package/guidelines/akanApi/akanApi.instruction.md +6 -4
- package/guidelines/conventions/core.md +23 -5
- package/guidelines/conventions/rules/app.md +4 -1
- package/guidelines/conventions/rules/page.md +5 -4
- package/guidelines/conventions/rules/ts.md +3 -3
- package/guidelines/errorCodes/errorCodes.instruction.md +165 -0
- package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
- package/guidelines/mcpRule/mcpRule.instruction.md +225 -5
- package/guidelines/pageRule/pageRule.instruction.md +10 -1
- package/guidelines/queryRule/queryRule.instruction.md +3 -1
- package/guidelines/runtimeRule/runtimeRule.instruction.md +14 -8
- package/guidelines/transportRule/transportRule.instruction.md +31 -1
- package/incrementalBuilder.proc.js +609 -437
- package/{index-skmtj8rm.js → index-02v45hh9.js} +27 -10
- package/{index-j6gc8n14.js → index-0csk6jqm.js} +11 -9
- package/{index-2r9ff9qm.js → index-0wa5z6rm.js} +2 -2
- package/{index-nmvhjn8c.js → index-0z8sbdme.js} +93 -82
- package/{index-2vgv7fs7.js → index-1c2807kg.js} +727 -693
- package/{index-hj6w4ka1.js → index-1p81ecbz.js} +1 -1
- package/{index-2mf1aen9.js → index-1p9bxjmt.js} +2 -2
- package/{index-an76bdrv.js → index-2kh4xj3m.js} +1 -1
- package/{index-99qvtff2.js → index-2vn0m9z5.js} +5 -5
- package/{index-rp4yf32g.js → index-3569fr49.js} +36 -29
- package/{index-xvk2a75m.js → index-38x8ynrx.js} +25 -25
- package/{index-cmg5ngqa.js → index-3fmzz9sf.js} +20 -20
- package/{index-rfzp4pqs.js → index-45aprybg.js} +3 -3
- package/{index-k92x3vne.js → index-4a1n0nym.js} +1 -1
- package/{index-ra9fvn7s.js → index-4zgm54wf.js} +76 -40
- package/{index-exn38bzx.js → index-652f3bs8.js} +116 -54
- package/{index-grxs6fts.js → index-6gepp8yn.js} +57 -31
- package/{index-vm0dn0mt.js → index-6j351de4.js} +294 -157
- package/{index-w15mg3km.js → index-7ssr7wq4.js} +1 -1
- package/{index-gxav1bjz.js → index-82cmbpxc.js} +9 -9
- package/{index-2mrn1mrg.js → index-9f3reh2y.js} +1 -1
- package/{index-gcx48get.js → index-9rymt8d6.js} +2 -2
- package/{index-swwjakt0.js → index-ankyx6dj.js} +14 -18
- package/{index-28x1aszt.js → index-b0t92k71.js} +154 -58
- package/index-b372rck5.js +799 -0
- package/{index-yf9wc28h.js → index-bejy9zyc.js} +1 -1
- package/{index-r0a604h4.js → index-c669pbyb.js} +5 -4
- package/{index-xyn02k0w.js → index-cm9rb480.js} +662 -433
- package/{index-j9790rhk.js → index-d0n78fzc.js} +1635 -1139
- package/{index-hqv34wzq.js → index-dr1carpr.js} +10 -10
- package/index-f2arv0mv.js +30 -0
- package/{index-5radqwn2.js → index-gtydr9qc.js} +12 -12
- package/{index-j6eeh5d7.js → index-j3fqs8rc.js} +5 -5
- package/{index-yckz5t8b.js → index-jdw9m5c4.js} +516 -434
- package/{index-ny2k80mv.js → index-jf4vk1s0.js} +9 -2
- package/{index-x40bdsca.js → index-jg5rwrf7.js} +77 -115
- package/{index-5zwr4n6k.js → index-ktxdfqg5.js} +65 -8
- package/index-mnhrqjjq.js +127 -0
- package/{index-3ghdb7p5.js → index-pc42gxa5.js} +2777 -3676
- package/{index-0hbtve0a.js → index-q8h4eg5y.js} +32 -28
- package/{index-j3v29pq7.js → index-qh81drde.js} +219 -175
- package/{index-b4qq3rq0.js → index-rwgqba9p.js} +1 -1
- package/{index-w8yasvpc.js → index-scfsqen7.js} +2136 -2175
- package/{index-9p260r4e.js → index-trffs83s.js} +538 -250
- package/{index-0gg15zwa.js → index-twjgmryg.js} +6 -6
- package/index-whvhsb5f.js +80 -0
- package/{index-h7hehkw6.js → index-xczjdng6.js} +3 -1
- package/{index-39jz41jb.js → index-xs9a3ddt.js} +3 -3
- package/{index-35j83zkd.js → index-xv3pvdw4.js} +2 -2
- package/{index-34792nh7.js → index-y2g0s9tn.js} +1 -1
- package/{index-43f4h4cm.js → index-ymgsvhc5.js} +7 -8
- package/{index-ygdbn9jn.js → index-zyb0ebm4.js} +1 -1
- package/{index-bns3wcpc.js → index-zyjztrvc.js} +2 -2
- package/index.js +30 -24
- package/libExecutor-nstr00s7.js +10 -0
- package/{library.command-bmd7zc5m.js → library.command-b02aw1hm.js} +12 -5
- package/{localRegistry.command-y6en1599.js → localRegistry.command-3hg1p4aj.js} +24 -24
- package/{module.command-7exfffqw.js → module.command-bd9gz6cv.js} +11 -7
- package/{package.command-adskw2rj.js → package.command-xmr0mxze.js} +11 -10
- package/package.json +8 -8
- package/{page.command-dw01272p.js → page.command-x94qf58g.js} +8 -4
- package/{pipeline.command-0b1r3y5r.js → pipeline.command-n2843k6t.js} +15 -9
- package/pkgExecutor-cka27e3c.js +10 -0
- package/{primitive.command-byw6vc04.js → primitive.command-cs7v376h.js} +12 -8
- package/{projectTypecheck-kkrpq60a.js → projectTypecheck-za2n3nbr.js} +1 -1
- package/{prompter-qrwx1p17.js → prompter-d33wmdpa.js} +2 -2
- package/{quality.command-6rqnhzct.js → quality.command-nqngh1jd.js} +25 -16
- package/{recipeScanner-4b69ybe0.js → recipeScanner-rrx69awy.js} +1 -1
- package/{repair.command-rw5zymak.js → repair.command-v2medwsm.js} +12 -8
- package/{routeSourceValidator-4h947v7c.js → routeSourceValidator-8n6j1vn7.js} +4 -2
- package/{scalar.command-2dyp9nh9.js → scalar.command-61cjmxn1.js} +10 -6
- package/skills/akan-debug/SKILL.md +8 -5
- package/skills/akan-err/SKILL.md +7 -0
- package/skills/akan-mcp/SKILL.md +19 -1
- package/skills/akan-scaffold/SKILL.md +1 -1
- package/skills/akan-validate/SKILL.md +3 -3
- package/{subspace.command-111ynwv1.js → subspace.command-dtv8nfh7.js} +30 -24
- package/templates/app/page/_layout.tsx +13 -0
- package/templates/app/page/styles.css.template +40 -0
- package/templates/appSample/page/_index.tsx +9 -9
- package/templates/appSample/page/_layout.tsx +1 -0
- package/templates/appSample/page/styles.css.template +40 -5
- package/templates/appSample/ui/Recipe/jellyButton.ts +1 -1
- 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/.devcontainer/devcontainer.json.template +1 -1
- package/templates/workspaceRoot/AGENTS.md.template +2 -1
- package/templates/workspaceRoot/README.ts +4 -2
- package/{tunnel.command-2gcpfbdj.js → tunnel.command-fmwm5fgb.js} +15 -13
- package/{typeChecker-s640r6c0.js → typeChecker-7jt6abrs.js} +1 -1
- package/typecheck.proc.js +3 -2
- package/{verify.command-djgs86ma.js → verify.command-4f260t53.js} +19 -17
- package/{workflow.command-n0k2mxr5.js → workflow.command-tm5q9xsm.js} +21 -14
- package/{workspace.command-fh1qwxfx.js → workspace.command-75gc280j.js} +56 -54
- package/CodeAgent-x2p3a3e0.js +0 -11
- package/TunnelShare-c4xsfzg5.js +0 -15
- package/agent.command-9et2e27p.js +0 -52
- package/cloud.script-xze4zh7n.js +0 -31
- package/context.command-rk1dwrg4.js +0 -57
- package/context.runner-83ky5m1b.js +0 -30
- package/dependencyScanner-78sq8m4q.js +0 -8
- /package/templates/{appSample → app}/public/fonts/Pretendard-Bold.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-Medium.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-Regular.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-SemiBold.woff2 +0 -0
|
@@ -2,26 +2,34 @@
|
|
|
2
2
|
import {
|
|
3
3
|
camelToKebabCase,
|
|
4
4
|
runner
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-652f3bs8.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-pc42gxa5.js";
|
|
20
|
+
import {
|
|
21
|
+
FileSys2
|
|
22
|
+
} from "./index-zyjztrvc.js";
|
|
23
|
+
import {
|
|
24
|
+
LibExecutor2
|
|
25
|
+
} from "./index-f2arv0mv.js";
|
|
26
|
+
import {
|
|
27
|
+
PkgExecutor2
|
|
28
|
+
} from "./index-mnhrqjjq.js";
|
|
29
|
+
import {
|
|
30
|
+
collectRecipeSources2,
|
|
31
|
+
scanRecipes2
|
|
32
|
+
} from "./index-1p81ecbz.js";
|
|
25
33
|
import {
|
|
26
34
|
countBlocking,
|
|
27
35
|
formatStyleContract,
|
|
@@ -29,22 +37,18 @@ 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-ktxdfqg5.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-trffs83s.js";
|
|
44
48
|
import {
|
|
45
49
|
getNpmRegistryUrl,
|
|
46
50
|
getLatestPackageVersion
|
|
47
|
-
} from "./index-
|
|
51
|
+
} from "./index-jf4vk1s0.js";
|
|
48
52
|
import {
|
|
49
53
|
sysInputs,
|
|
50
54
|
workflowSpecs
|
|
@@ -55,27 +59,119 @@ 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;
|
|
@@ -1666,7 +1881,7 @@ class WorkspaceRunner extends runner("workspace") {
|
|
|
1666
1881
|
dryRun: true
|
|
1667
1882
|
});
|
|
1668
1883
|
const writes = [
|
|
1669
|
-
...planned.map((file) => path5.relative(fsRoot, file.filePath)),
|
|
1884
|
+
...planned.map((file) => path5.relative(fsRoot, file.filePath).replaceAll(path5.sep, "/")),
|
|
1670
1885
|
...normalizedRegistryUrl ? [".npmrc"] : [],
|
|
1671
1886
|
`apps/${appName}`,
|
|
1672
1887
|
...libs.map((libName) => `libs/${libName}`)
|
|
@@ -1745,7 +1960,7 @@ class WorkspaceRunner extends runner("workspace") {
|
|
|
1745
1960
|
const root = workspace.workspaceRoot;
|
|
1746
1961
|
const outer = (await WorkspaceRunner.#git(root, ["rev-parse", "--show-toplevel"]))?.trim();
|
|
1747
1962
|
if (outer && await WorkspaceRunner.#git(root, ["check-ignore", "-q", path5.join(root, "package.json")]) === null)
|
|
1748
|
-
return { committed: false, repository: outer };
|
|
1963
|
+
return { committed: false, repository: path5.resolve(outer) };
|
|
1749
1964
|
const known = await Promise.all(["GIT_AUTHOR_IDENT", "GIT_COMMITTER_IDENT"].map((ident) => WorkspaceRunner.#git(root, ["var", ident])));
|
|
1750
1965
|
const identity = known.every((ident) => ident !== null) ? undefined : WorkspaceRunner.fallbackGitIdentity;
|
|
1751
1966
|
await workspace.commit("Initial commit", { init: true, ...identity ? { identity } : {} });
|
|
@@ -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,22 @@ 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
|
-
import {
|
|
1951
|
-
import
|
|
2165
|
+
import { readFile as readFile4 } from "fs/promises";
|
|
2166
|
+
import path10 from "path";
|
|
1952
2167
|
import { RESERVED_ROUTE_CONFIG_EXPORTS } from "akanjs/common";
|
|
1953
|
-
import
|
|
1954
|
-
import ts20 from "typescript";
|
|
2168
|
+
import ts22 from "typescript";
|
|
1955
2169
|
|
|
1956
|
-
// pkgs/@akanjs/devkit/commentDensityScanner.ts
|
|
2170
|
+
// pkgs/@akanjs/devkit/quality/commentDensityScanner.ts
|
|
1957
2171
|
import path6 from "path";
|
|
1958
|
-
import
|
|
2172
|
+
import ts15 from "typescript";
|
|
1959
2173
|
|
|
1960
|
-
// pkgs/@akanjs/devkit/sourceComments.ts
|
|
1961
|
-
import
|
|
2174
|
+
// pkgs/@akanjs/devkit/quality/sourceComments.ts
|
|
2175
|
+
import ts14 from "typescript";
|
|
1962
2176
|
|
|
1963
2177
|
class SourceComments {
|
|
1964
|
-
static #scanner =
|
|
2178
|
+
static #scanner = ts14.createScanner(ts14.ScriptTarget.Latest, false);
|
|
1965
2179
|
static of(sourceFile) {
|
|
1966
2180
|
const comments = [];
|
|
1967
2181
|
const scanGap = (start, end) => {
|
|
@@ -1969,22 +2183,22 @@ class SourceComments {
|
|
|
1969
2183
|
return;
|
|
1970
2184
|
const scanner = SourceComments.#scanner;
|
|
1971
2185
|
scanner.setText(sourceFile.text, start, end - start);
|
|
1972
|
-
for (let kind = scanner.scan();kind !==
|
|
1973
|
-
if (kind !==
|
|
2186
|
+
for (let kind = scanner.scan();kind !== ts14.SyntaxKind.EndOfFileToken; kind = scanner.scan()) {
|
|
2187
|
+
if (kind !== ts14.SyntaxKind.SingleLineCommentTrivia && kind !== ts14.SyntaxKind.MultiLineCommentTrivia)
|
|
1974
2188
|
continue;
|
|
1975
2189
|
comments.push(SourceComments.#commentOf(sourceFile, scanner.getTokenStart(), scanner.getTokenText()));
|
|
1976
2190
|
}
|
|
1977
2191
|
scanner.setText(undefined);
|
|
1978
2192
|
};
|
|
1979
2193
|
const visit = (node) => {
|
|
1980
|
-
if (node.kind ===
|
|
2194
|
+
if (node.kind === ts14.SyntaxKind.JsxText)
|
|
1981
2195
|
return;
|
|
1982
|
-
if (
|
|
2196
|
+
if (ts14.isToken(node)) {
|
|
1983
2197
|
scanGap(node.pos, node.getStart(sourceFile));
|
|
1984
2198
|
return;
|
|
1985
2199
|
}
|
|
1986
2200
|
const children = [];
|
|
1987
|
-
|
|
2201
|
+
ts14.forEachChild(node, (child) => {
|
|
1988
2202
|
children.push(child);
|
|
1989
2203
|
}, (nodes) => {
|
|
1990
2204
|
children.push(...nodes);
|
|
@@ -2015,7 +2229,7 @@ class SourceComments {
|
|
|
2015
2229
|
}
|
|
2016
2230
|
}
|
|
2017
2231
|
|
|
2018
|
-
// pkgs/@akanjs/devkit/commentDensityScanner.ts
|
|
2232
|
+
// pkgs/@akanjs/devkit/quality/commentDensityScanner.ts
|
|
2019
2233
|
class CommentDensityScanner {
|
|
2020
2234
|
static rule = "akan.comment.density";
|
|
2021
2235
|
static maxShare = 0.01;
|
|
@@ -2087,11 +2301,11 @@ class CommentDensityScanner {
|
|
|
2087
2301
|
static #isMeasured({ file, sourceFile }) {
|
|
2088
2302
|
if (/\.(test|spec)\.tsx?$/.test(file) || path6.basename(file) === "guards.ts")
|
|
2089
2303
|
return false;
|
|
2090
|
-
return !sourceFile.statements.every((statement) =>
|
|
2304
|
+
return !sourceFile.statements.every((statement) => ts15.isExportDeclaration(statement) || ts15.isExpressionStatement(statement) && ts15.isStringLiteral(statement.expression));
|
|
2091
2305
|
}
|
|
2092
2306
|
}
|
|
2093
2307
|
|
|
2094
|
-
// pkgs/@akanjs/devkit/deprecatedCommentScanner.ts
|
|
2308
|
+
// pkgs/@akanjs/devkit/quality/deprecatedCommentScanner.ts
|
|
2095
2309
|
class DeprecatedCommentScanner {
|
|
2096
2310
|
static rule = "akan.comment.deprecated-marker";
|
|
2097
2311
|
static #marker = /^[!?*\s]*(?:(?:TODO|FIXME|XXX|NOTE)\b\s*:?\s*)?@?deprecated\b/i;
|
|
@@ -2113,9 +2327,9 @@ class DeprecatedCommentScanner {
|
|
|
2113
2327
|
}
|
|
2114
2328
|
}
|
|
2115
2329
|
|
|
2116
|
-
// pkgs/@akanjs/devkit/formSetterScanner.ts
|
|
2330
|
+
// pkgs/@akanjs/devkit/quality/formSetterScanner.ts
|
|
2117
2331
|
import { capitalize, formSetterNames } from "akanjs/common";
|
|
2118
|
-
import
|
|
2332
|
+
import ts16 from "typescript";
|
|
2119
2333
|
|
|
2120
2334
|
class FormSetterScanner {
|
|
2121
2335
|
static #constantPath = /(?:^|\/)lib\/([^_/][^/]*)\/\1\.constant\.ts$/;
|
|
@@ -2134,7 +2348,7 @@ class FormSetterScanner {
|
|
|
2134
2348
|
const fullModelClasses = new Set([`${className}Input`, `${className}Object`, `Light${className}`, className]);
|
|
2135
2349
|
const keys = new Set(FormSetterScanner.#baseFields);
|
|
2136
2350
|
for (const statement of sourceFile.statements)
|
|
2137
|
-
if (
|
|
2351
|
+
if (ts16.isClassDeclaration(statement) && statement.name && fullModelClasses.has(statement.name.text))
|
|
2138
2352
|
for (const key of FormSetterScanner.#viaFieldKeysOf(statement))
|
|
2139
2353
|
keys.add(key);
|
|
2140
2354
|
for (const key of keys)
|
|
@@ -2143,33 +2357,33 @@ class FormSetterScanner {
|
|
|
2143
2357
|
return setters;
|
|
2144
2358
|
}
|
|
2145
2359
|
static #viaFieldKeysOf(declaration) {
|
|
2146
|
-
const via = declaration.heritageClauses?.find((clause) => clause.token ===
|
|
2147
|
-
if (!via || !
|
|
2360
|
+
const via = declaration.heritageClauses?.find((clause) => clause.token === ts16.SyntaxKind.ExtendsKeyword)?.types[0]?.expression;
|
|
2361
|
+
if (!via || !ts16.isCallExpression(via))
|
|
2148
2362
|
return [];
|
|
2149
2363
|
return via.arguments.flatMap((argument) => {
|
|
2150
|
-
if (!
|
|
2364
|
+
if (!ts16.isArrowFunction(argument) && !ts16.isFunctionExpression(argument))
|
|
2151
2365
|
return [];
|
|
2152
2366
|
const fields = FormSetterScanner.#returnedObjectOf(argument.body);
|
|
2153
|
-
return (fields?.properties ?? []).flatMap((property) => property.name && (
|
|
2367
|
+
return (fields?.properties ?? []).flatMap((property) => property.name && (ts16.isIdentifier(property.name) || ts16.isStringLiteral(property.name)) ? [property.name.text] : []);
|
|
2154
2368
|
});
|
|
2155
2369
|
}
|
|
2156
2370
|
static #returnedObjectOf(body) {
|
|
2157
2371
|
let expression = body;
|
|
2158
|
-
if (
|
|
2159
|
-
expression = body.statements.find(
|
|
2160
|
-
while (expression && (
|
|
2372
|
+
if (ts16.isBlock(body))
|
|
2373
|
+
expression = body.statements.find(ts16.isReturnStatement)?.expression;
|
|
2374
|
+
while (expression && (ts16.isParenthesizedExpression(expression) || ts16.isAsExpression(expression)))
|
|
2161
2375
|
expression = expression.expression;
|
|
2162
|
-
return expression &&
|
|
2376
|
+
return expression && ts16.isObjectLiteralExpression(expression) ? expression : null;
|
|
2163
2377
|
}
|
|
2164
2378
|
#scanFile({ file, sourceFile }, fieldSetters) {
|
|
2165
2379
|
const wrapped = [];
|
|
2166
2380
|
const visit = (node) => {
|
|
2167
|
-
if (
|
|
2381
|
+
if (ts16.isJsxAttribute(node)) {
|
|
2168
2382
|
const setter = FormSetterScanner.#wrappedSetterOf(node, fieldSetters);
|
|
2169
2383
|
if (setter)
|
|
2170
2384
|
wrapped.push({ setter, line: FormSetterScanner.#lineOf(sourceFile, node) });
|
|
2171
2385
|
}
|
|
2172
|
-
|
|
2386
|
+
ts16.forEachChild(node, visit);
|
|
2173
2387
|
};
|
|
2174
2388
|
visit(sourceFile);
|
|
2175
2389
|
if (!wrapped.length)
|
|
@@ -2188,13 +2402,13 @@ class FormSetterScanner {
|
|
|
2188
2402
|
];
|
|
2189
2403
|
}
|
|
2190
2404
|
static #wrappedSetterOf(attribute, fieldSetters) {
|
|
2191
|
-
if (!
|
|
2405
|
+
if (!ts16.isIdentifier(attribute.name) || !/^on[A-Z]/.test(attribute.name.text))
|
|
2192
2406
|
return null;
|
|
2193
2407
|
const initializer = attribute.initializer;
|
|
2194
|
-
if (!initializer || !
|
|
2408
|
+
if (!initializer || !ts16.isJsxExpression(initializer) || !initializer.expression)
|
|
2195
2409
|
return null;
|
|
2196
2410
|
const handler = initializer.expression;
|
|
2197
|
-
if (!
|
|
2411
|
+
if (!ts16.isArrowFunction(handler) && !ts16.isFunctionExpression(handler))
|
|
2198
2412
|
return null;
|
|
2199
2413
|
if (!handler.parameters.length)
|
|
2200
2414
|
return null;
|
|
@@ -2205,14 +2419,14 @@ class FormSetterScanner {
|
|
|
2205
2419
|
const visit = (current) => {
|
|
2206
2420
|
if (found)
|
|
2207
2421
|
return;
|
|
2208
|
-
if (
|
|
2422
|
+
if (ts16.isCallExpression(current) && ts16.isPropertyAccessExpression(current.expression)) {
|
|
2209
2423
|
const { expression, name } = current.expression;
|
|
2210
|
-
if (
|
|
2424
|
+
if (ts16.isPropertyAccessExpression(expression) && ts16.isIdentifier(expression.expression) && expression.expression.text === "st" && expression.name.text === "do" && fieldSetters.has(name.text)) {
|
|
2211
2425
|
found = name.text;
|
|
2212
2426
|
return;
|
|
2213
2427
|
}
|
|
2214
2428
|
}
|
|
2215
|
-
|
|
2429
|
+
ts16.forEachChild(current, visit);
|
|
2216
2430
|
};
|
|
2217
2431
|
visit(node);
|
|
2218
2432
|
return found;
|
|
@@ -2222,9 +2436,9 @@ class FormSetterScanner {
|
|
|
2222
2436
|
}
|
|
2223
2437
|
}
|
|
2224
2438
|
|
|
2225
|
-
// pkgs/@akanjs/devkit/kindBranchScanner.ts
|
|
2439
|
+
// pkgs/@akanjs/devkit/quality/kindBranchScanner.ts
|
|
2226
2440
|
import path7 from "path";
|
|
2227
|
-
import
|
|
2441
|
+
import ts17 from "typescript";
|
|
2228
2442
|
|
|
2229
2443
|
class KindBranchScanner {
|
|
2230
2444
|
static rule = "akan.global.kind-branch";
|
|
@@ -2232,10 +2446,10 @@ class KindBranchScanner {
|
|
|
2232
2446
|
static #kindName = /(Kind|Type|Mode)$/;
|
|
2233
2447
|
static #kindSubject = /^(kind|type|mode)$|[a-z](Kind|Type|Mode)$/;
|
|
2234
2448
|
static #equalities = new Set([
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2449
|
+
ts17.SyntaxKind.EqualsEqualsEqualsToken,
|
|
2450
|
+
ts17.SyntaxKind.ExclamationEqualsEqualsToken,
|
|
2451
|
+
ts17.SyntaxKind.EqualsEqualsToken,
|
|
2452
|
+
ts17.SyntaxKind.ExclamationEqualsToken
|
|
2239
2453
|
]);
|
|
2240
2454
|
scan(sourceFiles) {
|
|
2241
2455
|
const enums = sourceFiles.flatMap((sourceFile) => KindBranchScanner.#enumsOf(sourceFile));
|
|
@@ -2287,7 +2501,7 @@ class KindBranchScanner {
|
|
|
2287
2501
|
static #sitesIn({ file, sourceFile }, ownersByValue) {
|
|
2288
2502
|
const sites = [];
|
|
2289
2503
|
const record = (literal, subject) => {
|
|
2290
|
-
if (!
|
|
2504
|
+
if (!ts17.isStringLiteralLike(literal) || !ownersByValue.has(literal.text))
|
|
2291
2505
|
return;
|
|
2292
2506
|
if (!KindBranchScanner.#isKindSubject(subject))
|
|
2293
2507
|
return;
|
|
@@ -2298,28 +2512,28 @@ class KindBranchScanner {
|
|
|
2298
2512
|
});
|
|
2299
2513
|
};
|
|
2300
2514
|
const visit = (node) => {
|
|
2301
|
-
if (
|
|
2515
|
+
if (ts17.isBinaryExpression(node) && KindBranchScanner.#equalities.has(node.operatorToken.kind)) {
|
|
2302
2516
|
record(node.left, node.right);
|
|
2303
2517
|
record(node.right, node.left);
|
|
2304
|
-
} else if (
|
|
2518
|
+
} else if (ts17.isCaseClause(node) && ts17.isSwitchStatement(node.parent.parent))
|
|
2305
2519
|
record(node.expression, node.parent.parent.expression);
|
|
2306
|
-
|
|
2520
|
+
ts17.forEachChild(node, visit);
|
|
2307
2521
|
};
|
|
2308
2522
|
visit(sourceFile);
|
|
2309
2523
|
return sites;
|
|
2310
2524
|
}
|
|
2311
2525
|
static #isKindSubject(subject) {
|
|
2312
2526
|
let current = subject;
|
|
2313
|
-
while (
|
|
2527
|
+
while (ts17.isParenthesizedExpression(current) || ts17.isAsExpression(current) || ts17.isNonNullExpression(current))
|
|
2314
2528
|
current = current.expression;
|
|
2315
|
-
const name =
|
|
2529
|
+
const name = ts17.isIdentifier(current) ? current.text : ts17.isPropertyAccessExpression(current) ? current.name.text : ts17.isElementAccessExpression(current) && ts17.isStringLiteralLike(current.argumentExpression) ? current.argumentExpression.text : "";
|
|
2316
2530
|
return KindBranchScanner.#kindSubject.test(name);
|
|
2317
2531
|
}
|
|
2318
2532
|
static #enumsOf({ file, sourceFile }) {
|
|
2319
2533
|
if (!/^(apps|libs)\/[^/]+\/lib\/.+\.constant\.ts$/.test(file))
|
|
2320
2534
|
return [];
|
|
2321
2535
|
return sourceFile.statements.flatMap((statement) => {
|
|
2322
|
-
if (!
|
|
2536
|
+
if (!ts17.isClassDeclaration(statement) || !statement.name)
|
|
2323
2537
|
return [];
|
|
2324
2538
|
if (!KindBranchScanner.#kindName.test(statement.name.text))
|
|
2325
2539
|
return [];
|
|
@@ -2344,22 +2558,22 @@ class KindBranchScanner {
|
|
|
2344
2558
|
static #enumValuesOf(statement) {
|
|
2345
2559
|
for (const clause of statement.heritageClauses ?? [])
|
|
2346
2560
|
for (const { expression } of clause.types) {
|
|
2347
|
-
if (!
|
|
2561
|
+
if (!ts17.isCallExpression(expression) || !ts17.isIdentifier(expression.expression))
|
|
2348
2562
|
continue;
|
|
2349
2563
|
if (expression.expression.text !== "enumOf")
|
|
2350
2564
|
continue;
|
|
2351
2565
|
let list = expression.arguments[1];
|
|
2352
|
-
while (list && (
|
|
2566
|
+
while (list && (ts17.isAsExpression(list) || ts17.isParenthesizedExpression(list)))
|
|
2353
2567
|
list = list.expression;
|
|
2354
|
-
if (!list || !
|
|
2568
|
+
if (!list || !ts17.isArrayLiteralExpression(list))
|
|
2355
2569
|
return null;
|
|
2356
|
-
return list.elements.filter(
|
|
2570
|
+
return list.elements.filter(ts17.isStringLiteralLike).map(({ text }) => text);
|
|
2357
2571
|
}
|
|
2358
2572
|
return null;
|
|
2359
2573
|
}
|
|
2360
2574
|
}
|
|
2361
2575
|
|
|
2362
|
-
// pkgs/@akanjs/devkit/maintainabilityExceptionScanner.ts
|
|
2576
|
+
// pkgs/@akanjs/devkit/quality/maintainabilityExceptionScanner.ts
|
|
2363
2577
|
import { existsSync as existsSync2 } from "fs";
|
|
2364
2578
|
import { readdir, readFile as readFile2 } from "fs/promises";
|
|
2365
2579
|
import path8 from "path";
|
|
@@ -2367,6 +2581,7 @@ class MaintainabilityExceptionScanner {
|
|
|
2367
2581
|
static rule = "akan.baseline.exceptions";
|
|
2368
2582
|
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
2583
|
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.";
|
|
2584
|
+
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
2585
|
async scan(workspaceRoot) {
|
|
2371
2586
|
const sysPaths = await Promise.all(["apps", "libs", "pkgs"].map((sysRoot) => MaintainabilityExceptionScanner.#dirsIn(workspaceRoot, sysRoot)));
|
|
2372
2587
|
const warnings = await Promise.all(sysPaths.flat().map((sysPath) => MaintainabilityExceptionScanner.#scanSys(workspaceRoot, sysPath)));
|
|
@@ -2412,7 +2627,7 @@ class MaintainabilityExceptionScanner {
|
|
|
2412
2627
|
line: locations[0]?.line ?? 1,
|
|
2413
2628
|
message: `${sysPath} carries ${reasonedNum} reasoned exception${reasonedNum === 1 ? "" : "s"} and ${adoptedNum} adopted-debt entr${adoptedNum === 1 ? "y" : "ies"} for ${rule}: ${listed.join(", ")}.`,
|
|
2414
2629
|
locations,
|
|
2415
|
-
fix: MaintainabilityBaseline.reasonedRules.has(rule) ? MaintainabilityExceptionScanner.#shapeFix : MaintainabilityExceptionScanner.#correctnessFix
|
|
2630
|
+
fix: MaintainabilityBaseline.reasonedRules.has(rule) ? MaintainabilityExceptionScanner.#shapeFix : rule === "akan.error.bare-error" ? MaintainabilityExceptionScanner.#bareErrorFix : MaintainabilityExceptionScanner.#correctnessFix
|
|
2416
2631
|
};
|
|
2417
2632
|
}
|
|
2418
2633
|
static #lineOf(lines, rule, key) {
|
|
@@ -2421,11 +2636,11 @@ class MaintainabilityExceptionScanner {
|
|
|
2421
2636
|
}
|
|
2422
2637
|
}
|
|
2423
2638
|
|
|
2424
|
-
// pkgs/@akanjs/devkit/ssrScanner.ts
|
|
2425
|
-
import
|
|
2639
|
+
// pkgs/@akanjs/devkit/quality/ssrScanner.ts
|
|
2640
|
+
import ts19 from "typescript";
|
|
2426
2641
|
|
|
2427
|
-
// pkgs/@akanjs/devkit/renderMutationScanner.ts
|
|
2428
|
-
import
|
|
2642
|
+
// pkgs/@akanjs/devkit/quality/renderMutationScanner.ts
|
|
2643
|
+
import ts18 from "typescript";
|
|
2429
2644
|
|
|
2430
2645
|
class RenderMutationScanner {
|
|
2431
2646
|
static rule = "akan.ssr.render-mutation";
|
|
@@ -2454,7 +2669,7 @@ class RenderMutationScanner {
|
|
|
2454
2669
|
const helper = follow ? RenderMutationScanner.#helperOf(node, functions) : undefined;
|
|
2455
2670
|
if (helper)
|
|
2456
2671
|
helpers.add(helper);
|
|
2457
|
-
|
|
2672
|
+
ts18.forEachChild(node, (child) => visit(child, follow));
|
|
2458
2673
|
};
|
|
2459
2674
|
for (const body of RenderMutationScanner.#renderBodiesOf(sourceFile, functions))
|
|
2460
2675
|
visit(body, true);
|
|
@@ -2471,7 +2686,7 @@ class RenderMutationScanner {
|
|
|
2471
2686
|
}));
|
|
2472
2687
|
}
|
|
2473
2688
|
#isRenderMutation(file, node, fetchNames) {
|
|
2474
|
-
if (!
|
|
2689
|
+
if (!ts18.isCallExpression(node))
|
|
2475
2690
|
return false;
|
|
2476
2691
|
const name = RenderMutationScanner.#endpointOf(node.expression, fetchNames);
|
|
2477
2692
|
if (!name || !this.#mutations.isMutation(file, name))
|
|
@@ -2479,64 +2694,64 @@ class RenderMutationScanner {
|
|
|
2479
2694
|
return !RenderMutationScanner.#optsIn(node, this.#mutations.policyIndexOf(file, name));
|
|
2480
2695
|
}
|
|
2481
2696
|
static #isEventHandler(node) {
|
|
2482
|
-
return
|
|
2697
|
+
return ts18.isJsxAttribute(node) && ts18.isIdentifier(node.name) && /^on[A-Z]/.test(node.name.text);
|
|
2483
2698
|
}
|
|
2484
2699
|
static #endpointOf(callee, fetchNames) {
|
|
2485
|
-
if (
|
|
2700
|
+
if (ts18.isPropertyAccessExpression(callee))
|
|
2486
2701
|
return RenderMutationScanner.#isFetch(callee.expression, fetchNames) ? callee.name.text : null;
|
|
2487
|
-
if (
|
|
2702
|
+
if (ts18.isElementAccessExpression(callee) && ts18.isStringLiteralLike(callee.argumentExpression))
|
|
2488
2703
|
return RenderMutationScanner.#isFetch(callee.expression, fetchNames) ? callee.argumentExpression.text : null;
|
|
2489
2704
|
return null;
|
|
2490
2705
|
}
|
|
2491
2706
|
static #isFetch(expression, fetchNames) {
|
|
2492
|
-
return
|
|
2707
|
+
return ts18.isIdentifier(expression) && fetchNames.has(expression.text);
|
|
2493
2708
|
}
|
|
2494
2709
|
static #optsIn(call, policyIndex) {
|
|
2495
2710
|
if (policyIndex === null)
|
|
2496
2711
|
return false;
|
|
2497
2712
|
const leading = call.arguments.slice(0, policyIndex + 1);
|
|
2498
|
-
if (leading.some((argument) =>
|
|
2713
|
+
if (leading.some((argument) => ts18.isSpreadElement(argument)))
|
|
2499
2714
|
return true;
|
|
2500
2715
|
const policy = leading[policyIndex];
|
|
2501
2716
|
return policy ? RenderMutationScanner.#policyOptsIn(policy) : false;
|
|
2502
2717
|
}
|
|
2503
2718
|
static #policyOptsIn(argument) {
|
|
2504
2719
|
const policy = RenderMutationScanner.#unwrap(argument);
|
|
2505
|
-
if (!
|
|
2720
|
+
if (!ts18.isObjectLiteralExpression(policy))
|
|
2506
2721
|
return !RenderMutationScanner.#cannotBePolicy(policy);
|
|
2507
2722
|
return policy.properties.some((property) => {
|
|
2508
|
-
if (
|
|
2723
|
+
if (ts18.isSpreadAssignment(property))
|
|
2509
2724
|
return true;
|
|
2510
|
-
if (!
|
|
2725
|
+
if (!ts18.isPropertyAssignment(property) && !ts18.isShorthandPropertyAssignment(property))
|
|
2511
2726
|
return false;
|
|
2512
|
-
if (!(
|
|
2727
|
+
if (!(ts18.isIdentifier(property.name) || ts18.isStringLiteral(property.name)))
|
|
2513
2728
|
return false;
|
|
2514
2729
|
if (property.name.text !== "duringRender")
|
|
2515
2730
|
return false;
|
|
2516
|
-
if (
|
|
2731
|
+
if (ts18.isShorthandPropertyAssignment(property))
|
|
2517
2732
|
return true;
|
|
2518
2733
|
const value = RenderMutationScanner.#unwrap(property.initializer);
|
|
2519
|
-
return value.kind !==
|
|
2734
|
+
return value.kind !== ts18.SyntaxKind.FalseKeyword && !(ts18.isIdentifier(value) && value.text === "undefined");
|
|
2520
2735
|
});
|
|
2521
2736
|
}
|
|
2522
2737
|
static #unwrap(expression) {
|
|
2523
2738
|
let current = expression;
|
|
2524
|
-
while (
|
|
2739
|
+
while (ts18.isParenthesizedExpression(current) || ts18.isAsExpression(current) || ts18.isSatisfiesExpression(current) || ts18.isNonNullExpression(current) || ts18.isTypeAssertionExpression(current))
|
|
2525
2740
|
current = current.expression;
|
|
2526
2741
|
return current;
|
|
2527
2742
|
}
|
|
2528
2743
|
static #cannotBePolicy(expression) {
|
|
2529
|
-
if (
|
|
2744
|
+
if (ts18.isIdentifier(expression))
|
|
2530
2745
|
return expression.text === "undefined";
|
|
2531
|
-
return
|
|
2746
|
+
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
2747
|
}
|
|
2533
2748
|
static #fetchBindingsOf(sourceFile) {
|
|
2534
2749
|
const names = new Set;
|
|
2535
2750
|
for (const statement of sourceFile.statements) {
|
|
2536
|
-
if (!
|
|
2751
|
+
if (!ts18.isImportDeclaration(statement) || statement.importClause?.isTypeOnly)
|
|
2537
2752
|
continue;
|
|
2538
2753
|
const bindings = statement.importClause?.namedBindings;
|
|
2539
|
-
if (!bindings || !
|
|
2754
|
+
if (!bindings || !ts18.isNamedImports(bindings))
|
|
2540
2755
|
continue;
|
|
2541
2756
|
for (const element of bindings.elements)
|
|
2542
2757
|
if (!element.isTypeOnly && (element.propertyName ?? element.name).text === "fetch")
|
|
@@ -2547,35 +2762,35 @@ class RenderMutationScanner {
|
|
|
2547
2762
|
static #functionsOf(sourceFile) {
|
|
2548
2763
|
const functions = new Map;
|
|
2549
2764
|
for (const statement of sourceFile.statements) {
|
|
2550
|
-
if (
|
|
2765
|
+
if (ts18.isFunctionDeclaration(statement) && statement.name && statement.body)
|
|
2551
2766
|
functions.set(statement.name.text, statement.body);
|
|
2552
|
-
if (!
|
|
2767
|
+
if (!ts18.isVariableStatement(statement))
|
|
2553
2768
|
continue;
|
|
2554
2769
|
for (const declaration of statement.declarationList.declarations) {
|
|
2555
2770
|
const initializer = declaration.initializer && RenderMutationScanner.#unwrap(declaration.initializer);
|
|
2556
|
-
if (!
|
|
2771
|
+
if (!ts18.isIdentifier(declaration.name) || !initializer)
|
|
2557
2772
|
continue;
|
|
2558
|
-
if (
|
|
2773
|
+
if (ts18.isArrowFunction(initializer) || ts18.isFunctionExpression(initializer))
|
|
2559
2774
|
functions.set(declaration.name.text, initializer.body);
|
|
2560
2775
|
}
|
|
2561
2776
|
}
|
|
2562
2777
|
return functions;
|
|
2563
2778
|
}
|
|
2564
2779
|
static #helperOf(node, functions) {
|
|
2565
|
-
const callee =
|
|
2566
|
-
return callee &&
|
|
2780
|
+
const callee = ts18.isCallExpression(node) ? node.expression : ts18.isJsxSelfClosingElement(node) || ts18.isJsxOpeningElement(node) ? node.tagName : undefined;
|
|
2781
|
+
return callee && ts18.isIdentifier(callee) ? functions.get(callee.text) : undefined;
|
|
2567
2782
|
}
|
|
2568
2783
|
static #renderBodiesOf(sourceFile, functions) {
|
|
2569
2784
|
const bodies = [];
|
|
2570
|
-
const bodyOf = (node) =>
|
|
2785
|
+
const bodyOf = (node) => ts18.isIdentifier(node) ? functions.get(node.text) : node;
|
|
2571
2786
|
const visit = (node) => {
|
|
2572
|
-
if (
|
|
2787
|
+
if (ts18.isCallExpression(node) && ts18.isPropertyAccessExpression(node.expression) && RenderMutationScanner.#stages.has(node.expression.name.text) && RenderMutationScanner.#isRouteChain(node.expression.expression))
|
|
2573
2788
|
for (const argument of node.arguments) {
|
|
2574
2789
|
const body = bodyOf(argument);
|
|
2575
2790
|
if (body)
|
|
2576
2791
|
bodies.push(body);
|
|
2577
2792
|
}
|
|
2578
|
-
|
|
2793
|
+
ts18.forEachChild(node, visit);
|
|
2579
2794
|
};
|
|
2580
2795
|
visit(sourceFile);
|
|
2581
2796
|
for (const statement of sourceFile.statements) {
|
|
@@ -2587,28 +2802,28 @@ class RenderMutationScanner {
|
|
|
2587
2802
|
}
|
|
2588
2803
|
static #isRouteChain(expression) {
|
|
2589
2804
|
let current = expression;
|
|
2590
|
-
while (
|
|
2591
|
-
if (
|
|
2805
|
+
while (ts18.isCallExpression(current)) {
|
|
2806
|
+
if (ts18.isIdentifier(current.expression))
|
|
2592
2807
|
return RenderMutationScanner.#builders.has(current.expression.text);
|
|
2593
|
-
if (!
|
|
2808
|
+
if (!ts18.isPropertyAccessExpression(current.expression))
|
|
2594
2809
|
return false;
|
|
2595
2810
|
current = current.expression.expression;
|
|
2596
2811
|
}
|
|
2597
2812
|
return false;
|
|
2598
2813
|
}
|
|
2599
2814
|
static #legacyPageOf(statement, functions) {
|
|
2600
|
-
if (
|
|
2601
|
-
return statement.modifiers?.some((modifier) => modifier.kind ===
|
|
2602
|
-
if (!
|
|
2815
|
+
if (ts18.isFunctionDeclaration(statement))
|
|
2816
|
+
return statement.modifiers?.some((modifier) => modifier.kind === ts18.SyntaxKind.DefaultKeyword) ? statement.body : undefined;
|
|
2817
|
+
if (!ts18.isExportAssignment(statement))
|
|
2603
2818
|
return;
|
|
2604
2819
|
const expression = RenderMutationScanner.#unwrap(statement.expression);
|
|
2605
|
-
if (
|
|
2820
|
+
if (ts18.isIdentifier(expression))
|
|
2606
2821
|
return functions.get(expression.text);
|
|
2607
|
-
return
|
|
2822
|
+
return ts18.isArrowFunction(expression) || ts18.isFunctionExpression(expression) ? expression.body : undefined;
|
|
2608
2823
|
}
|
|
2609
2824
|
}
|
|
2610
2825
|
|
|
2611
|
-
// pkgs/@akanjs/devkit/ssrScanner.ts
|
|
2826
|
+
// pkgs/@akanjs/devkit/quality/ssrScanner.ts
|
|
2612
2827
|
var STATIC_COMPONENT_MIN_MASS = 4;
|
|
2613
2828
|
var MIXED_COMPONENT_MIN_MASS = 10;
|
|
2614
2829
|
var MIXED_COMPONENT_MAX_TOUCHES = 2;
|
|
@@ -2689,18 +2904,18 @@ class SsrScanner {
|
|
|
2689
2904
|
return warnings;
|
|
2690
2905
|
}
|
|
2691
2906
|
#isMountEffect(sourceFile, node) {
|
|
2692
|
-
if (!
|
|
2907
|
+
if (!ts19.isCallExpression(node))
|
|
2693
2908
|
return false;
|
|
2694
2909
|
const callee = node.expression.getText(sourceFile);
|
|
2695
2910
|
if (callee !== "useEffect" && callee !== "useLayoutEffect")
|
|
2696
2911
|
return false;
|
|
2697
2912
|
const deps = node.arguments[1];
|
|
2698
|
-
return !!deps &&
|
|
2913
|
+
return !!deps && ts19.isArrayLiteralExpression(deps) && deps.elements.length === 0;
|
|
2699
2914
|
}
|
|
2700
2915
|
#getLoadCalls(sourceFile, node) {
|
|
2701
2916
|
const calls = [];
|
|
2702
2917
|
SsrScanner.#walk(node, (child) => {
|
|
2703
|
-
if (!
|
|
2918
|
+
if (!ts19.isCallExpression(child))
|
|
2704
2919
|
return;
|
|
2705
2920
|
const callee = child.expression.getText(sourceFile);
|
|
2706
2921
|
if (/^fetch\.[a-z]/.test(callee) || /^st\.do\.(init|get|view|load|list|count|insight)[A-Z]/.test(callee))
|
|
@@ -2713,7 +2928,7 @@ class SsrScanner {
|
|
|
2713
2928
|
return [];
|
|
2714
2929
|
const warnings = [];
|
|
2715
2930
|
SsrScanner.#walk(sourceFile.sourceFile, (node) => {
|
|
2716
|
-
if (
|
|
2931
|
+
if (ts19.isCallExpression(node) && node.expression.getText(sourceFile.sourceFile) === "useState")
|
|
2717
2932
|
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
2933
|
});
|
|
2719
2934
|
return warnings;
|
|
@@ -2756,14 +2971,14 @@ class SsrScanner {
|
|
|
2756
2971
|
return components;
|
|
2757
2972
|
}
|
|
2758
2973
|
#getComponentNodes(statement) {
|
|
2759
|
-
if (
|
|
2974
|
+
if (ts19.isFunctionDeclaration(statement) && statement.body)
|
|
2760
2975
|
return [{ name: statement.name?.text ?? "default", node: statement.body }];
|
|
2761
|
-
if (!
|
|
2976
|
+
if (!ts19.isVariableStatement(statement))
|
|
2762
2977
|
return [];
|
|
2763
2978
|
return statement.declarationList.declarations.flatMap((declaration) => {
|
|
2764
|
-
if (!
|
|
2979
|
+
if (!ts19.isIdentifier(declaration.name) || !declaration.initializer)
|
|
2765
2980
|
return [];
|
|
2766
|
-
if (!
|
|
2981
|
+
if (!ts19.isArrowFunction(declaration.initializer) && !ts19.isFunctionExpression(declaration.initializer))
|
|
2767
2982
|
return [];
|
|
2768
2983
|
return [{ name: declaration.name.text, node: declaration.initializer }];
|
|
2769
2984
|
});
|
|
@@ -2771,7 +2986,7 @@ class SsrScanner {
|
|
|
2771
2986
|
#getTouches(sourceFile, node) {
|
|
2772
2987
|
const touches = [];
|
|
2773
2988
|
SsrScanner.#walk(node, (child) => {
|
|
2774
|
-
if (
|
|
2989
|
+
if (ts19.isCallExpression(child)) {
|
|
2775
2990
|
const callee = child.expression.getText(sourceFile);
|
|
2776
2991
|
const bareName = callee.split(".").pop() ?? callee;
|
|
2777
2992
|
if (callee === "createContext" || callee === "lazy")
|
|
@@ -2779,9 +2994,9 @@ class SsrScanner {
|
|
|
2779
2994
|
else if (/^use[A-Z]/.test(bareName) && !SsrScanner.#serverSafeCalls.has(bareName))
|
|
2780
2995
|
touches.push(bareName);
|
|
2781
2996
|
}
|
|
2782
|
-
if (
|
|
2997
|
+
if (ts19.isJsxAttribute(child) && /^on[A-Z]/.test(child.name.getText(sourceFile)))
|
|
2783
2998
|
touches.push(child.name.getText(sourceFile));
|
|
2784
|
-
if (
|
|
2999
|
+
if (ts19.isPropertyAccessExpression(child)) {
|
|
2785
3000
|
const root = getAccessRoot(child);
|
|
2786
3001
|
if (root === "st")
|
|
2787
3002
|
touches.push("st");
|
|
@@ -2794,7 +3009,7 @@ class SsrScanner {
|
|
|
2794
3009
|
#getTagNames(sourceFile, node) {
|
|
2795
3010
|
const tags = new Set;
|
|
2796
3011
|
SsrScanner.#walk(node, (child) => {
|
|
2797
|
-
if (
|
|
3012
|
+
if (ts19.isJsxOpeningElement(child) || ts19.isJsxSelfClosingElement(child))
|
|
2798
3013
|
tags.add(child.tagName.getText(sourceFile).split(".")[0]);
|
|
2799
3014
|
});
|
|
2800
3015
|
return tags;
|
|
@@ -2802,7 +3017,7 @@ class SsrScanner {
|
|
|
2802
3017
|
#getMass(node) {
|
|
2803
3018
|
let mass = 0;
|
|
2804
3019
|
SsrScanner.#walk(node, (child) => {
|
|
2805
|
-
if (
|
|
3020
|
+
if (ts19.isJsxOpeningElement(child) || ts19.isJsxSelfClosingElement(child))
|
|
2806
3021
|
mass += 1;
|
|
2807
3022
|
});
|
|
2808
3023
|
return mass;
|
|
@@ -2810,30 +3025,30 @@ class SsrScanner {
|
|
|
2810
3025
|
static #walk(node, visit) {
|
|
2811
3026
|
const walk = (child) => {
|
|
2812
3027
|
visit(child);
|
|
2813
|
-
|
|
3028
|
+
ts19.forEachChild(child, walk);
|
|
2814
3029
|
};
|
|
2815
|
-
|
|
3030
|
+
ts19.forEachChild(node, walk);
|
|
2816
3031
|
}
|
|
2817
3032
|
#hasUseClient(sourceFile) {
|
|
2818
3033
|
const first = sourceFile.statements[0];
|
|
2819
|
-
if (!first || !
|
|
3034
|
+
if (!first || !ts19.isExpressionStatement(first) || !ts19.isStringLiteral(first.expression))
|
|
2820
3035
|
return false;
|
|
2821
3036
|
return first.expression.text === "use client";
|
|
2822
3037
|
}
|
|
2823
3038
|
#hasVendorImport(sourceFile) {
|
|
2824
|
-
return sourceFile.statements.some((statement) =>
|
|
3039
|
+
return sourceFile.statements.some((statement) => ts19.isImportDeclaration(statement) && isVendorSpecifier(getSpecifier(statement)));
|
|
2825
3040
|
}
|
|
2826
3041
|
#getVendorNames(sourceFile) {
|
|
2827
3042
|
const names = new Set;
|
|
2828
3043
|
for (const statement of sourceFile.statements) {
|
|
2829
|
-
if (!
|
|
3044
|
+
if (!ts19.isImportDeclaration(statement) || !isVendorSpecifier(getSpecifier(statement)))
|
|
2830
3045
|
continue;
|
|
2831
3046
|
const clause = statement.importClause;
|
|
2832
3047
|
if (clause?.name)
|
|
2833
3048
|
names.add(clause.name.text);
|
|
2834
|
-
if (clause?.namedBindings &&
|
|
3049
|
+
if (clause?.namedBindings && ts19.isNamespaceImport(clause.namedBindings))
|
|
2835
3050
|
names.add(clause.namedBindings.name.text);
|
|
2836
|
-
if (clause?.namedBindings &&
|
|
3051
|
+
if (clause?.namedBindings && ts19.isNamedImports(clause.namedBindings))
|
|
2837
3052
|
for (const element of clause.namedBindings.elements)
|
|
2838
3053
|
names.add(element.name.text);
|
|
2839
3054
|
}
|
|
@@ -2841,10 +3056,10 @@ class SsrScanner {
|
|
|
2841
3056
|
}
|
|
2842
3057
|
#importsClientRuntime(sourceFile) {
|
|
2843
3058
|
for (const statement of sourceFile.statements) {
|
|
2844
|
-
if (!
|
|
3059
|
+
if (!ts19.isImportDeclaration(statement))
|
|
2845
3060
|
continue;
|
|
2846
3061
|
const bindings = statement.importClause?.namedBindings;
|
|
2847
|
-
if (!bindings || !
|
|
3062
|
+
if (!bindings || !ts19.isNamedImports(bindings))
|
|
2848
3063
|
continue;
|
|
2849
3064
|
if (bindings.elements.some((element) => SsrScanner.#clientRuntimeImports.has(element.name.text)))
|
|
2850
3065
|
return true;
|
|
@@ -2895,7 +3110,7 @@ function getShare(serverMass, clientMass) {
|
|
|
2895
3110
|
return total === 0 ? 1 : serverMass / total;
|
|
2896
3111
|
}
|
|
2897
3112
|
function getSpecifier(statement) {
|
|
2898
|
-
return
|
|
3113
|
+
return ts19.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : "";
|
|
2899
3114
|
}
|
|
2900
3115
|
function isVendorSpecifier(specifier) {
|
|
2901
3116
|
if (specifier === "" || specifier.startsWith(".") || specifier.startsWith("/"))
|
|
@@ -2908,13 +3123,13 @@ function isVendorSpecifier(specifier) {
|
|
|
2908
3123
|
}
|
|
2909
3124
|
function getAccessRoot(node) {
|
|
2910
3125
|
let current = node;
|
|
2911
|
-
while (
|
|
3126
|
+
while (ts19.isPropertyAccessExpression(current))
|
|
2912
3127
|
current = current.expression;
|
|
2913
|
-
return
|
|
3128
|
+
return ts19.isIdentifier(current) ? current.text : "";
|
|
2914
3129
|
}
|
|
2915
3130
|
|
|
2916
|
-
// pkgs/@akanjs/devkit/testOnlyExportScanner.ts
|
|
2917
|
-
import
|
|
3131
|
+
// pkgs/@akanjs/devkit/quality/testOnlyExportScanner.ts
|
|
3132
|
+
import ts20 from "typescript";
|
|
2918
3133
|
|
|
2919
3134
|
class TestOnlyExportScanner {
|
|
2920
3135
|
static rule = "akan.global.test-only-export";
|
|
@@ -2965,9 +3180,9 @@ class TestOnlyExportScanner {
|
|
|
2965
3180
|
static #identifierLinesOf(sourceFile) {
|
|
2966
3181
|
const lines = new Map;
|
|
2967
3182
|
const visit = (node) => {
|
|
2968
|
-
if (
|
|
3183
|
+
if (ts20.isIdentifier(node) && !lines.has(node.text))
|
|
2969
3184
|
lines.set(node.text, sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1);
|
|
2970
|
-
|
|
3185
|
+
ts20.forEachChild(node, visit);
|
|
2971
3186
|
};
|
|
2972
3187
|
visit(sourceFile);
|
|
2973
3188
|
return lines;
|
|
@@ -2984,15 +3199,15 @@ class TestOnlyExportScanner {
|
|
|
2984
3199
|
});
|
|
2985
3200
|
}
|
|
2986
3201
|
static #isNamedExport(statement) {
|
|
2987
|
-
if (!
|
|
3202
|
+
if (!ts20.canHaveModifiers(statement))
|
|
2988
3203
|
return false;
|
|
2989
|
-
const modifiers =
|
|
2990
|
-
return modifiers.some((modifier) => modifier.kind ===
|
|
3204
|
+
const modifiers = ts20.getModifiers(statement) ?? [];
|
|
3205
|
+
return modifiers.some((modifier) => modifier.kind === ts20.SyntaxKind.ExportKeyword) && !modifiers.some((modifier) => modifier.kind === ts20.SyntaxKind.DefaultKeyword);
|
|
2991
3206
|
}
|
|
2992
3207
|
static #declaredNamesOf(statement) {
|
|
2993
|
-
if (
|
|
2994
|
-
return statement.declarationList.declarations.map((declaration) => declaration.name).filter((name) =>
|
|
2995
|
-
if (
|
|
3208
|
+
if (ts20.isVariableStatement(statement))
|
|
3209
|
+
return statement.declarationList.declarations.map((declaration) => declaration.name).filter((name) => ts20.isIdentifier(name));
|
|
3210
|
+
if (ts20.isFunctionDeclaration(statement) || ts20.isClassDeclaration(statement) || ts20.isInterfaceDeclaration(statement) || ts20.isTypeAliasDeclaration(statement) || ts20.isEnumDeclaration(statement))
|
|
2996
3211
|
return statement.name ? [statement.name] : [];
|
|
2997
3212
|
return [];
|
|
2998
3213
|
}
|
|
@@ -3002,17 +3217,85 @@ class TestOnlyExportScanner {
|
|
|
3002
3217
|
const visit = (node) => {
|
|
3003
3218
|
if (used || ownStatements.has(node))
|
|
3004
3219
|
return;
|
|
3005
|
-
if (
|
|
3220
|
+
if (ts20.isIdentifier(node) && node.text === name)
|
|
3006
3221
|
used = true;
|
|
3007
3222
|
else
|
|
3008
|
-
|
|
3223
|
+
ts20.forEachChild(node, visit);
|
|
3009
3224
|
};
|
|
3010
3225
|
visit(sourceFile);
|
|
3011
3226
|
return used;
|
|
3012
3227
|
}
|
|
3013
3228
|
}
|
|
3014
3229
|
|
|
3015
|
-
// pkgs/@akanjs/devkit/
|
|
3230
|
+
// pkgs/@akanjs/devkit/quality/workspaceSourceFiles.ts
|
|
3231
|
+
import { readdir as readdir2, readFile as readFile3, stat } from "fs/promises";
|
|
3232
|
+
import path9 from "path";
|
|
3233
|
+
import ignore from "ignore";
|
|
3234
|
+
import ts21 from "typescript";
|
|
3235
|
+
class WorkspaceSourceFiles {
|
|
3236
|
+
#workspaceRoot;
|
|
3237
|
+
constructor(workspaceRoot) {
|
|
3238
|
+
this.#workspaceRoot = workspaceRoot;
|
|
3239
|
+
}
|
|
3240
|
+
async collect(dirs = ["apps", "libs"]) {
|
|
3241
|
+
const ignoreFilter = ignore().add(await this.#readGitIgnore());
|
|
3242
|
+
const files = new Set;
|
|
3243
|
+
for (const dir of dirs) {
|
|
3244
|
+
const absoluteDir = path9.join(this.#workspaceRoot, dir);
|
|
3245
|
+
if (await WorkspaceSourceFiles.#isDirectory(absoluteDir))
|
|
3246
|
+
await this.#walk(absoluteDir, ignoreFilter, files);
|
|
3247
|
+
}
|
|
3248
|
+
return [...files].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
3249
|
+
}
|
|
3250
|
+
async read(file) {
|
|
3251
|
+
const absolutePath = path9.join(this.#workspaceRoot, file);
|
|
3252
|
+
const content = await readFile3(absolutePath, "utf8");
|
|
3253
|
+
const scriptKind = file.endsWith(".tsx") ? ts21.ScriptKind.TSX : ts21.ScriptKind.TS;
|
|
3254
|
+
return {
|
|
3255
|
+
file,
|
|
3256
|
+
absolutePath,
|
|
3257
|
+
content,
|
|
3258
|
+
sourceFile: ts21.createSourceFile(file, content, ts21.ScriptTarget.Latest, true, scriptKind)
|
|
3259
|
+
};
|
|
3260
|
+
}
|
|
3261
|
+
async#readGitIgnore() {
|
|
3262
|
+
const gitIgnorePath = path9.join(this.#workspaceRoot, ".gitignore");
|
|
3263
|
+
if (!await Bun.file(gitIgnorePath).exists())
|
|
3264
|
+
return [];
|
|
3265
|
+
return (await readFile3(gitIgnorePath, "utf8")).split(/\r?\n/);
|
|
3266
|
+
}
|
|
3267
|
+
async#walk(currentPath, ignoreFilter, files) {
|
|
3268
|
+
const entries = await readdir2(currentPath, { withFileTypes: true });
|
|
3269
|
+
for (const entry of entries) {
|
|
3270
|
+
const absolutePath = path9.join(currentPath, entry.name);
|
|
3271
|
+
const relativePath = path9.relative(this.#workspaceRoot, absolutePath).split(path9.sep).join("/");
|
|
3272
|
+
if (WorkspaceSourceFiles.#shouldSkip(relativePath, entry.isDirectory(), ignoreFilter))
|
|
3273
|
+
continue;
|
|
3274
|
+
if (entry.isDirectory()) {
|
|
3275
|
+
await this.#walk(absolutePath, ignoreFilter, files);
|
|
3276
|
+
continue;
|
|
3277
|
+
}
|
|
3278
|
+
if ((relativePath.endsWith(".ts") || relativePath.endsWith(".tsx")) && !relativePath.endsWith(".d.ts")) {
|
|
3279
|
+
files.add(relativePath);
|
|
3280
|
+
} else if (AbstractDoc.isAbstractPath(relativePath)) {
|
|
3281
|
+
files.add(relativePath);
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
static #shouldSkip(relativePath, isDirectory, ignoreFilter) {
|
|
3286
|
+
const ignorePath = isDirectory ? `${relativePath}/` : relativePath;
|
|
3287
|
+
return relativePath === ".git" || relativePath.includes("/.git/") || relativePath.includes("/node_modules/") || ignoreFilter.ignores(relativePath) || ignoreFilter.ignores(ignorePath);
|
|
3288
|
+
}
|
|
3289
|
+
static async#isDirectory(absolutePath) {
|
|
3290
|
+
try {
|
|
3291
|
+
return (await stat(absolutePath)).isDirectory();
|
|
3292
|
+
} catch {
|
|
3293
|
+
return false;
|
|
3294
|
+
}
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
|
|
3298
|
+
// pkgs/@akanjs/devkit/quality/qualityScanner.ts
|
|
3016
3299
|
var MAX_FILE_LINES = 2000;
|
|
3017
3300
|
var PLACEHOLDER_EXPORT_NAMES = new Set([
|
|
3018
3301
|
"aa",
|
|
@@ -3086,8 +3369,9 @@ function getRuleFix(rule) {
|
|
|
3086
3369
|
|
|
3087
3370
|
class AkanQualityScanner {
|
|
3088
3371
|
async scan(workspaceRoot) {
|
|
3089
|
-
const
|
|
3090
|
-
const
|
|
3372
|
+
const workspaceFiles = new WorkspaceSourceFiles(workspaceRoot);
|
|
3373
|
+
const targetFiles = await workspaceFiles.collect();
|
|
3374
|
+
const sourceFiles = await Promise.all(targetFiles.filter((file) => !AbstractDoc.isAbstractPath(file)).map((file) => workspaceFiles.read(file)));
|
|
3091
3375
|
const abstractFiles = await Promise.all(targetFiles.filter((file) => AbstractDoc.isAbstractPath(file)).map((file) => this.#readTextFile(workspaceRoot, file)));
|
|
3092
3376
|
const ssr = new SsrScanner().scan(sourceFiles);
|
|
3093
3377
|
const warnings = [
|
|
@@ -3111,53 +3395,15 @@ class AkanQualityScanner {
|
|
|
3111
3395
|
suggestedRules: SUGGESTED_RULES
|
|
3112
3396
|
};
|
|
3113
3397
|
}
|
|
3114
|
-
async
|
|
3115
|
-
const
|
|
3116
|
-
const
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
continue;
|
|
3121
|
-
await this.#walkTargetFiles(workspaceRoot, absoluteTargetRoot, ignoreFilter, files);
|
|
3122
|
-
}
|
|
3123
|
-
return files.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
3124
|
-
}
|
|
3125
|
-
async#readGitIgnore(workspaceRoot) {
|
|
3126
|
-
const gitIgnorePath = path9.join(workspaceRoot, ".gitignore");
|
|
3127
|
-
if (!await Bun.file(gitIgnorePath).exists())
|
|
3128
|
-
return [];
|
|
3129
|
-
return (await readFile3(gitIgnorePath, "utf8")).split(/\r?\n/);
|
|
3130
|
-
}
|
|
3131
|
-
async#walkTargetFiles(workspaceRoot, currentPath, ignoreFilter, files) {
|
|
3132
|
-
const entries = await readdir2(currentPath, { withFileTypes: true });
|
|
3133
|
-
for (const entry of entries) {
|
|
3134
|
-
const absolutePath = path9.join(currentPath, entry.name);
|
|
3135
|
-
const relativePath = toPosix(path9.relative(workspaceRoot, absolutePath));
|
|
3136
|
-
if (shouldSkipPath(relativePath, entry.isDirectory(), ignoreFilter))
|
|
3137
|
-
continue;
|
|
3138
|
-
if (entry.isDirectory()) {
|
|
3139
|
-
await this.#walkTargetFiles(workspaceRoot, absolutePath, ignoreFilter, files);
|
|
3140
|
-
continue;
|
|
3141
|
-
}
|
|
3142
|
-
if ((relativePath.endsWith(".ts") || relativePath.endsWith(".tsx")) && !relativePath.endsWith(".d.ts")) {
|
|
3143
|
-
files.push(relativePath);
|
|
3144
|
-
} else if (AbstractDoc.isAbstractPath(relativePath)) {
|
|
3145
|
-
files.push(relativePath);
|
|
3146
|
-
}
|
|
3147
|
-
}
|
|
3148
|
-
}
|
|
3149
|
-
async#readSourceFile(workspaceRoot, file) {
|
|
3150
|
-
const absolutePath = path9.join(workspaceRoot, file);
|
|
3151
|
-
const content = await readFile3(absolutePath, "utf8");
|
|
3152
|
-
return {
|
|
3153
|
-
file,
|
|
3154
|
-
absolutePath,
|
|
3155
|
-
content,
|
|
3156
|
-
sourceFile: ts20.createSourceFile(file, content, ts20.ScriptTarget.Latest, true, getScriptKind(file))
|
|
3157
|
-
};
|
|
3398
|
+
async scanSsr(workspaceRoot, dirs) {
|
|
3399
|
+
const workspaceFiles = new WorkspaceSourceFiles(workspaceRoot);
|
|
3400
|
+
const read = (file) => !AbstractDoc.isAbstractPath(file) && (dirs.some((dir) => file.startsWith(`${dir}/`)) || /^libs\/[^/]+\/lib\/.+\.signal\.ts$/.test(file));
|
|
3401
|
+
const files = (await workspaceFiles.collect([...dirs, "libs"])).filter(read);
|
|
3402
|
+
const { warnings } = new SsrScanner().scan(await Promise.all(files.map((file) => workspaceFiles.read(file))));
|
|
3403
|
+
return warnings.map((warning) => ({ ...warning, fix: warning.fix ?? getRuleFix(warning.rule) })).sort(compareWarnings);
|
|
3158
3404
|
}
|
|
3159
3405
|
async#readTextFile(workspaceRoot, file) {
|
|
3160
|
-
return { file, content: await
|
|
3406
|
+
return { file, content: await readFile4(path10.join(workspaceRoot, file), "utf8") };
|
|
3161
3407
|
}
|
|
3162
3408
|
#scanGlobalQuality(sourceFiles) {
|
|
3163
3409
|
const exportedFunctionLikes = sourceFiles.flatMap((sourceFile) => getExportedFunctionLikes(sourceFile));
|
|
@@ -3250,8 +3496,8 @@ class AkanQualityScanner {
|
|
|
3250
3496
|
const suffix = CONVENTION_SUFFIXES.find((candidate) => sourceFile.file.endsWith(candidate));
|
|
3251
3497
|
if (!suffix)
|
|
3252
3498
|
return [];
|
|
3253
|
-
const modelName = toPascalCase(
|
|
3254
|
-
return getTopLevelDeclarations(sourceFile).filter((declaration) => !isAllowedConventionDeclaration(suffix, modelName, declaration)).map((declaration) => fileWarning(`akan.convention${suffix.replace(".ts", "")}`, "convention", sourceFile.file, `${
|
|
3499
|
+
const modelName = toPascalCase(path10.basename(sourceFile.file, suffix));
|
|
3500
|
+
return getTopLevelDeclarations(sourceFile).filter((declaration) => !isAllowedConventionDeclaration(suffix, modelName, declaration)).map((declaration) => fileWarning(`akan.convention${suffix.replace(".ts", "")}`, "convention", sourceFile.file, `${path10.basename(sourceFile.file)} should not declare top-level ${declaration.kind} "${declaration.name}". Allowed declarations: ${getConventionDescription(suffix, modelName)}.`, declaration.line));
|
|
3255
3501
|
}
|
|
3256
3502
|
#scanAbstractQuality({ file, content }) {
|
|
3257
3503
|
const lineCount = AbstractDoc.lineCountOf(content);
|
|
@@ -3273,7 +3519,7 @@ class AkanQualityScanner {
|
|
|
3273
3519
|
}
|
|
3274
3520
|
const facetShadow = rootEntry?.isDir ? facetIndexShadowOf(sourceFile.file.split("/").slice(2).join("/")) : null;
|
|
3275
3521
|
if (facetShadow)
|
|
3276
|
-
warnings.push(fileWarning("akan.layout.facet-index-shadow", "layout", sourceFile.file, `${
|
|
3522
|
+
warnings.push(fileWarning("akan.layout.facet-index-shadow", "layout", sourceFile.file, `${path10.basename(sourceFile.file)} ${facetShadow}.`));
|
|
3277
3523
|
const libFacetFile = getLibFacetRootFile(sourceFile.file);
|
|
3278
3524
|
if (libFacetFile && !isAllowedLibFacetRootFile(libFacetFile))
|
|
3279
3525
|
warnings.push(fileWarning("akan.layout.lib-facet-file", "layout", sourceFile.file, `Unexpected lib facet root file "${libFacetFile}". ${libFacetRootHintOf(libFacetFile) ?? "Keep direct lib/ root files limited to generated support facets."}`));
|
|
@@ -3352,13 +3598,13 @@ function getExportedFunctionLikes(sourceFile) {
|
|
|
3352
3598
|
duplicateNameExempt: nameExempt || isConventionDuplicateNameExempt(sourceFile.file, isEnumClass)
|
|
3353
3599
|
});
|
|
3354
3600
|
for (const statement of sourceFile.sourceFile.statements) {
|
|
3355
|
-
if (
|
|
3601
|
+
if (ts22.isFunctionDeclaration(statement) && statement.name && isExported(statement))
|
|
3356
3602
|
add(statement.name.text, "function", statement, statement.body);
|
|
3357
|
-
if (
|
|
3603
|
+
if (ts22.isClassDeclaration(statement) && statement.name && isExported(statement))
|
|
3358
3604
|
add(statement.name.text, "class", statement, statement, isEnumClassStatement(sourceFile.sourceFile, statement));
|
|
3359
|
-
if (
|
|
3605
|
+
if (ts22.isVariableStatement(statement) && isExported(statement)) {
|
|
3360
3606
|
for (const declaration of statement.declarationList.declarations) {
|
|
3361
|
-
if (!
|
|
3607
|
+
if (!ts22.isIdentifier(declaration.name) || !isFunctionLikeInitializer(declaration.initializer))
|
|
3362
3608
|
continue;
|
|
3363
3609
|
add(declaration.name.text, "function-variable", declaration, declaration.initializer);
|
|
3364
3610
|
}
|
|
@@ -3386,14 +3632,14 @@ function isConventionDuplicateNameExempt(file, isEnumClass) {
|
|
|
3386
3632
|
return false;
|
|
3387
3633
|
}
|
|
3388
3634
|
function isEnumClassStatement(sourceFile, statement) {
|
|
3389
|
-
if (!
|
|
3635
|
+
if (!ts22.isClassDeclaration(statement))
|
|
3390
3636
|
return false;
|
|
3391
|
-
const heritageClause = statement.heritageClauses?.find((clause) => clause.token ===
|
|
3637
|
+
const heritageClause = statement.heritageClauses?.find((clause) => clause.token === ts22.SyntaxKind.ExtendsKeyword);
|
|
3392
3638
|
const expression = heritageClause?.types[0]?.expression;
|
|
3393
3639
|
return !!expression && expression.getText(sourceFile).startsWith("enumOf(");
|
|
3394
3640
|
}
|
|
3395
3641
|
function getExportedClassNames(sourceFile) {
|
|
3396
|
-
return sourceFile.statements.filter((statement) =>
|
|
3642
|
+
return sourceFile.statements.filter((statement) => ts22.isClassDeclaration(statement)).filter((statement) => isExported(statement)).map((statement) => statement.name?.text).filter((name) => !!name);
|
|
3397
3643
|
}
|
|
3398
3644
|
function isComponentDeclarationFile(file) {
|
|
3399
3645
|
if (!file.endsWith(".tsx"))
|
|
@@ -3409,7 +3655,7 @@ function isComponentDeclarationFile(file) {
|
|
|
3409
3655
|
function getComponentFileDeclarations(sourceFile) {
|
|
3410
3656
|
const reExportedNames = new Set;
|
|
3411
3657
|
for (const statement of sourceFile.statements) {
|
|
3412
|
-
if (
|
|
3658
|
+
if (ts22.isExportDeclaration(statement) && statement.exportClause && ts22.isNamedExports(statement.exportClause)) {
|
|
3413
3659
|
for (const element of statement.exportClause.elements)
|
|
3414
3660
|
reExportedNames.add((element.propertyName ?? element.name).text);
|
|
3415
3661
|
}
|
|
@@ -3419,19 +3665,19 @@ function getComponentFileDeclarations(sourceFile) {
|
|
|
3419
3665
|
const isDefaultExport = isDefaultExportStatement(statement);
|
|
3420
3666
|
const inlineExported = isExported(statement);
|
|
3421
3667
|
const add = (name, kind, line) => declarations.push({ name, kind, line, exported: inlineExported || reExportedNames.has(name), isDefaultExport });
|
|
3422
|
-
if (
|
|
3668
|
+
if (ts22.isInterfaceDeclaration(statement))
|
|
3423
3669
|
add(statement.name.text, "interface", getLine(sourceFile, statement));
|
|
3424
|
-
else if (
|
|
3670
|
+
else if (ts22.isTypeAliasDeclaration(statement))
|
|
3425
3671
|
add(statement.name.text, "type", getLine(sourceFile, statement));
|
|
3426
|
-
else if (
|
|
3672
|
+
else if (ts22.isEnumDeclaration(statement))
|
|
3427
3673
|
add(statement.name.text, "enum", getLine(sourceFile, statement));
|
|
3428
|
-
else if (
|
|
3674
|
+
else if (ts22.isFunctionDeclaration(statement) && statement.name)
|
|
3429
3675
|
add(statement.name.text, "function", getLine(sourceFile, statement));
|
|
3430
|
-
else if (
|
|
3676
|
+
else if (ts22.isClassDeclaration(statement) && statement.name)
|
|
3431
3677
|
add(statement.name.text, "class", getLine(sourceFile, statement));
|
|
3432
|
-
else if (
|
|
3678
|
+
else if (ts22.isVariableStatement(statement)) {
|
|
3433
3679
|
for (const declaration of statement.declarationList.declarations) {
|
|
3434
|
-
if (!
|
|
3680
|
+
if (!ts22.isIdentifier(declaration.name))
|
|
3435
3681
|
continue;
|
|
3436
3682
|
const kind = isFunctionLikeInitializer(declaration.initializer) ? "function" : "variable";
|
|
3437
3683
|
add(declaration.name.text, kind, getLine(sourceFile, declaration));
|
|
@@ -3443,15 +3689,15 @@ function getComponentFileDeclarations(sourceFile) {
|
|
|
3443
3689
|
function getCompoundComponentNames(sourceFile) {
|
|
3444
3690
|
const names = new Set;
|
|
3445
3691
|
for (const statement of sourceFile.statements) {
|
|
3446
|
-
if (!
|
|
3692
|
+
if (!ts22.isExpressionStatement(statement))
|
|
3447
3693
|
continue;
|
|
3448
3694
|
const { expression } = statement;
|
|
3449
|
-
if (!
|
|
3695
|
+
if (!ts22.isBinaryExpression(expression) || expression.operatorToken.kind !== ts22.SyntaxKind.EqualsToken)
|
|
3450
3696
|
continue;
|
|
3451
|
-
if (!
|
|
3697
|
+
if (!ts22.isPropertyAccessExpression(expression.left) || !isPascalCaseName(expression.left.name.text))
|
|
3452
3698
|
continue;
|
|
3453
3699
|
names.add(expression.left.name.text);
|
|
3454
|
-
if (
|
|
3700
|
+
if (ts22.isIdentifier(expression.right) && isPascalCaseName(expression.right.text))
|
|
3455
3701
|
names.add(expression.right.text);
|
|
3456
3702
|
}
|
|
3457
3703
|
return names;
|
|
@@ -3471,11 +3717,11 @@ function isPascalCaseName(name) {
|
|
|
3471
3717
|
return /^[A-Z]/.test(name) && !/^[A-Z0-9_]+$/.test(name);
|
|
3472
3718
|
}
|
|
3473
3719
|
function isDefaultExportStatement(statement) {
|
|
3474
|
-
if (
|
|
3720
|
+
if (ts22.isExportAssignment(statement))
|
|
3475
3721
|
return !statement.isExportEquals;
|
|
3476
|
-
if (!
|
|
3722
|
+
if (!ts22.canHaveModifiers(statement))
|
|
3477
3723
|
return false;
|
|
3478
|
-
return !!
|
|
3724
|
+
return !!ts22.getModifiers(statement)?.some((modifier) => modifier.kind === ts22.SyntaxKind.DefaultKeyword);
|
|
3479
3725
|
}
|
|
3480
3726
|
function getBangCommentWarnings(sourceFile) {
|
|
3481
3727
|
if (!isClientReachableFile(sourceFile.file))
|
|
@@ -3511,11 +3757,11 @@ function getGlobalMutationWarnings(sourceFile) {
|
|
|
3511
3757
|
const warnings = [];
|
|
3512
3758
|
for (const statement of sourceFile.sourceFile.statements) {
|
|
3513
3759
|
const warn = (rule, message) => warnings.push(fileWarning(rule, "file", sourceFile.file, message, getLine(sourceFile.sourceFile, statement)));
|
|
3514
|
-
if (
|
|
3760
|
+
if (ts22.isModuleDeclaration(statement) && statement.name.getText(sourceFile.sourceFile) === "global")
|
|
3515
3761
|
warn("akan.file.global-declaration", "Global declarations require an explicit low-level integration allowlist.");
|
|
3516
|
-
if (
|
|
3762
|
+
if (ts22.isInterfaceDeclaration(statement) && statement.name.text === "Window")
|
|
3517
3763
|
warn("akan.file.window-augmentation", "Window augmentation should be isolated to approved browser integration files.");
|
|
3518
|
-
if (
|
|
3764
|
+
if (ts22.isExpressionStatement(statement) && statement.expression.getText(sourceFile.sourceFile).includes(".prototype."))
|
|
3519
3765
|
warn("akan.file.prototype-mutation", "Prototype mutation should be avoided or isolated to approved low-level integration files.");
|
|
3520
3766
|
}
|
|
3521
3767
|
return warnings;
|
|
@@ -3532,19 +3778,19 @@ function getTopLevelDeclaration(sourceFile, statement) {
|
|
|
3532
3778
|
exported: isExported(statement),
|
|
3533
3779
|
node: statement
|
|
3534
3780
|
});
|
|
3535
|
-
if (
|
|
3781
|
+
if (ts22.isClassDeclaration(statement) && statement.name)
|
|
3536
3782
|
return [declared(statement.name.text, "class")];
|
|
3537
|
-
if (
|
|
3783
|
+
if (ts22.isFunctionDeclaration(statement) && statement.name)
|
|
3538
3784
|
return [declared(statement.name.text, "function")];
|
|
3539
|
-
if (
|
|
3785
|
+
if (ts22.isInterfaceDeclaration(statement))
|
|
3540
3786
|
return [declared(statement.name.text, "interface")];
|
|
3541
|
-
if (
|
|
3787
|
+
if (ts22.isTypeAliasDeclaration(statement))
|
|
3542
3788
|
return [declared(statement.name.text, "type")];
|
|
3543
|
-
if (
|
|
3789
|
+
if (ts22.isEnumDeclaration(statement))
|
|
3544
3790
|
return [declared(statement.name.text, "enum")];
|
|
3545
|
-
if (
|
|
3546
|
-
return statement.declarationList.declarations.filter((declaration) =>
|
|
3547
|
-
if (
|
|
3791
|
+
if (ts22.isVariableStatement(statement))
|
|
3792
|
+
return statement.declarationList.declarations.filter((declaration) => ts22.isIdentifier(declaration.name)).map((declaration) => declared(declaration.name.text, "variable", getLine(sourceFile, declaration)));
|
|
3793
|
+
if (ts22.isExportDeclaration(statement))
|
|
3548
3794
|
return [{ name: "export declaration", kind: "export", line, exported: true, node: statement }];
|
|
3549
3795
|
return [];
|
|
3550
3796
|
}
|
|
@@ -3632,13 +3878,13 @@ function getModuleInfo(file) {
|
|
|
3632
3878
|
return { moduleName, fileName, kind: "database" };
|
|
3633
3879
|
}
|
|
3634
3880
|
function isExportedConst(declaration) {
|
|
3635
|
-
return declaration.exported &&
|
|
3881
|
+
return declaration.exported && ts22.isVariableStatement(declaration.node) && (declaration.node.declarationList.flags & ts22.NodeFlags.Const) !== 0;
|
|
3636
3882
|
}
|
|
3637
3883
|
function isExported(node) {
|
|
3638
|
-
return !!(
|
|
3884
|
+
return !!(ts22.getCombinedModifierFlags(node) & ts22.ModifierFlags.Export);
|
|
3639
3885
|
}
|
|
3640
3886
|
function isFunctionLikeInitializer(node) {
|
|
3641
|
-
return !!node && (
|
|
3887
|
+
return !!node && (ts22.isArrowFunction(node) || ts22.isFunctionExpression(node));
|
|
3642
3888
|
}
|
|
3643
3889
|
function getBodyFingerprint(sourceFile, node) {
|
|
3644
3890
|
if (!node)
|
|
@@ -3648,20 +3894,6 @@ function getBodyFingerprint(sourceFile, node) {
|
|
|
3648
3894
|
return;
|
|
3649
3895
|
return createHash("sha256").update(normalizedBody).digest("hex");
|
|
3650
3896
|
}
|
|
3651
|
-
function shouldSkipPath(relativePath, isDirectory, ignoreFilter) {
|
|
3652
|
-
const ignorePath = isDirectory ? `${relativePath}/` : relativePath;
|
|
3653
|
-
return relativePath === ".git" || relativePath.includes("/.git/") || relativePath.includes("/node_modules/") || ignoreFilter.ignores(relativePath) || ignoreFilter.ignores(ignorePath);
|
|
3654
|
-
}
|
|
3655
|
-
async function isDirectory(absolutePath) {
|
|
3656
|
-
try {
|
|
3657
|
-
return (await stat(absolutePath)).isDirectory();
|
|
3658
|
-
} catch {
|
|
3659
|
-
return false;
|
|
3660
|
-
}
|
|
3661
|
-
}
|
|
3662
|
-
function getScriptKind(file) {
|
|
3663
|
-
return file.endsWith(".tsx") ? ts20.ScriptKind.TSX : ts20.ScriptKind.TS;
|
|
3664
|
-
}
|
|
3665
3897
|
function getLine(sourceFile, node) {
|
|
3666
3898
|
return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
|
|
3667
3899
|
}
|
|
@@ -3680,9 +3912,6 @@ function findPatternLines(content, pattern) {
|
|
|
3680
3912
|
function toPascalCase(value) {
|
|
3681
3913
|
return value.replace(/(^|[-_./])([a-zA-Z0-9])/g, (_, __, char) => char.toUpperCase()).replace(/[-_./]/g, "");
|
|
3682
3914
|
}
|
|
3683
|
-
function toPosix(value) {
|
|
3684
|
-
return value.split(path9.sep).join("/");
|
|
3685
|
-
}
|
|
3686
3915
|
function groupBy(items, getKey) {
|
|
3687
3916
|
const grouped = new Map;
|
|
3688
3917
|
for (const item of items) {
|