Skip to content

Commit 8998eac

Browse files
committed
chore: sync fleet-canonical scripts/fix.mts from socket-repo-template@c7eff9e
Refresh of the auto-fix script to the new fleet-canonical form. Functional change vs. prior local copy: extra argv now flows through to `pnpm run lint --fix`, so `pnpm run fix --all`, `pnpm run fix --staged`, and explicit file paths all work uniformly across the fleet. Eliminates the prior split where socket-addon + socket-stuie used an inline `oxfmt --write . && oxlint --fix` form that rejected `--all`. Both adopted scripts/fix.mts in their own commits today; this brings the rest of the fleet to byte-identical with the new canonical version. Synced byte-identical from socket-repo-template via sync-scaffolding.
1 parent 23698db commit 8998eac

1 file changed

Lines changed: 25 additions & 27 deletions

File tree

scripts/fix.mts

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,33 @@
33
* tools (zizmor, agentshield) if available.
44
*
55
* Steps:
6-
* 1. pnpm run lint --fix — oxlint + oxfmt
7-
* 2. zizmor --fix .github/ — GitHub Actions workflow fixes (if .github/ exists)
8-
* 3. agentshield scan --fix — Claude config fixes (if .claude/ exists)
6+
* 1. pnpm run lint --fix — oxlint + oxfmt (forwards extra argv like --all)
7+
* 2. zizmor --fix .github/ — GitHub Actions workflow fixes
8+
* (skipped if .github/ doesn't exist)
9+
* 3. agentshield scan --fix — Claude config fixes
10+
* (skipped if .claude/ or agentshield isn't installed)
11+
*
12+
* Forwards `process.argv.slice(2)` to the lint step, so
13+
* `pnpm run fix --all` runs `pnpm run lint --fix --all` (full-tree
14+
* fix), and `pnpm run fix --staged` does the staged-only flow.
915
*/
1016

1117
import { existsSync } from 'node:fs'
1218
import process from 'node:process'
1319

14-
import type { Logger } from '@socketsecurity/lib/logger'
1520
import { getDefaultLogger } from '@socketsecurity/lib/logger'
16-
import type { SpawnResult } from '@socketsecurity/lib/spawn'
1721
import { spawn } from '@socketsecurity/lib/spawn'
18-
import { errorMessage } from './utils/error-message.mts'
1922

2023
const WIN32 = process.platform === 'win32'
21-
const logger: Logger = getDefaultLogger()
22-
23-
type RunOptions = {
24-
label?: string
25-
required?: boolean
26-
}
27-
28-
function getErrorMessage(error: unknown): string {
29-
return errorMessage(error)
30-
}
24+
const logger = getDefaultLogger()
3125

3226
async function run(
3327
cmd: string,
3428
args: string[],
35-
{ label, required = true }: RunOptions = {},
29+
{ label, required = true }: { label?: string; required?: boolean } = {},
3630
): Promise<number> {
3731
try {
38-
const result: Awaited<SpawnResult> = await spawn(cmd, args, {
32+
const result = await spawn(cmd, args, {
3933
shell: WIN32,
4034
stdio: 'inherit',
4135
})
@@ -49,21 +43,24 @@ async function run(
4943
}
5044
return 0
5145
} catch (e) {
46+
const msg = e instanceof Error ? e.message : String(e)
5247
if (!required) {
53-
logger.warn(`${label || cmd}: ${getErrorMessage(e)} (non-blocking)`)
48+
logger.warn(`${label || cmd}: ${msg} (non-blocking)`)
5449
return 0
5550
}
5651
throw e
5752
}
5853
}
5954

6055
async function main(): Promise<void> {
61-
const extraArgs: string[] = process.argv.slice(2)
62-
63-
// Step 1: Lint fix — delegates to per-package lint scripts.
64-
const lintExit = await run('pnpm', ['run', 'lint', '--fix', ...extraArgs], {
65-
label: 'lint --fix',
66-
})
56+
// Step 1: Lint fix — delegates to scripts/lint.mts which runs both
57+
// oxfmt and oxlint. Forward extra argv so `--all` / `--staged` /
58+
// explicit file paths reach the lint runner unchanged.
59+
const lintExit = await run(
60+
'pnpm',
61+
['run', 'lint', '--fix', ...process.argv.slice(2)],
62+
{ label: 'lint --fix' },
63+
)
6764
if (lintExit) {
6865
process.exitCode = lintExit
6966
}
@@ -87,7 +84,8 @@ async function main(): Promise<void> {
8784
}
8885
}
8986

90-
main().catch((error: unknown) => {
91-
logger.error(error)
87+
main().catch((e: unknown) => {
88+
const msg = e instanceof Error ? e.message : String(e)
89+
logger.error(msg)
9290
process.exitCode = 1
9391
})

0 commit comments

Comments
 (0)