refactor: make lint workflows Oxlint-only

This commit is contained in:
Turtle
2026-08-09 14:55:06 +08:00
parent 8c124f84b6
commit 7016ad93de
24 changed files with 323 additions and 253 deletions
+45 -3
View File
@@ -3,6 +3,12 @@ import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
const oxlintCli = fileURLToPath(new URL('../node_modules/oxlint/bin/oxlint', import.meta.url))
const MAX_CAPTURED_OUTPUT_BYTES = 64 * 1024 * 1024
const FIX_FLAGS = new Set(['--fix', '--fix-dangerously', '--fix-suggestions'])
function isFixInvocation(args: readonly string[]): boolean {
return args.some(arg => FIX_FLAGS.has(arg))
}
/** Complete Oxlint child-process arguments and environment. */
export interface OxlintInvocation {
@@ -32,14 +38,50 @@ export function resolveOxlintInvocation(args: readonly string[], env: NodeJS.Pro
}
}
function completeFrom(result: { readonly signal: NodeJS.Signals | null; readonly status: number | null }): void {
if (result.signal !== null) {
process.kill(process.pid, result.signal)
return
}
process.exitCode = result.status ?? 1
}
function main(): void {
const invocation = resolveOxlintInvocation(process.argv.slice(2), process.env)
const result = spawnSync(process.execPath, [oxlintCli, ...invocation.args], {
if (!isFixInvocation(invocation.args)) {
const result = spawnSync(process.execPath, [oxlintCli, ...invocation.args], {
env: invocation.env,
stdio: 'inherit',
})
if (result.error !== undefined) throw result.error
completeFrom(result)
return
}
const first = spawnSync(process.execPath, [oxlintCli, ...invocation.args], {
encoding: 'utf8',
env: invocation.env,
maxBuffer: MAX_CAPTURED_OUTPUT_BYTES,
})
if (first.error !== undefined) throw first.error
if (first.signal !== null) {
completeFrom(first)
return
}
if (first.status === 0) {
process.stdout.write(first.stdout)
process.stderr.write(first.stderr)
process.exitCode = 0
return
}
// Overlapping JS-plugin fixes can expose one more fixable diagnostic after the first pass.
const second = spawnSync(process.execPath, [oxlintCli, ...invocation.args], {
env: invocation.env,
stdio: 'inherit',
})
if (result.error !== undefined) throw result.error
process.exitCode = result.status ?? 1
if (second.error !== undefined) throw second.error
completeFrom(second)
}
const entrypoint = process.argv[1]