Commit fda45ea
fix(linter/promise/prefer-await-to-callbacks): false positive for
Fixes #12530
The `promise/prefer-await-to-callbacks` rule was incorrectly flagging
DOM event handlers using `addEventListener` as callback patterns that
should use async/await. This resulted in false positives for legitimate
event handling code.
## Problem
The rule was triggering on code like this:
```js
socket.addEventListener('error', (error) => {
// snipped
})
```
This is not a callback-style async operation but rather an event
handler, which should not be converted to async/await.
## Solution
Extended the existing exemption logic to include `addEventListener` and
`removeEventListener` methods alongside the already-exempted `on` and
`once` methods. These are all event handler registration methods that
should not be subject to the callback-to-async/await conversion rule.
## Changes
- Added `addEventListener` and `removeEventListener` to the list of
exempted method names
- Added comprehensive test cases covering various event handler
scenarios
- Verified that the rule still correctly flags actual callback patterns
## Testing
The fix ensures that:
- ✅ WebSocket `addEventListener` calls no longer trigger false positives
- ✅ DOM element `addEventListener`/`removeEventListener` calls are
exempted
- ✅ Existing `on`/`once` event handler exemptions continue to work
- ✅ Actual callback patterns are still correctly detected and flagged
- ✅ All existing tests continue to pass
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 Share your feedback on Copilot coding agent for the chance to win a
$200 gift card! Click
[here](https://survey.alchemer.com/s3/8343779/Copilot-Coding-agent) to
start the survey.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Dunqing <29533304+Dunqing@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>addEventListener (#12537)1 parent d3604f9 commit fda45ea
File tree
1 file changed
+8
-1
lines changed- crates/oxc_linter/src/rules/promise
1 file changed
+8
-1
lines changedLines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
| |||
165 | 168 | | |
166 | 169 | | |
167 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
168 | 175 | | |
169 | 176 | | |
170 | 177 | | |
| |||
0 commit comments