@devries-cameron20 / t3code Mirror · read-only / commits / aef8b6fcf0
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 19:30 UTC

fix(scripts): mobile lint fails instead of passing when ktlint or detekt is missing (#22896)

Co-authored-by: Shubh <shubh@shubhxho.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 21, 2026 at 14:12 UTC aef8b6fcf0f6cc5cc901618b3723dd60317e7ac4
2 files changed +71 -23
scripts/mobile-native-static-check.test.ts new
+26
@@ -0,0 +1,26 @@
1 +import { assert, it } from "@effect/vitest";
2 +import * as Effect from "effect/Effect";
3 +
4 +import { requireKotlinTools } from "./mobile-native-static-check.ts";
5 +
6 +it.effect("allows Kotlin checks when ktlint and detekt are on PATH", () =>
7 + requireKotlinTools({ ktlint: true, detekt: true }),
8 +);
9 +
10 +it.effect("fails when ktlint or detekt is missing instead of skipping", () =>
11 + Effect.gen(function* () {
12 + const ktlintError = yield* requireKotlinTools({ ktlint: false, detekt: true }).pipe(
13 + Effect.flip,
14 + );
15 + if (ktlintError._tag !== "NativeStaticCheckMissingToolError") {
16 + return assert.fail(`Unexpected error: ${ktlintError._tag}`);
17 + }
18 + assert.deepEqual(ktlintError.commands, ["ktlint"]);
19 +
20 + const bothError = yield* requireKotlinTools({ ktlint: false, detekt: false }).pipe(Effect.flip);
21 + if (bothError._tag !== "NativeStaticCheckMissingToolError") {
22 + return assert.fail(`Unexpected error: ${bothError._tag}`);
23 + }
24 + assert.deepEqual(bothError.commands, ["ktlint", "detekt"]);
25 + }),
26 +);
scripts/mobile-native-static-check.ts
+45 -23
@@ -63,6 +63,21 @@ export class NativeStaticCheckCommandError extends Schema.TaggedError<NativeStat
63 }
64 }
65
66 +const kotlinToolCommands = ["ktlint", "detekt"] as const;
67 +
68 +export class NativeStaticCheckMissingToolError extends Schema.TaggedError<NativeStaticCheckMissingToolError>()(
69 + "NativeStaticCheckMissingToolError",
70 + {
71 + commands: Schema.Array(Schema.Literals(kotlinToolCommands)),
72 + },
73 +) {
74 + override get message(): string {
75 + const names = this.commands.join(" and ");
76 + const verb = this.commands.length === 1 ? "is" : "are";
77 + return `${names} ${verb} not installed; cannot run Kotlin static analysis. Install via \`brew bundle install --file apps/mobile/Brewfile\` or put the JVM tools on PATH.`;
78 + }
79 +}
80 +
81 const tools = [
82 {
83 command: "swiftlint",
@@ -117,6 +132,16 @@ const warnMissingTool = (tool: NativeStaticTool, checkName: string) =>
132 `${tool.command} is not installed; skipping ${checkName}. Install it with '${tool.installHint}' or run 'brew bundle install --file apps/mobile/Brewfile'.`,
133 );
134
135 +export const requireKotlinTools = Effect.fn("requireKotlinTools")(function* (available: {
136 + readonly ktlint: boolean;
137 + readonly detekt: boolean;
138 +}) {
139 + const missing = kotlinToolCommands.filter((command) => !available[command]);
140 + if (missing.length > 0) {
141 + return yield* new NativeStaticCheckMissingToolError({ commands: missing });
142 + }
143 +});
144 +
145 export const runCommand = Effect.fn("runCommand")(function* (
146 command: string,
147 args: ReadonlyArray<string>,
@@ -253,29 +278,24 @@ const runNativeStaticChecks = Effect.fn("runNativeStaticChecks")(function* () {
278 }
279
280 if (kotlinSources.length > 0) {
256 - const relativeKotlinSources = kotlinSources.map((source) => path.relative(root, source));
257 -
258 - if (availableTools.get("ktlint")) {
259 - yield* runCommand("ktlint", relativeKotlinSources, root);
260 - } else {
261 - yield* warnMissingTool(tools[1], "ktlint");
262 - }
281 + yield* requireKotlinTools({
282 + ktlint: availableTools.get("ktlint") === true,
283 + detekt: availableTools.get("detekt") === true,
284 + });
285
264 - if (availableTools.get("detekt")) {
265 - yield* runCommand(
266 - "detekt",
267 - [
268 - "--config",
269 - "detekt.yml",
270 - "--input",
271 - relativeKotlinSources.join(","),
272 - "--build-upon-default-config",
273 - ],
274 - root,
275 - );
276 - } else {
277 - yield* warnMissingTool(tools[2], "detekt");
278 - }
286 + const relativeKotlinSources = kotlinSources.map((source) => path.relative(root, source));
287 + yield* runCommand("ktlint", relativeKotlinSources, root);
288 + yield* runCommand(
289 + "detekt",
290 + [
291 + "--config",
292 + "detekt.yml",
293 + "--input",
294 + relativeKotlinSources.join(","),
295 + "--build-upon-default-config",
296 + ],
297 + root,
298 + );
299 }
300
301 yield* Console.log("Skipping generated native project folders: android/, ios/.");
@@ -284,7 +304,9 @@ const runNativeStaticChecks = Effect.fn("runNativeStaticChecks")(function* () {
304 export const mobileNativeStaticCheckCommand = Command.make("mobile-native-static-check", {}, () =>
305 runNativeStaticChecks(),
306 ).pipe(
287 - Command.withDescription("Run mobile native static analysis when native tools are available."),
307 + Command.withDescription(
308 + "Run mobile native static analysis. SwiftLint may be skipped when unavailable; ktlint and detekt are required when Kotlin sources exist.",
309 + ),
310 );
311
312 if (import.meta.main) {