mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 19:50:43 +00:00
fix(lint): skip heavy-check lock for explicit oxlint files
This commit is contained in:
@@ -84,6 +84,36 @@ export function applyLocalOxlintPolicy(args, env, hostResources) {
|
|||||||
return { env: nextEnv, args: nextArgs };
|
return { env: nextEnv, args: nextArgs };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function shouldAcquireLocalHeavyCheckLockForOxlint(
|
||||||
|
args,
|
||||||
|
{ cwd = process.cwd(), env = process.env } = {},
|
||||||
|
) {
|
||||||
|
if (env.OPENCLAW_OXLINT_FORCE_LOCK === "1") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const separatorIndex = args.indexOf("--");
|
||||||
|
const candidateArgs = (() => {
|
||||||
|
if (separatorIndex !== -1) {
|
||||||
|
return args.slice(separatorIndex + 1);
|
||||||
|
}
|
||||||
|
const firstFlagIndex = args.findIndex((arg) => arg.startsWith("-"));
|
||||||
|
return firstFlagIndex === -1 ? args : args.slice(0, firstFlagIndex);
|
||||||
|
})();
|
||||||
|
const explicitTargets = candidateArgs.filter((arg) => arg.length > 0 && !arg.startsWith("-"));
|
||||||
|
if (explicitTargets.length === 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !explicitTargets.every((target) => {
|
||||||
|
try {
|
||||||
|
return fs.statSync(path.resolve(cwd, target)).isFile();
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function shouldThrottleLocalHeavyChecks(env, hostResources) {
|
export function shouldThrottleLocalHeavyChecks(env, hostResources) {
|
||||||
if (!isLocalCheckEnabled(env)) {
|
if (!isLocalCheckEnabled(env)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -3,16 +3,22 @@ import path from "node:path";
|
|||||||
import {
|
import {
|
||||||
acquireLocalHeavyCheckLockSync,
|
acquireLocalHeavyCheckLockSync,
|
||||||
applyLocalOxlintPolicy,
|
applyLocalOxlintPolicy,
|
||||||
|
shouldAcquireLocalHeavyCheckLockForOxlint,
|
||||||
} from "./lib/local-heavy-check-runtime.mjs";
|
} from "./lib/local-heavy-check-runtime.mjs";
|
||||||
|
|
||||||
const { args: finalArgs, env } = applyLocalOxlintPolicy(process.argv.slice(2), process.env);
|
const { args: finalArgs, env } = applyLocalOxlintPolicy(process.argv.slice(2), process.env);
|
||||||
|
|
||||||
const oxlintPath = path.resolve("node_modules", ".bin", "oxlint");
|
const oxlintPath = path.resolve("node_modules", ".bin", "oxlint");
|
||||||
const releaseLock = acquireLocalHeavyCheckLockSync({
|
const releaseLock = shouldAcquireLocalHeavyCheckLockForOxlint(finalArgs, {
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
env,
|
env,
|
||||||
toolName: "oxlint",
|
})
|
||||||
});
|
? acquireLocalHeavyCheckLockSync({
|
||||||
|
cwd: process.cwd(),
|
||||||
|
env,
|
||||||
|
toolName: "oxlint",
|
||||||
|
})
|
||||||
|
: () => {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = spawnSync(oxlintPath, finalArgs, {
|
const result = spawnSync(oxlintPath, finalArgs, {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
acquireLocalHeavyCheckLockSync,
|
acquireLocalHeavyCheckLockSync,
|
||||||
applyLocalOxlintPolicy,
|
applyLocalOxlintPolicy,
|
||||||
applyLocalTsgoPolicy,
|
applyLocalTsgoPolicy,
|
||||||
|
shouldAcquireLocalHeavyCheckLockForOxlint,
|
||||||
} from "../../scripts/lib/local-heavy-check-runtime.mjs";
|
} from "../../scripts/lib/local-heavy-check-runtime.mjs";
|
||||||
import { createScriptTestHarness } from "./test-helpers.js";
|
import { createScriptTestHarness } from "./test-helpers.js";
|
||||||
|
|
||||||
@@ -217,6 +218,39 @@ describe("local-heavy-check-runtime", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("skips the heavy-check lock for explicit oxlint file targets", () => {
|
||||||
|
const cwd = createTempDir("openclaw-oxlint-lock-skip-");
|
||||||
|
const target = path.join(cwd, "sample.ts");
|
||||||
|
fs.writeFileSync(target, "export const ok = true;\n", "utf8");
|
||||||
|
|
||||||
|
expect(
|
||||||
|
shouldAcquireLocalHeavyCheckLockForOxlint(["--type-aware", "--", "sample.ts"], { cwd }),
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps the heavy-check lock for directory targets and broad oxlint runs", () => {
|
||||||
|
const cwd = createTempDir("openclaw-oxlint-lock-keep-");
|
||||||
|
fs.mkdirSync(path.join(cwd, "src"), { recursive: true });
|
||||||
|
fs.writeFileSync(path.join(cwd, "src", "sample.ts"), "export const ok = true;\n", "utf8");
|
||||||
|
|
||||||
|
expect(shouldAcquireLocalHeavyCheckLockForOxlint(["--type-aware", "--", "src"], { cwd })).toBe(
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
expect(shouldAcquireLocalHeavyCheckLockForOxlint(["--type-aware"], { cwd })).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows forcing the oxlint lock back on", () => {
|
||||||
|
const cwd = createTempDir("openclaw-oxlint-lock-force-");
|
||||||
|
fs.writeFileSync(path.join(cwd, "sample.ts"), "export const ok = true;\n", "utf8");
|
||||||
|
|
||||||
|
expect(
|
||||||
|
shouldAcquireLocalHeavyCheckLockForOxlint(["--type-aware", "--", "sample.ts"], {
|
||||||
|
cwd,
|
||||||
|
env: makeEnv({ OPENCLAW_OXLINT_FORCE_LOCK: "1" }),
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it("reclaims stale local heavy-check locks from dead pids", () => {
|
it("reclaims stale local heavy-check locks from dead pids", () => {
|
||||||
const cwd = createTempDir("openclaw-local-heavy-check-");
|
const cwd = createTempDir("openclaw-local-heavy-check-");
|
||||||
const commonDir = path.join(cwd, ".git");
|
const commonDir = path.join(cwd, ".git");
|
||||||
|
|||||||
Reference in New Issue
Block a user