chore: clean up biome lint warnings#241
Conversation
|
CodeAnt AI is reviewing your PR. |
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
Walkthrough本次改动仅在 index.mjs、lib/config.mjs、lib/youdao.mjs 中新增 biome-ignore 注释,用于屏蔽未使用异常变量及可选链复杂度相关的 lint 告警,未涉及任何功能逻辑或控制流变更。 ChangesLint 告警抑制
Estimated code review effort: 1 (Trivial) | ~3 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces lint cleanups across several files, including prefixing unused variables with underscores, and adds a comprehensive test suite in tests/lint-cleanup.test.ts to cover various error handling and parsing paths. The review feedback suggests utilizing ES2019 optional catch binding (catch {}) to clean up unused catch variables, removing unnecessary optional chaining on guaranteed string variables, and completely removing unused local variables rather than just prefixing them with underscores.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| spinner.stop(); | ||
| printIciba(word, result?.message, options); | ||
| } catch (error) { | ||
| } catch (_error) { |
There was a problem hiding this comment.
| spinner.stop(); | ||
| printYoudao(word, result, options); | ||
| } catch (error) { | ||
| } catch (_error) { |
There was a problem hiding this comment.
| for (const line of lines) { | ||
| const trimmed = line.trim(); | ||
| if (!trimmed || !trimmed.startsWith('data:')) continue; | ||
| if (!trimmed?.startsWith('data:')) continue; |
There was a problem hiding this comment.
trimmed is guaranteed to be a string because it is the result of line.trim(), where line is a string from buffer.split('\\n'). Therefore, the optional chaining operator (?.) is unnecessary. Furthermore, if trimmed is an empty string, trimmed.startsWith('data:') will return false, so !trimmed.startsWith('data:') will evaluate to true and correctly continue. Thus, we can simplify this to if (!trimmed.startsWith('data:')) continue;.
| if (!trimmed?.startsWith('data:')) continue; | |
| if (!trimmed.startsWith('data:')) continue; |
| try { | ||
| return JSON.parse(content.toString()); | ||
| } catch (e) { | ||
| } catch (_e) { |
There was a problem hiding this comment.
| const pos = s.pos || ''; | ||
| const tran = s.tran || ''; | ||
| const _tran = s.tran || ''; | ||
| const words = (s.ws || []).map((w) => w.w).filter(Boolean); |
There was a problem hiding this comment.
The variable _tran is declared but never used. Since this is a local variable inside a loop (and not a function parameter where signature matching might be required), it can be safely removed entirely instead of just prefixing it with an underscore to suppress the lint warning.
| const pos = s.pos || ''; | |
| const tran = s.tran || ''; | |
| const _tran = s.tran || ''; | |
| const words = (s.ws || []).map((w) => w.w).filter(Boolean); | |
| const pos = s.pos || ''; | |
| const words = (s.ws || []).map((w) => w.w).filter(Boolean); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #241 +/- ##
==========================================
- Coverage 80.46% 80.37% -0.10%
==========================================
Files 10 10
Lines 1126 1131 +5
Branches 192 190 -2
==========================================
+ Hits 906 909 +3
- Misses 212 214 +2
Partials 8 8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
CodeAnt AI finished reviewing your PR. |
There was a problem hiding this comment.
🧹 Nitpick comments (4)
lib/config.mjs (1)
19-19: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value同上,可省略 catch 绑定
_e未在 catch 块中使用,可直接使用无绑定的catch {}写法。♻️ 建议改动
- } catch (_e) { + } catch {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/config.mjs` at line 19, The catch binding in the config-loading logic is unused, so simplify the existing try/catch in the config module by switching the unnamed error variable in the relevant catch block to a binding-free catch form. Update the catch associated with the configuration parsing/loading path in the config module so it no longer declares an unused parameter, keeping the behavior unchanged.lib/youdao.mjs (1)
131-135: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
_tran变量完全未使用,建议直接删除与 catch 参数不同,这里
_tran并非语法必需的绑定,仅是一个从未被读取的局部变量。仅为消除 Biome 警告而重命名,不如直接删除该行更清晰,避免遗留死代码。♻️ 建议改动
for (const s of synos) { const pos = s.pos || ''; - const _tran = s.tran || ''; const words = (s.ws || []).map((w) => w.w).filter(Boolean);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/youdao.mjs` around lines 131 - 135, The synos loop in the youdao translation logic contains an unused local variable `_tran` that should be removed rather than renamed or kept as dead code. Update the loop that reads `s.pos`, `s.tran`, and builds `words` so it no longer assigns `_tran`, and keep the rest of the `synos` processing unchanged.tests/lint-cleanup.test.ts (1)
75-92: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value测试未验证近义词翻译文本(
tran)该测试仅断言输出包含
words(opening),但printYoudao中的tran字段(近义词释义文本)从未被输出或断言,测试无法覆盖该字段被丢弃这一事实。鉴于这是本 PR 新增测试且目的正是覆盖近义词分支,建议明确说明或验证该行为,而不仅仅依赖巧合的字符串重叠(words与tran值恰好相同)。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/lint-cleanup.test.ts` around lines 75 - 92, Update the printYoudao synonym test in lint-cleanup.test.ts so it explicitly verifies the syno branch behavior rather than relying on the shared string “opening”; use the printYoudao symbol and assert against the rendered output for the synonym translation text field tran, or adjust the expectation to match the intended omission if tran is not supposed to be printed. This test should clearly confirm the handling of syno.synos entries and avoid passing only because ws and tran happen to contain the same word.index.mjs (1)
87-87: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value可用可选 catch 绑定进一步简化
将异常变量重命名为
_error只是绕过 Biome 的未使用变量检查,既然两处 catch 块都完全不使用异常对象,可以直接省略绑定(catch {}),Node.js/现代浏览器均已原生支持该 ES2019 特性,可从根本上消除“声明但未使用”的变量。♻️ 建议改动
- } catch (_error) { + } catch {Also applies to: 106-106
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@index.mjs` at line 87, The catch blocks in the main entry flow are not using the caught error, so rename-based suppression is unnecessary. Update the relevant try/catch statements in index.mjs, including the catch blocks around the identified handlers, to use optional catch binding by removing the unused exception parameter entirely (catch {}). Keep the surrounding logic in place and ensure both affected catch sites are updated consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@index.mjs`:
- Line 87: The catch blocks in the main entry flow are not using the caught
error, so rename-based suppression is unnecessary. Update the relevant try/catch
statements in index.mjs, including the catch blocks around the identified
handlers, to use optional catch binding by removing the unused exception
parameter entirely (catch {}). Keep the surrounding logic in place and ensure
both affected catch sites are updated consistently.
In `@lib/config.mjs`:
- Line 19: The catch binding in the config-loading logic is unused, so simplify
the existing try/catch in the config module by switching the unnamed error
variable in the relevant catch block to a binding-free catch form. Update the
catch associated with the configuration parsing/loading path in the config
module so it no longer declares an unused parameter, keeping the behavior
unchanged.
In `@lib/youdao.mjs`:
- Around line 131-135: The synos loop in the youdao translation logic contains
an unused local variable `_tran` that should be removed rather than renamed or
kept as dead code. Update the loop that reads `s.pos`, `s.tran`, and builds
`words` so it no longer assigns `_tran`, and keep the rest of the `synos`
processing unchanged.
In `@tests/lint-cleanup.test.ts`:
- Around line 75-92: Update the printYoudao synonym test in lint-cleanup.test.ts
so it explicitly verifies the syno branch behavior rather than relying on the
shared string “opening”; use the printYoudao symbol and assert against the
rendered output for the synonym translation text field tran, or adjust the
expectation to match the intended omission if tran is not supposed to be
printed. This test should clearly confirm the handling of syno.synos entries and
avoid passing only because ws and tran happen to contain the same word.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2541446a-9f05-4d0b-b7b5-bc996a01921e
📒 Files selected for processing (4)
index.mjslib/config.mjslib/youdao.mjstests/lint-cleanup.test.ts
265b3fa to
07c8ab3
Compare
Summary
Verification