Why doesn’t AI Guard automatically fix empty catch blocks and floating promises?
Because the only fix a tool can apply without understanding the code would hide the problem, not solve it. Inserting a TODO comment into an empty catch block, or void before an unawaited call, makes the finding disappear while the error is still swallowed, and an agent running eslint --fix would do exactly that. Since 1.4.7 these two rules offer editor suggestions that a person applies instead.
By the AI Guard maintainers · Last updated · Applies to v1.4.7
What changed in 1.4.7
Before 1.4.7, no-empty-catch had an automatic fix that inserted /* TODO: handle error */ and no-floating-promise had one that inserted void. Both made the lint finding go away. Neither handled the error. 1.4.7 removed both fixes.
// Before 1.4.7, eslint --fix turned this…try { await saveOrder(order);} catch (e) {} // …into this. The error is still swallowed; the finding is gone.try { await saveOrder(order);} catch (e) { /* TODO: handle error */ }An agent told to "make lint pass" runs --fix, sees a clean result and moves on. A guardrail that the agent can fix away is not a guardrail.
What happens now
- `no-empty-catch` reports empty catch blocks, and also a catch block that contains only a
TODO,FIXMEorXXXcomment, because those comments are not an explanation. A comment that explains why the error is ignored is accepted. Editors offer one suggestion: rethrow the error. - `no-floating-promise` reports async calls that are not awaited, returned or handled with
.catch(). Editors offer two suggestions: addawait(inside an async function), orvoidfor a call that really is fire-and-forget.
Suggestions are applied one at a time by a person in the editor; eslint --fix does not apply them. Code that relied on the old fixes will see these findings again after upgrading.
Which rules still have automatic fixes
Three rules keep an automatic fix, because the fix changes the code in a way that does not hide a problem:
| Rule | What the fix does |
|---|---|
| `no-hardcoded-secret` | Moves the value to process.env |
| `no-await-in-loop` | Rewrites simple independent loops to Promise.all |
| `no-invisible-unicode` | Removes invisible characters from comments and escapes them in strings, templates and regexes |