Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/core/src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ export async function writeFileWithLock(path: string, content: string, retry = 3
return
}

let relase: () => Promise<void> | undefined
let release: () => Promise<void> | undefined
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix the type annotation precedence.

The type () => Promise<void> | undefined means a function that returns either Promise<void> or undefined. However, lockfile.lock() returns a function that always returns Promise<void>, never undefined. The variable itself can be undefined before assignment.

Apply this diff to correct the type annotation:

-  let release: () => Promise<void> | undefined
+  let release: (() => Promise<void>) | undefined

This change clarifies that release is either undefined or a function returning Promise<void>, and may eliminate the need for the @ts-expect-error directive below.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let release: () => Promise<void> | undefined
let release: (() => Promise<void>) | undefined
🤖 Prompt for AI Agents
In packages/core/src/files.ts around line 111, the type annotation for release
is wrong: it currently reads as a function that may return undefined. Update the
declaration so release is either undefined or a function returning Promise<void>
(i.e. change to a union where the function type is grouped), and remove the
now-unnecessary @ts-expect-error below (or adjust any usage checks) so
TypeScript correctly understands release can be undefined prior to assignment
but, when assigned, is a () => Promise<void>.


try {
try {
// 获取文件锁
relase = await lockfile.lock(path, { realpath: false })
release = await lockfile.lock(path, { realpath: false })
}
catch {
// 获取文件锁失败
Expand All @@ -125,8 +125,8 @@ export async function writeFileWithLock(path: string, content: string, retry = 3
finally {
// eslint-disable-next-line ts/ban-ts-comment
// @ts-expect-error'
if (relase) {
await relase() // 释放文件锁
if (release) {
Comment on lines 126 to +128
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Clean up type suppression if possible.

The @ts-expect-error directive suggests a type checking issue. If the type annotation on line 111 is corrected, this suppression may no longer be necessary. Additionally, the comment has a typographical error (extra quote at the end).

Consider removing the type suppression after fixing the type annotation, or at minimum fix the comment typo:

-    // eslint-disable-next-line ts/ban-ts-comment
-    // @ts-expect-error'
     if (release) {

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/core/src/files.ts around lines 126 to 128, the inline comment
currently reads "// @ts-expect-error'" and suppresses a type error; fix the
underlying type annotation at line 111 so the suppression is no longer needed,
remove the entire eslint/ts-ignore block, and if you must keep a suppression,
correct the typo by removing the trailing quote and use the minimal necessary
directive (e.g. // @ts-expect-error) with a short rationale comment.

await release() // 释放文件锁
}
}
}