Skip to content

Commit 90d1514

Browse files
roodboiclaude
andcommitted
style(daemon): hoist regexes to module scope for the repo lint profile
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 61ac7f6 commit 90d1514

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/daemon/launchd.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,16 @@ export function isVirtualExecutablePath(path: string): boolean {
218218
/**
219219
* Extracts ProgramArguments[0] from rendered launchd plist text.
220220
*/
221+
const PLIST_STRING_PATTERN = /<string>([^<]+)<\/string>/;
222+
221223
export function extractLaunchdProgramPath(opts: {
222224
readonly plistText: string;
223225
}): string | null {
224226
const anchor = opts.plistText.indexOf("<key>ProgramArguments</key>");
225227
if (anchor < 0) {
226228
return null;
227229
}
228-
const match = opts.plistText.slice(anchor).match(/<string>([^<]+)<\/string>/);
230+
const match = opts.plistText.slice(anchor).match(PLIST_STRING_PATTERN);
229231
return match?.[1] ?? null;
230232
}
231233

src/daemon/process.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function sleep({ ms }: { readonly ms: number }): Promise<void> {
6868
}
6969

7070
const DAEMON_COMMAND_MARKER = "daemon start --foreground";
71+
const WHITESPACE_PATTERN = /\s+/;
7172

7273
/**
7374
* Finds hackd processes that the pid file does not track ("orphans").
@@ -119,13 +120,13 @@ export async function findOrphanDaemonProcesses(opts: {
119120
* would also kill unrelated processes that merely mention them.
120121
*/
121122
function isHackDaemonCommand(opts: { readonly command: string }): boolean {
122-
const firstToken = opts.command.trim().split(/\s+/)[0] ?? "";
123+
const firstToken = opts.command.trim().split(WHITESPACE_PATTERN)[0] ?? "";
123124
const base = firstToken.split("/").pop()?.toLowerCase() ?? "";
124125
if (base === "hack" || base.startsWith("hack-")) {
125126
return true;
126127
}
127128
if (base === "bun") {
128-
const secondToken = opts.command.trim().split(/\s+/)[1] ?? "";
129+
const secondToken = opts.command.trim().split(WHITESPACE_PATTERN)[1] ?? "";
129130
const secondBase = secondToken.split("/").pop()?.toLowerCase() ?? "";
130131
return secondBase === "index.ts" || secondBase.startsWith("hack");
131132
}

0 commit comments

Comments
 (0)