Skip to content

Biome showcase #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function greet(name: string) {
console.log("Hello, " + name)
}

let unused = 123
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove unused variable.

The unused variable is declared but never used in the code.

-let unused = 123
📝 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 unused = 123
🤖 Prompt for AI Agents
In test.ts at line 5, there is a variable named 'unused' declared but never
used. Remove the declaration of this unused variable to clean up the code and
avoid unnecessary declarations.


const x = 1
x = 2
Comment on lines +7 to +8
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix const reassignment error.

You cannot reassign a value to a constant. This will cause a compilation error.

-const x = 1
-x = 2
+let x = 1
+x = 2
📝 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
const x = 1
x = 2
let x = 1
x = 2
🧰 Tools
🪛 Biome (1.9.4)

[error] 7-8: Can't assign x because it's a constant

This is where the variable is defined as constant

Unsafe fix: Replace const with let if you assign it to a new value.

(lint/correctness/noConstAssign)

🤖 Prompt for AI Agents
In test.ts around lines 7 to 8, the code attempts to reassign a value to a
constant variable 'x', which causes a compilation error. To fix this, change the
declaration of 'x' from 'const' to 'let' if reassignment is needed, or avoid
reassigning 'x' altogether if it should remain constant.


const items = [1, 2, 3]
items.forEach(async item => {
await fetch(`/api/${item}`)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling to fetch calls.

The fetch call lacks error handling, which could cause unhandled promise rejections.

-  await fetch(`/api/${item}`)
+  await fetch(`/api/${item}`).catch(error => {
+    console.error(`Failed to fetch /api/${item}:`, error)
+  })
📝 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
await fetch(`/api/${item}`)
await fetch(`/api/${item}`).catch(error => {
console.error(`Failed to fetch /api/${item}:`, error)
})
🤖 Prompt for AI Agents
In test.ts at line 12, the fetch call lacks error handling which can lead to
unhandled promise rejections. Wrap the fetch call in a try-catch block or use
.catch() to handle any errors that may occur during the fetch operation. Ensure
that any errors are logged or handled appropriately to prevent the application
from crashing.

})
Comment on lines +10 to +13
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace forEach with Promise.all for async operations.

Using forEach with async callbacks creates side effects and doesn't wait for completion. Replace with Promise.all and map for proper async handling.

-items.forEach(async item => {
-  await fetch(`/api/${item}`)
-})
+await Promise.all(items.map(async item => {
+  return fetch(`/api/${item}`)
+}))
📝 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
const items = [1, 2, 3]
items.forEach(async item => {
await fetch(`/api/${item}`)
})
const items = [1, 2, 3]
await Promise.all(items.map(async item => {
return fetch(`/api/${item}`)
}))
🤖 Prompt for AI Agents
In test.ts around lines 10 to 13, the code uses forEach with an async callback,
which does not wait for the async operations to complete. Replace the forEach
loop with Promise.all combined with map to run all fetch calls concurrently and
properly await their completion. This ensures all async operations finish before
proceeding.


greet("world")