Skip to content

Commit 13dbb09

Browse files
committed
fix(json): resolve lint warnings (prefer-exponentiation-operator, curly, no-unnecessary-type-assertion)
1 parent dc53ea3 commit 13dbb09

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/infra/json-files.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,13 @@ describe("json file helpers", () => {
201201
let callCount = 0;
202202

203203
vi.spyOn(fsPromises, "lstat").mockImplementation(async (p, ...args) => {
204-
const stat = await origLstat(p as fs.PathLike, ...(args as any));
204+
const stat = await origLstat(p, ...args);
205205
const pathStr = typeof p === "string" ? p : String(p);
206206
if (pathStr === targetPath) {
207207
callCount++;
208208
if (callCount <= targetCallCount) {
209209
// Modify ino: for BigInt ino add 100n, for number ino add 100
210-
const modifiedIno =
211-
typeof stat.ino === "bigint" ? stat.ino + 100n : (stat.ino as number) + 100;
210+
const modifiedIno = typeof stat.ino === "bigint" ? stat.ino + 100n : stat.ino + 100;
212211

213212
// Clone stat preserving prototype, override ino
214213
return Object.assign(Object.create(Object.getPrototypeOf(stat)), stat, {

src/infra/json-files.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import "./fs-safe-defaults.js";
2-
import { replaceFileAtomic } from "./replace-file.js";
32
import {
43
JsonFileReadError,
54
readJson as readJsonImpl,
65
readJsonIfExists as readJsonIfExistsImpl,
76
} from "@openclaw/fs-safe/json";
7+
import { replaceFileAtomic } from "./replace-file.js";
88

99
export {
1010
JsonFileReadError,
@@ -51,7 +51,7 @@ async function withRetryOnFileChanged<T>(fn: () => Promise<T>): Promise<T> {
5151
return await fn();
5252
} catch (err) {
5353
if (isFileChangedDuringRead(err) && attempt < RETRY_MAX_ATTEMPTS - 1) {
54-
await new Promise((r) => setTimeout(r, RETRY_BASE_DELAY_MS * Math.pow(2, attempt)));
54+
await new Promise((r) => setTimeout(r, RETRY_BASE_DELAY_MS * 2 ** attempt));
5555
continue;
5656
}
5757
throw err;
@@ -75,7 +75,9 @@ export async function readJsonIfExists<T>(filePath: string): Promise<T | null> {
7575
try {
7676
return await withRetryOnFileChanged(() => readJsonIfExistsImpl<T>(filePath));
7777
} catch (err) {
78-
if (err instanceof JsonFileReadError) throw err;
78+
if (err instanceof JsonFileReadError) {
79+
throw err;
80+
}
7981
throw new JsonFileReadError(filePath, "read", err);
8082
}
8183
}

0 commit comments

Comments
 (0)