@akanjs/devkit 3.3.0-rc.2 → 3.3.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +284 -20
- package/DEV_RUNTIME_KNOBS.md +1 -1
- package/README.ko.md +3 -2
- package/README.md +3 -3
- package/akanApp/akanApp.host.test.ts +1 -1
- package/akanConfig/akanConfig.test.ts +57 -8
- package/akanConfig/akanConfig.ts +16 -69
- package/akanConfig/dockerImage.ts +17 -0
- package/akanConfig/nativeKeys.ts +52 -0
- package/app/applicationBuildRunner.test.ts +321 -1
- package/app/applicationBuildRunner.ts +90 -3
- package/artifact/implicitRootLayoutRender.test.tsx +4 -1
- package/codeAgent/agent/CodeAgent.ts +36 -16
- package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
- package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
- package/codeAgent/agent/CodeAgentGate.ts +23 -4
- package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +62 -0
- package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
- package/codeAgent/agent/codeAgentContract.test.ts +117 -5
- package/codeAgent/skills/akan-agent/SKILL.md +8 -1
- package/codeAgent/skills/akan-code/SKILL.md +38 -3
- package/codeAgent/skills/akan-err/SKILL.md +11 -2
- package/codeAgent/skills/akan-page/SKILL.md +21 -26
- package/codeAgent/skills/akan-runtime/SKILL.md +41 -16
- package/codeAgent/skills/akan-service/SKILL.md +2 -2
- package/docs/apiReference.test.ts +14 -0
- package/docs/apiReference.ts +21 -3
- package/docs/declarationReader.ts +28 -1
- package/executors/appExecutor.ts +16 -7
- package/executors/workspaceExecutor.ts +7 -4
- package/frontendBuild/buildRouteClient.test.ts +2 -7
- package/frontendBuild/clientEntryDiscovery.test.ts +35 -0
- package/frontendBuild/clientEntryDiscovery.ts +16 -3
- package/frontendBuild/cssCompiler.test.ts +112 -0
- package/frontendBuild/cssCompiler.ts +41 -21
- package/frontendBuild/devBarrelImports.test.ts +30 -0
- package/frontendBuild/devBarrelImports.ts +2 -2
- package/frontendBuild/pagesBundleBuilder.ts +3 -1
- package/frontendBuild/plainStylesheet.test.ts +155 -0
- package/frontendBuild/plainStylesheet.ts +197 -0
- package/frontendBuild/rscServerRendererGuard.test.ts +60 -0
- package/frontendBuild/rscServerRendererGuard.ts +68 -0
- package/guideline/agentAssets.test.ts +10 -0
- package/guideline/agentAssets.ts +52 -11
- package/incrementalBuilder/buildBatch.proc.ts +9 -9
- package/incrementalBuilder/buildBatchProtocol.ts +1 -1
- package/incrementalBuilder/builderBoot.ts +5 -5
- package/incrementalBuilder/builderGraphPayloads.ts +4 -4
- package/incrementalBuilder/builderLanes.ts +2 -2
- package/incrementalBuilder/builderWatch.ts +8 -8
- package/incrementalBuilder/csrRegistry.ts +4 -4
- package/incrementalBuilder/incrementalBuilder.proc.ts +8 -8
- package/incrementalBuilder/ssrRegistry.ts +6 -6
- package/index.ts +1 -1
- package/integration/renderAdmissionSoak.test.ts +99 -0
- package/integration/renderAdmissionSoak.ts +609 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
- package/lint/biomeCheck.test.ts +145 -0
- package/lint/biomeCheck.ts +131 -0
- package/lint/no-arbitrary-color.grit +5 -0
- package/lint/no-conditional-st-hook.grit +5 -1
- package/lint/no-daisyui-legacy-class.grit +8 -0
- package/lint/no-document-cookie.grit +3 -0
- package/lint/no-inline-color.grit +10 -2
- package/lint/no-oversized-list-limit.grit +2 -0
- package/lint/no-raw-palette-class.grit +7 -0
- package/lint/no-unpublished-form-setter.grit +2 -0
- package/lint/no-web-only-api-outside-webkit.grit +5 -0
- package/lint/no-web-storage.grit +3 -0
- package/lint/withheldEnvFile.ts +17 -0
- package/mobile/nativeApp.test.ts +7 -5
- package/mobile/nativeApp.ts +2 -2
- package/mobile/nativeConfig.test.ts +117 -1
- package/mobile/nativeConfig.ts +66 -22
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +14 -169
- package/packageExports.test.ts +38 -24
- package/test/secretEnvFixture.ts +134 -0
- package/transforms/barrelAnalyzer.ts +2 -2
- package/transforms/secretEnvDeclaration.test.ts +208 -0
- package/transforms/secretEnvDeclaration.ts +213 -0
- package/transforms/secretEnvFile.test.ts +117 -0
- package/transforms/secretEnvFile.ts +113 -0
- package/transforms/secretEnvName.test.ts +54 -0
- package/transforms/secretEnvName.ts +29 -0
- package/transforms/secretEnvSource.test.ts +148 -0
- package/transforms/secretEnvSource.ts +166 -0
- package/transforms/serverEnvEvaluationError.ts +11 -0
- package/transforms/serverEnvPlugin.test.ts +2 -1
- package/transforms/serverEnvPlugin.ts +13 -0
- package/transforms/serverEnvProfile.test.ts +115 -2
- package/transforms/serverEnvProfile.ts +117 -40
- package/transforms/serverEnvSecrets.test.ts +292 -0
- package/transforms/transforms.test.ts +3 -3
- package/tunnel/createTunnel.test.ts +29 -8
- package/tunnel/createTunnel.ts +18 -11
- package/typecheck/projectTypecheck.test.ts +29 -0
- package/typecheck/typeChecker.test.ts +49 -0
- package/typecheck/typeChecker.ts +9 -7
- package/typecheck/withheldDiagnostics.ts +41 -0
- package/util/fileEditor.ts +1 -0
- package/util/selectModel.ts +1 -0
- package/workspace/getRelatedCnsts.ts +7 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const Slate = () => <div className="bg-slate-500" />; // @flag
|
|
2
|
+
export const Gray = () => <div className="bg-gray-500" />; // @flag
|
|
3
|
+
export const Zinc = () => <div className="bg-zinc-500" />; // @flag
|
|
4
|
+
export const Neutral = () => <div className="bg-neutral-500" />; // @flag
|
|
5
|
+
export const Stone = () => <div className="bg-stone-500" />; // @flag
|
|
6
|
+
export const Red = () => <div className="bg-red-500" />; // @flag
|
|
7
|
+
export const Orange = () => <div className="bg-orange-500" />; // @flag
|
|
8
|
+
export const Amber = () => <div className="bg-amber-500" />; // @flag
|
|
9
|
+
export const Yellow = () => <div className="bg-yellow-500" />; // @flag
|
|
10
|
+
export const Lime = () => <div className="bg-lime-500" />; // @flag
|
|
11
|
+
export const Green = () => <div className="bg-green-500" />; // @flag
|
|
12
|
+
export const Emerald = () => <div className="bg-emerald-500" />; // @flag
|
|
13
|
+
export const Teal = () => <div className="bg-teal-500" />; // @flag
|
|
14
|
+
export const Cyan = () => <div className="bg-cyan-500" />; // @flag
|
|
15
|
+
export const Sky = () => <div className="bg-sky-500" />; // @flag
|
|
16
|
+
export const Blue = () => <div className="bg-blue-500" />; // @flag
|
|
17
|
+
export const Indigo = () => <div className="bg-indigo-500" />; // @flag
|
|
18
|
+
export const Violet = () => <div className="bg-violet-500" />; // @flag
|
|
19
|
+
export const Purple = () => <div className="bg-purple-500" />; // @flag
|
|
20
|
+
export const Fuchsia = () => <div className="bg-fuchsia-500" />; // @flag
|
|
21
|
+
export const Pink = () => <div className="bg-pink-500" />; // @flag
|
|
22
|
+
export const Rose = () => <div className="bg-rose-500" />; // @flag
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdir, symlink } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { hasBiome, tempDirs, writeText } from "../test/testHelpers";
|
|
5
|
+
import { BiomeCheck } from "./biomeCheck";
|
|
6
|
+
|
|
7
|
+
const makeTempRoot = tempDirs("akan-devkit-biome-check-");
|
|
8
|
+
const repoRoot = path.resolve(import.meta.dir, "../../../..");
|
|
9
|
+
const sentinel = "SENTINEL_DB_PASSWORD_4f9c2a71e0b3";
|
|
10
|
+
|
|
11
|
+
const workspace = async () => {
|
|
12
|
+
const root = await makeTempRoot();
|
|
13
|
+
await mkdir(path.join(root, "node_modules"), { recursive: true });
|
|
14
|
+
await symlink(path.join(repoRoot, "node_modules/@biomejs"), path.join(root, "node_modules/@biomejs"));
|
|
15
|
+
await writeText(
|
|
16
|
+
path.join(root, "biome.json"),
|
|
17
|
+
JSON.stringify({
|
|
18
|
+
vcs: { enabled: false },
|
|
19
|
+
linter: { rules: { suspicious: { noTemplateCurlyInString: "error", noExplicitAny: "error" } } },
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
await writeText(
|
|
23
|
+
path.join(root, "apps/demo/env/env.server.main.ts"),
|
|
24
|
+
`export const env = { apiKey: "${sentinel}", password: "${sentinel}\${x}" };\n`,
|
|
25
|
+
);
|
|
26
|
+
await writeText(path.join(root, "apps/demo/ui/card.ts"), "export const card: any = 1;\n");
|
|
27
|
+
return root;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const run = async (root: string, options: { write: boolean; maxDiagnostics: number }) => {
|
|
31
|
+
const printed: string[] = [];
|
|
32
|
+
const error = await BiomeCheck.run({
|
|
33
|
+
root,
|
|
34
|
+
target: path.join(root, "apps/demo"),
|
|
35
|
+
configPath: path.join(root, "biome.json"),
|
|
36
|
+
print: (text) => printed.push(text),
|
|
37
|
+
...options,
|
|
38
|
+
}).then(
|
|
39
|
+
() => null,
|
|
40
|
+
(e: unknown) => e as Error,
|
|
41
|
+
);
|
|
42
|
+
return { output: printed.join("\n"), error };
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
describe.skipIf(!hasBiome)("BiomeCheck", () => {
|
|
46
|
+
test.each([true, false])(
|
|
47
|
+
"names an env file's diagnostics by position and rule only, with write %p",
|
|
48
|
+
async (write) => {
|
|
49
|
+
const root = await workspace();
|
|
50
|
+
const { output, error } = await run(root, { write, maxDiagnostics: 200 });
|
|
51
|
+
|
|
52
|
+
expect(output).not.toContain(sentinel);
|
|
53
|
+
expect(output).not.toContain("apiKey");
|
|
54
|
+
expect(output).toMatch(
|
|
55
|
+
/apps\/demo\/env\/env\.server\.main\.ts:\d+:\d+ error lint\/suspicious\/noTemplateCurlyInString/,
|
|
56
|
+
);
|
|
57
|
+
expect(output).toContain("withheld");
|
|
58
|
+
expect(output).toContain("export const card: any = 1;");
|
|
59
|
+
expect(error?.message).toBe(write ? "Lint found 2 errors." : "Lint found 3 errors.");
|
|
60
|
+
if (!write) expect(output).toMatch(/env\.server\.main\.ts:0:0 error format/);
|
|
61
|
+
},
|
|
62
|
+
60_000,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
test("counts an env file's diagnostics when nothing else fails, and keeps to the cap", async () => {
|
|
66
|
+
const root = await workspace();
|
|
67
|
+
await writeText(path.join(root, "apps/demo/ui/card.ts"), "export const card = 1;\n");
|
|
68
|
+
const all = await run(root, { write: true, maxDiagnostics: 0 });
|
|
69
|
+
expect(all.error?.message).toBe("Lint found 1 error.");
|
|
70
|
+
expect(all.output).not.toContain(sentinel);
|
|
71
|
+
|
|
72
|
+
const capped = await run(await workspace(), { write: false, maxDiagnostics: 1 });
|
|
73
|
+
expect(capped.output.match(/env\.server\.main\.ts:/g)).toHaveLength(1);
|
|
74
|
+
expect(capped.output).toContain("not shown");
|
|
75
|
+
expect(capped.output).not.toContain("export const card: any");
|
|
76
|
+
expect(capped.error).not.toBeNull();
|
|
77
|
+
}, 60_000);
|
|
78
|
+
|
|
79
|
+
test("explains a biome.json Biome cannot read, in Biome's own words", async () => {
|
|
80
|
+
const root = await workspace();
|
|
81
|
+
await writeText(path.join(root, "biome.json"), '{ // a comment\n "vcs": { "enabled": false } }');
|
|
82
|
+
const { error, output } = await run(root, { write: false, maxDiagnostics: 200 });
|
|
83
|
+
expect(output).toBe("");
|
|
84
|
+
expect(error?.message).toContain("biome.json");
|
|
85
|
+
expect(error?.message).not.toContain("gave no report");
|
|
86
|
+
}, 60_000);
|
|
87
|
+
|
|
88
|
+
test("reports every file of a large app in groups, and stops at the cap with the count left", async () => {
|
|
89
|
+
const root = await workspace();
|
|
90
|
+
await writeText(path.join(root, "apps/demo/env/env.server.main.ts"), "export const env = {};\n");
|
|
91
|
+
await writeText(path.join(root, "apps/demo/ui/card.ts"), "export const card = 1;\n");
|
|
92
|
+
for (let idx = 0; idx < 250; idx += 1)
|
|
93
|
+
await writeText(path.join(root, `apps/demo/ui/many/file${idx}.ts`), `export const value${idx}: any = ${idx};\n`);
|
|
94
|
+
const reported = (output: string) => output.match(/noExplicitAny ━/g)?.length ?? 0;
|
|
95
|
+
|
|
96
|
+
const all = await run(root, { write: false, maxDiagnostics: 0 });
|
|
97
|
+
expect(reported(all.output)).toBe(250);
|
|
98
|
+
expect(all.output).not.toContain("not shown");
|
|
99
|
+
expect(all.output.match(/^Found 250 errors\.$/gm)).toHaveLength(1);
|
|
100
|
+
expect(all.output).not.toContain("Checked ");
|
|
101
|
+
expect(all.error?.message).toBe("Lint found 250 errors.");
|
|
102
|
+
|
|
103
|
+
const capped = await run(root, { write: false, maxDiagnostics: 150 });
|
|
104
|
+
expect(reported(capped.output)).toBe(150);
|
|
105
|
+
expect(capped.output).toContain("50 more diagnostics are not shown; --max-diagnostics 0 shows them all.");
|
|
106
|
+
}, 120_000);
|
|
107
|
+
|
|
108
|
+
test("lists after a write only what is still wrong", async () => {
|
|
109
|
+
const root = await workspace();
|
|
110
|
+
await writeText(path.join(root, "apps/demo/env/env.server.main.ts"), "export const env = {};\n");
|
|
111
|
+
await writeText(path.join(root, "apps/demo/ui/card.ts"), "export const card = 1;\nexport const other = 2\n");
|
|
112
|
+
const { output, error } = await run(root, { write: true, maxDiagnostics: 200 });
|
|
113
|
+
expect(output).toBe("");
|
|
114
|
+
expect(error).toBeNull();
|
|
115
|
+
expect(await Bun.file(path.join(root, "apps/demo/ui/card.ts")).text()).toContain("export const other = 2;");
|
|
116
|
+
}, 60_000);
|
|
117
|
+
|
|
118
|
+
test("withholds a grit plugin diagnostic on an env file", async () => {
|
|
119
|
+
const root = await workspace();
|
|
120
|
+
await writeText(
|
|
121
|
+
path.join(root, "no-marker.grit"),
|
|
122
|
+
'engine biome(1.0)\nlanguage js(typescript)\n`MARKER` as $m where { register_diagnostic(span = $m, message = "marker found", severity = "error") }\n',
|
|
123
|
+
);
|
|
124
|
+
await writeText(
|
|
125
|
+
path.join(root, "biome.json"),
|
|
126
|
+
JSON.stringify({ vcs: { enabled: false }, plugins: ["./no-marker.grit"] }),
|
|
127
|
+
);
|
|
128
|
+
await writeText(
|
|
129
|
+
path.join(root, "apps/demo/env/env.server.main.ts"),
|
|
130
|
+
`export const env = { password: MARKER, other: "${sentinel}" };\n`,
|
|
131
|
+
);
|
|
132
|
+
const { output, error } = await run(root, { write: false, maxDiagnostics: 200 });
|
|
133
|
+
expect(output).not.toContain(sentinel);
|
|
134
|
+
expect(output).toMatch(/env\.server\.main\.ts:\d+:\d+ error plugin - the text is withheld/);
|
|
135
|
+
expect(error).not.toBeNull();
|
|
136
|
+
}, 60_000);
|
|
137
|
+
|
|
138
|
+
test("drops a group's own summary lines, coloured or not", () => {
|
|
139
|
+
const coloured = "\u001b[1mChecked 100 files in 1s.\u001b[0m\n\u001b[31mFound 3 errors.\u001b[39m\na.ts:1:1 lint/x";
|
|
140
|
+
expect(BiomeCheck.withoutSummary(coloured)).toBe("a.ts:1:1 lint/x");
|
|
141
|
+
expect(BiomeCheck.withoutSummary("Checked 1 file in 2ms.\nFound 1 warning.\nb.ts:2:1 lint/y")).toBe(
|
|
142
|
+
"b.ts:2:1 lint/y",
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { CliError } from "../commandDecorators/cliError";
|
|
2
|
+
import { type BiomeDiagnostic, Linter, parseBiomeReport } from "./linter";
|
|
3
|
+
import { WithheldEnvFile } from "./withheldEnvFile";
|
|
4
|
+
|
|
5
|
+
export interface BiomeCheckOptions {
|
|
6
|
+
root: string;
|
|
7
|
+
target: string;
|
|
8
|
+
configPath: string | null;
|
|
9
|
+
write: boolean;
|
|
10
|
+
//? 0 shows every diagnostic.
|
|
11
|
+
maxDiagnostics: number;
|
|
12
|
+
print: (text: string) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//* Biome's own report quotes source lines, so a first run writes the fixes and reads the JSON report. An env file's
|
|
16
|
+
//* diagnostics are printed from it by position and rule alone; Biome prints the rest again, from the files that have any.
|
|
17
|
+
export class BiomeCheck {
|
|
18
|
+
static readonly #groupSize = 100;
|
|
19
|
+
static readonly #summary = /^(?:Checked \d+ files? in |Found \d+ (?:errors?|warnings?|info))/;
|
|
20
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: an ANSI colour sequence starts with the escape character
|
|
21
|
+
static readonly #colour = /\u001b\[[0-9;]*m/g;
|
|
22
|
+
|
|
23
|
+
static async run({ root, target, configPath, write, maxDiagnostics, print }: BiomeCheckOptions) {
|
|
24
|
+
const [biome, ...biomeArgs] = Linter.biomeCommand(root);
|
|
25
|
+
//? Pinned: without it a malformed biome.json makes Biome fall back to discovery and name the wrong file.
|
|
26
|
+
const config = configPath ? ["--config-path", configPath] : [];
|
|
27
|
+
const first = Bun.spawn(
|
|
28
|
+
[
|
|
29
|
+
biome,
|
|
30
|
+
...biomeArgs,
|
|
31
|
+
"check",
|
|
32
|
+
...(write ? ["--write"] : []),
|
|
33
|
+
"--reporter=json",
|
|
34
|
+
"--max-diagnostics=none",
|
|
35
|
+
"--no-errors-on-unmatched",
|
|
36
|
+
...config,
|
|
37
|
+
target,
|
|
38
|
+
],
|
|
39
|
+
{ cwd: root, stdout: "pipe", stderr: "pipe" },
|
|
40
|
+
);
|
|
41
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
42
|
+
new Response(first.stdout).text(),
|
|
43
|
+
new Response(first.stderr).text(),
|
|
44
|
+
first.exited,
|
|
45
|
+
]);
|
|
46
|
+
let diagnostics: BiomeDiagnostic[];
|
|
47
|
+
try {
|
|
48
|
+
diagnostics = parseBiomeReport(stdout).diagnostics ?? [];
|
|
49
|
+
} catch {
|
|
50
|
+
const cause = (stderr || stdout).trim();
|
|
51
|
+
throw new CliError(
|
|
52
|
+
"failed",
|
|
53
|
+
cause && !WithheldEnvFile.namesEnvFile(cause)
|
|
54
|
+
? cause
|
|
55
|
+
: `Biome exited with ${exitCode} and gave no report that could be read.`,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const shown = diagnostics.filter(({ severity }) => severity !== "hint");
|
|
59
|
+
const inEnv = (diagnostic: BiomeDiagnostic) =>
|
|
60
|
+
WithheldEnvFile.isEnvFile(diagnostic.location?.path?.replaceAll("\\", "/"));
|
|
61
|
+
const fromEnv = shown.filter(inEnv);
|
|
62
|
+
const rest = shown.filter((diagnostic) => !inEnv(diagnostic));
|
|
63
|
+
let remaining = maxDiagnostics > 0 ? maxDiagnostics : Number.POSITIVE_INFINITY;
|
|
64
|
+
for (const diagnostic of fromEnv.slice(0, remaining)) print(BiomeCheck.#line(diagnostic));
|
|
65
|
+
let hidden = Math.max(0, fromEnv.length - remaining);
|
|
66
|
+
remaining -= Math.min(fromEnv.length, remaining);
|
|
67
|
+
for (const group of BiomeCheck.#groups(rest)) {
|
|
68
|
+
if (remaining <= 0) {
|
|
69
|
+
hidden += group.count;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const second = Bun.spawn(
|
|
73
|
+
[
|
|
74
|
+
biome,
|
|
75
|
+
...biomeArgs,
|
|
76
|
+
"check",
|
|
77
|
+
//? Biome shows 20 diagnostics unless told otherwise.
|
|
78
|
+
`--max-diagnostics=${Number.isFinite(remaining) ? remaining : "none"}`,
|
|
79
|
+
...(process.stdout.isTTY && !process.env.NO_COLOR ? ["--colors=force"] : []),
|
|
80
|
+
...config,
|
|
81
|
+
...group.files,
|
|
82
|
+
],
|
|
83
|
+
{ cwd: root, stdout: "pipe", stderr: "pipe" },
|
|
84
|
+
);
|
|
85
|
+
const [out, err] = await Promise.all([
|
|
86
|
+
new Response(second.stdout).text(),
|
|
87
|
+
new Response(second.stderr).text(),
|
|
88
|
+
second.exited,
|
|
89
|
+
]);
|
|
90
|
+
print(BiomeCheck.withoutSummary(`${out}${err}`));
|
|
91
|
+
remaining -= Math.min(group.count, remaining);
|
|
92
|
+
}
|
|
93
|
+
for (const diagnostic of rest.filter(({ location }) => !location?.path)) print(diagnostic.message);
|
|
94
|
+
if (hidden) print(`${hidden} more diagnostics are not shown; --max-diagnostics 0 shows them all.`);
|
|
95
|
+
const count = (severity: string) => shown.filter((diagnostic) => diagnostic.severity === severity).length;
|
|
96
|
+
for (const [severity, noun] of [
|
|
97
|
+
["error", "error"],
|
|
98
|
+
["warning", "warning"],
|
|
99
|
+
["information", "info"],
|
|
100
|
+
] as const)
|
|
101
|
+
if (count(severity))
|
|
102
|
+
print(`Found ${count(severity)} ${noun}${count(severity) === 1 || noun === "info" ? "" : "s"}.`);
|
|
103
|
+
const errors = count("error");
|
|
104
|
+
if (errors) throw new CliError("checkFailed", `Lint found ${errors} error${errors === 1 ? "" : "s"}.`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//? Each group's summary counts only its own files; the one printed at the end counts the whole run.
|
|
108
|
+
static withoutSummary(text: string) {
|
|
109
|
+
return text
|
|
110
|
+
.split("\n")
|
|
111
|
+
.filter((line) => !BiomeCheck.#summary.test(line.replace(BiomeCheck.#colour, "")))
|
|
112
|
+
.join("\n")
|
|
113
|
+
.trim();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
static #groups(diagnostics: BiomeDiagnostic[]) {
|
|
117
|
+
const counts = new Map<string, number>();
|
|
118
|
+
for (const { location } of diagnostics)
|
|
119
|
+
if (location?.path) counts.set(location.path, (counts.get(location.path) ?? 0) + 1);
|
|
120
|
+
const entries = [...counts];
|
|
121
|
+
return Array.from({ length: Math.ceil(entries.length / BiomeCheck.#groupSize) }, (_, index) => {
|
|
122
|
+
const slice = entries.slice(index * BiomeCheck.#groupSize, (index + 1) * BiomeCheck.#groupSize);
|
|
123
|
+
return { files: slice.map(([file]) => file), count: slice.reduce((sum, [, count]) => sum + count, 0) };
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static #line({ severity, category, location }: BiomeDiagnostic) {
|
|
128
|
+
const at = `${location?.path}:${location?.start?.line ?? 0}:${location?.start?.column ?? 0}`;
|
|
129
|
+
return `${at} ${severity} ${category ?? "biome"} - ${WithheldEnvFile.note}`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -10,6 +10,11 @@ or {
|
|
|
10
10
|
JsStringLiteralExpression() as $s,
|
|
11
11
|
JsTemplateChunkElement() as $s
|
|
12
12
|
} where {
|
|
13
|
+
// GritQL compiles a regex anew for every node it tries, so a substring every match must contain gates it.
|
|
14
|
+
$s <: or {
|
|
15
|
+
includes "[#", includes "[rgb", includes "[hsl", includes "[ok", includes "[lab(", includes "[lch(",
|
|
16
|
+
includes "[hwb(", includes "[color("
|
|
17
|
+
},
|
|
13
18
|
$s <: r"[\s\S]*\[(?:#[0-9a-fA-F]{3,8}|(?:rgb|rgba|hsl|hsla|oklch|oklab|lab|lch|hwb|color)\([^\]]*\))\][\s\S]*",
|
|
14
19
|
register_diagnostic(
|
|
15
20
|
span = $s,
|
|
@@ -32,6 +32,8 @@ pattern st_hook_call() {
|
|
|
32
32
|
`$chain.value($args)` where { $chain <: r"st\s*\.\s*expose\s*\([\s\S]*" },
|
|
33
33
|
// Computed access (`st["use"].x()`, `st.use[key]()`) at any step, which would take a snippet per combination.
|
|
34
34
|
JsCallExpression(callee = $callee) where {
|
|
35
|
+
// GritQL compiles a regex anew for every node it tries, so a substring every match must contain gates it.
|
|
36
|
+
$callee <: or { includes "use", includes "sel", includes "ref" },
|
|
35
37
|
$callee <: or {
|
|
36
38
|
r"st\s*(?:\.\s*use|\[\s*[\x27\x22`]use[\x27\x22`]\s*\])\s*(?:\.\s*[\w$]+|\[[^\]]*\])",
|
|
37
39
|
r"st\s*(?:\.\s*slice|\[\s*[\x27\x22`]slice[\x27\x22`]\s*\])\s*(?:\.\s*[\w$]+|\[[^\]]*\])\s*(?:\.\s*use|\[\s*[\x27\x22`]use[\x27\x22`]\s*\])\s*(?:\.\s*[\w$]+|\[[^\]]*\])",
|
|
@@ -78,7 +80,9 @@ pattern passed_by_name($name) {
|
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
// GritQL copies its match state for every snippet it tries, so a substring every hook's callee contains goes first.
|
|
84
|
+
JsCallExpression(callee = $hookCallee) as $call where {
|
|
85
|
+
$hookCallee <: includes "st",
|
|
82
86
|
$call <: st_hook_call(),
|
|
83
87
|
or {
|
|
84
88
|
$call <: within JsLogicalExpression(right = $right) where { $right <: contains $call } until function_boundary(),
|
|
@@ -18,8 +18,10 @@ or {
|
|
|
18
18
|
JsStringLiteralExpression() as $s,
|
|
19
19
|
JsTemplateChunkElement() as $s
|
|
20
20
|
} where {
|
|
21
|
+
// GritQL compiles a regex anew for every node it tries, so a substring every match must contain gates each one.
|
|
21
22
|
any {
|
|
22
23
|
and {
|
|
24
|
+
$s <: or { includes "-base-", includes "-content", includes "-error" },
|
|
23
25
|
$s <: r"[\s\S]*(?:^|[\s\"'`{(\[:!])(?:bg|text|border(?:-[tblrxy])?(?:-[se])?|ring(?:-offset)?|fill|stroke|shadow|from|to|via|divide|outline|decoration|placeholder|caret|accent)-(?:base-(?:100|200|300|content)|(?:primary|secondary|accent|neutral|info|success|warning|error)-content|error)(?:[\s\"'`})\]:/!,]|$)[\s\S]*",
|
|
24
26
|
register_diagnostic(
|
|
25
27
|
span = $s,
|
|
@@ -28,6 +30,12 @@ or {
|
|
|
28
30
|
)
|
|
29
31
|
},
|
|
30
32
|
and {
|
|
33
|
+
$s <: or {
|
|
34
|
+
includes "btn-", includes "badge-", includes "alert-", includes "input-", includes "select-",
|
|
35
|
+
includes "textarea-", includes "checkbox-", includes "toggle-", includes "loading-", includes "card-",
|
|
36
|
+
includes "modal-", includes "collapse-", includes "dropdown-", includes "stat-", includes "tab",
|
|
37
|
+
includes "menu-", includes "steps-", includes "join-item", includes "mockup-", includes "drawer-"
|
|
38
|
+
},
|
|
31
39
|
$s <: r"[\s\S]*(?:^|[\s\"'`{(\[:!])(?:btn-(?:primary|secondary|accent|neutral|info|success|warning|error|ghost|link|outline|square|circle|wide|block|xs|sm|md|lg)|badge-(?:primary|secondary|accent|neutral|info|success|warning|error|ghost|outline)|alert-(?:info|success|warning|error)|input-(?:bordered|primary|secondary|accent|ghost|error)|select-(?:bordered|primary|ghost)|textarea-(?:bordered|primary|ghost)|checkbox-(?:primary|secondary|accent)|toggle-(?:primary|secondary|accent)|loading-(?:spinner|dots|ring|ball|bars|infinity)|card-(?:body|title|actions)|modal-(?:box|action|backdrop)|collapse-(?:title|content|arrow|plus)|dropdown-(?:content|end|start|hover)|stat-(?:title|value|desc)|tabs-(?:boxed|lifted|bordered)|tab-active|menu-(?:title|dropdown)|steps-(?:horizontal|vertical)|join-item|mockup-(?:code|phone|browser|window)|drawer-(?:side|content|toggle))(?:[\s\"'`})\]:/!,]|$)[\s\S]*",
|
|
32
40
|
register_diagnostic(
|
|
33
41
|
span = $s,
|
|
@@ -10,6 +10,8 @@ language js(typescript, jsx)
|
|
|
10
10
|
// write is its own node (JsStaticMemberAssignment) that the expression form does not match.
|
|
11
11
|
or {
|
|
12
12
|
JsStaticMemberExpression() as $access where {
|
|
13
|
+
// GritQL copies its match state for every snippet it tries, so a substring every match must contain goes first.
|
|
14
|
+
$access <: includes "cookie",
|
|
13
15
|
$access <: or { `document.cookie`, `window.document.cookie`, `globalThis.document.cookie`, `self.document.cookie` },
|
|
14
16
|
register_diagnostic(
|
|
15
17
|
span = $access,
|
|
@@ -18,6 +20,7 @@ or {
|
|
|
18
20
|
)
|
|
19
21
|
},
|
|
20
22
|
JsStaticMemberAssignment(object = $object, member = $member) as $access where {
|
|
23
|
+
$member <: includes "cookie",
|
|
21
24
|
$member <: `cookie`,
|
|
22
25
|
$object <: or { `document`, `window.document`, `globalThis.document`, `self.document` },
|
|
23
26
|
register_diagnostic(
|
|
@@ -11,16 +11,24 @@ language js(typescript, jsx)
|
|
|
11
11
|
// warnings, not errors, so code written before the rule reached them is not broken.
|
|
12
12
|
// The hex arm skips `url(#id)`: a paint-server id such as `#fade` is spelled in hex digits.
|
|
13
13
|
// Cases: lint/__fixtures__/no-inline-color/{bad,good}.tsx
|
|
14
|
+
|
|
15
|
+
// GritQL compiles a regex anew for every node it tries, so a substring every match must contain gates it first.
|
|
16
|
+
pattern colour_literal_text() {
|
|
17
|
+
or { includes "#", includes "rgb", includes "hsl", includes "lab(", includes "lch(", includes "hwb(" }
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
or {
|
|
15
21
|
or {
|
|
16
|
-
JsStringLiteralExpression() as $s where { $s <: within `style={$obj}` },
|
|
17
|
-
JsTemplateChunkElement() as $s where { $s <: within `<style>$body</style>` }
|
|
22
|
+
JsStringLiteralExpression() as $s where { $s <: colour_literal_text(), $s <: within `style={$obj}` },
|
|
23
|
+
JsTemplateChunkElement() as $s where { $s <: colour_literal_text(), $s <: within `<style>$body</style>` }
|
|
18
24
|
} where { $tier = "error" },
|
|
19
25
|
or {
|
|
20
26
|
or { JsxString(), JsStringLiteralExpression(), JsTemplateChunkElement() } as $s where {
|
|
27
|
+
$s <: colour_literal_text(),
|
|
21
28
|
$s <: within JsxAttribute(name = r"(?:fill|stroke|stopColor|floodColor|lightingColor|color|stop-color|flood-color|lighting-color)")
|
|
22
29
|
},
|
|
23
30
|
or { JsStringLiteralExpression(), JsTemplateChunkElement() } as $s where {
|
|
31
|
+
$s <: colour_literal_text(),
|
|
24
32
|
$s <: within or { `$el.style.$prop = $value`, `$el.style[$prop] = $value`, `$el.style.setProperty($prop, $value)` }
|
|
25
33
|
}
|
|
26
34
|
} where { $tier = "warn" }
|
|
@@ -34,6 +34,8 @@ pattern page_sort() {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
JsCallExpression(callee = $callee, arguments = JsCallArguments(args = $args)) where {
|
|
37
|
+
// GritQL copies its match state for every snippet it tries, so a substring every match must contain goes first.
|
|
38
|
+
$callee <: or { includes "fetch", includes "do" },
|
|
37
39
|
or {
|
|
38
40
|
and {
|
|
39
41
|
$callee <: `fetch.$endpoint`,
|
|
@@ -16,6 +16,13 @@ or {
|
|
|
16
16
|
JsStringLiteralExpression() as $s,
|
|
17
17
|
JsTemplateChunkElement() as $s
|
|
18
18
|
} where {
|
|
19
|
+
// GritQL compiles a regex anew for every node it tries, so a substring every match must contain gates it.
|
|
20
|
+
$s <: or {
|
|
21
|
+
includes "slate-", includes "gray-", includes "zinc-", includes "neutral-", includes "stone-", includes "red-",
|
|
22
|
+
includes "orange-", includes "amber-", includes "yellow-", includes "lime-", includes "green-", includes "emerald-",
|
|
23
|
+
includes "teal-", includes "cyan-", includes "sky-", includes "blue-", includes "indigo-", includes "violet-",
|
|
24
|
+
includes "purple-", includes "fuchsia-", includes "pink-", includes "rose-"
|
|
25
|
+
},
|
|
19
26
|
$s <: r"[\s\S]*(?:^|[\s\"'`{(\[:!])(?:bg|text|border(?:-[tblrxy])?(?:-[se])?|ring(?:-offset)?|fill|stroke|shadow|from|to|via|divide|outline|decoration|placeholder|caret|accent)-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-\d{2,3}(?:[\s\"'`})\]:/!,]|$)[\s\S]*",
|
|
20
27
|
register_diagnostic(
|
|
21
28
|
span = $s,
|
|
@@ -24,6 +24,8 @@ language js(typescript, jsx)
|
|
|
24
24
|
// bind to different text, so the metavariable cannot unify them. Under-reporting, not a false positive.
|
|
25
25
|
//
|
|
26
26
|
JsxAttribute() as $attr where {
|
|
27
|
+
// GritQL copies its match state for every node a pattern tries, so a substring the reported body needs goes first.
|
|
28
|
+
$attr <: includes "st.do.",
|
|
27
29
|
$attr <: contains JsArrowFunctionExpression() as $arrow,
|
|
28
30
|
$arrow <: `($p) => $body`,
|
|
29
31
|
// One bare parameter. A metavariable matches a whole parameter list leniently, so `(a, b)` binds the
|
|
@@ -10,6 +10,8 @@ language js(typescript, jsx)
|
|
|
10
10
|
// points, because the name is also the libs/shared model (`Notification.View`, `cnst.Notification`).
|
|
11
11
|
or {
|
|
12
12
|
JsStaticMemberExpression() as $access where {
|
|
13
|
+
// GritQL copies its match state for every snippet it tries, so a substring every match must contain goes first.
|
|
14
|
+
$access <: includes "navigator",
|
|
13
15
|
$access <: or { `navigator.share`, `navigator.canShare` },
|
|
14
16
|
register_diagnostic(
|
|
15
17
|
span = $access,
|
|
@@ -18,6 +20,7 @@ or {
|
|
|
18
20
|
)
|
|
19
21
|
},
|
|
20
22
|
JsStaticMemberExpression() as $access where {
|
|
23
|
+
$access <: or { includes "navigator", includes "Notification" },
|
|
21
24
|
$access <: or { `navigator.serviceWorker`, `Notification.requestPermission`, `Notification.permission` },
|
|
22
25
|
register_diagnostic(
|
|
23
26
|
span = $access,
|
|
@@ -26,6 +29,7 @@ or {
|
|
|
26
29
|
)
|
|
27
30
|
},
|
|
28
31
|
JsStaticMemberExpression() as $access where {
|
|
32
|
+
$access <: includes "navigator",
|
|
29
33
|
$access <: `navigator.geolocation`,
|
|
30
34
|
register_diagnostic(
|
|
31
35
|
span = $access,
|
|
@@ -34,6 +38,7 @@ or {
|
|
|
34
38
|
)
|
|
35
39
|
},
|
|
36
40
|
JsStaticMemberExpression() as $access where {
|
|
41
|
+
$access <: includes "navigator",
|
|
37
42
|
$access <: `navigator.vibrate`,
|
|
38
43
|
register_diagnostic(
|
|
39
44
|
span = $access,
|
package/lint/no-web-storage.grit
CHANGED
|
@@ -11,6 +11,8 @@ language js(typescript, jsx)
|
|
|
11
11
|
// bare snippet matches the name in any position, a field, an object key or JSX text included.
|
|
12
12
|
or {
|
|
13
13
|
JsIdentifierExpression() as $access where {
|
|
14
|
+
// GritQL copies its match state for every snippet it tries, so a substring every match must contain goes first.
|
|
15
|
+
$access <: includes "Storage",
|
|
14
16
|
$access <: or { `localStorage`, `sessionStorage` },
|
|
15
17
|
register_diagnostic(
|
|
16
18
|
span = $access,
|
|
@@ -19,6 +21,7 @@ or {
|
|
|
19
21
|
)
|
|
20
22
|
},
|
|
21
23
|
JsStaticMemberExpression(object = $root, member = $name) as $access where {
|
|
24
|
+
$name <: includes "Storage",
|
|
22
25
|
$root <: or { `window`, `globalThis`, `self` },
|
|
23
26
|
$name <: or { `localStorage`, `sessionStorage` },
|
|
24
27
|
register_diagnostic(
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//* An env file holds deployment secrets, and a source line, a formatter diff or a rule message quotes them.
|
|
2
|
+
export class WithheldEnvFile {
|
|
3
|
+
static readonly #name = "env[\\\\/]env\\.(?:server|client)(?:\\.[A-Za-z0-9-]+)*\\.ts";
|
|
4
|
+
static readonly #envFile = new RegExp(`[\\\\/]${WithheldEnvFile.#name}$`);
|
|
5
|
+
static readonly #named = new RegExp(WithheldEnvFile.#name);
|
|
6
|
+
static readonly note = "the text is withheld because this file holds secrets";
|
|
7
|
+
|
|
8
|
+
static isEnvFile(fileName: string | undefined) {
|
|
9
|
+
return (
|
|
10
|
+
fileName !== undefined && WithheldEnvFile.#envFile.test(fileName.startsWith("env/") ? `/${fileName}` : fileName)
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static namesEnvFile(text: string) {
|
|
15
|
+
return WithheldEnvFile.#named.test(text);
|
|
16
|
+
}
|
|
17
|
+
}
|
package/mobile/nativeApp.test.ts
CHANGED
|
@@ -273,12 +273,12 @@ describe("NativeApp", () => {
|
|
|
273
273
|
expect(() => NativeApp.assertInstaller("ios", true)).toThrow(/not for ios/);
|
|
274
274
|
});
|
|
275
275
|
|
|
276
|
-
test("opens a dev build on its target's home, the CSR shell under the locale", () => {
|
|
276
|
+
test("opens a dev build on its target's home, the CSR shell under the locale, the device's language to pick", () => {
|
|
277
277
|
expect(new NativeApp(fakeApp(), target({ indexPath: "/explore" })).startPath("en", "ios")).toBe(
|
|
278
|
-
"/en/explore?csr=true&akanMobileTarget=default&akanMobileIndexPath=%2Fexplore",
|
|
278
|
+
"/en/explore?csr=true&akanMobileTarget=default&akanMobileLang=device&akanMobileIndexPath=%2Fexplore",
|
|
279
279
|
);
|
|
280
280
|
expect(new NativeApp(fakeApp(), target({ name: "admin", basePath: "/admin/" })).startPath("ko", "android")).toBe(
|
|
281
|
-
"/ko/admin?csr=true&akanMobileTarget=admin&akanMobileBasePath=admin",
|
|
281
|
+
"/ko/admin?csr=true&akanMobileTarget=admin&akanMobileLang=device&akanMobileBasePath=admin",
|
|
282
282
|
);
|
|
283
283
|
});
|
|
284
284
|
|
|
@@ -289,9 +289,11 @@ describe("NativeApp", () => {
|
|
|
289
289
|
expect(app.indexPath("android")).toBe("/mobile");
|
|
290
290
|
expect(app.indexPath("macos")).toBe("/");
|
|
291
291
|
expect(app.indexPath("windows")).toBe("/");
|
|
292
|
-
expect(app.startPath("en", "macos")).toBe(
|
|
292
|
+
expect(app.startPath("en", "macos")).toBe(
|
|
293
|
+
"/en?csr=true&akanMobileTarget=default&akanMobileLang=device&akanMobileIndexPath=%2F",
|
|
294
|
+
);
|
|
293
295
|
expect(app.startPath("en", "ios")).toBe(
|
|
294
|
-
"/en/mobile?csr=true&akanMobileTarget=default&akanMobileIndexPath=%2Fmobile",
|
|
296
|
+
"/en/mobile?csr=true&akanMobileTarget=default&akanMobileLang=device&akanMobileIndexPath=%2Fmobile",
|
|
295
297
|
);
|
|
296
298
|
});
|
|
297
299
|
|
package/mobile/nativeApp.ts
CHANGED
|
@@ -564,11 +564,11 @@ export class NativeApp {
|
|
|
564
564
|
}
|
|
565
565
|
|
|
566
566
|
/** The first page of a dev build, the target's home as a release bundle opens it; the dev server answers the CSR
|
|
567
|
-
* shell only for `?csr=true
|
|
567
|
+
* shell only for `?csr=true`, under a locale, and `akanMobileLang=device` has the page swap `lang` for the device's. */
|
|
568
568
|
startPath(lang: string, platform: NativePlatform) {
|
|
569
569
|
const basePath = this.target.config.basePath?.replace(/^\/+|\/+$/g, "");
|
|
570
570
|
const indexPath = this.indexPath(platform);
|
|
571
|
-
const params = new URLSearchParams({ csr: "true", akanMobileTarget: this.target.name });
|
|
571
|
+
const params = new URLSearchParams({ csr: "true", akanMobileTarget: this.target.name, akanMobileLang: "device" });
|
|
572
572
|
if (basePath) params.set("akanMobileBasePath", basePath);
|
|
573
573
|
if (indexPath) params.set("akanMobileIndexPath", indexPath);
|
|
574
574
|
const home = [lang, basePath, indexPath]
|