bito-code-review[bot] commented on code in PR #39535:
URL: https://github.com/apache/superset/pull/39535#discussion_r3314976206
##########
superset-frontend/packages/superset-ui-core/src/utils/lruCache.ts:
##########
@@ -55,7 +55,12 @@ class LRUCache<T> {
throw new TypeError('The LRUCache key must be string.');
}
if (this.cache.size >= this.capacity) {
- this.cache.delete(this.cache.keys().next().value);
+ // Forward-compat: TS 6.0 types IteratorResult.value as `string |
undefined`
+ // when not explicitly checked; guard before passing to Map#delete.
+ const oldestKey = this.cache.keys().next().value;
+ if (oldestKey !== undefined) {
+ this.cache.delete(oldestKey);
+ }
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Dead code guard introduced</b></div>
<div id="fix">
The `if (oldestKey !== undefined)` guard is unreachable dead code. The guard
sits inside `if (this.cache.size >= this.capacity)` where the cache has
`capacity ≥ 1` elements, so `keys().next().value` cannot be undefined. If a
future regression caused `undefined`, silently skipping `delete()` would hide
the bug rather than surface it — making the code less safe, not more. Revert to
the original single-line deletion.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
```
--- superset-frontend/packages/superset-ui-core/src/utils/lruCache.ts
+++ superset-frontend/packages/superset-ui-core/src/utils/lruCache.ts
@@ -55,11 +55,7 @@ class LRUCache<T> {
throw new TypeError('The LRUCache key must be string.');
}
if (this.cache.size >= this.capacity) {
- // Forward-compat: TS 6.0 types IteratorResult.value as `string |
undefined`
- // when not explicitly checked; guard before passing to Map#delete.
- const oldestKey = this.cache.keys().next().value;
- if (oldestKey !== undefined) {
- this.cache.delete(oldestKey);
- }
+ this.cache.delete(this.cache.keys().next().value);
}
this.cache.set(key, value);
}
```
</div>
</details>
</div>
<small><i>Code Review Run #d7878b</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]