Commit 7a0e931
committed
fix(linter): Update the unicorn/prefer-add-event-listener rule with new JavaScript APIs (#15581)
This will cause new violations for some users if they're using particularly new APIs, but that should be fine.
For users migrating from the ESLint plugin, I wonder if we should consider calling out in the docs that this rule (and other rules of this nature) will potentially differ from the original Unicorn rule due to data updates over time? I ran into problems with the jsx-a11y rule in my work codebase due to this kind of improvement, so it may be worth calling out.
This also renames `animationStart` and `animationEnd` to be lowercase, as I believe this discrepancy was a mistake in the porting process. The original rule undercases these when processing them with vendor prefixes: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/609d4870f3731d39bd5b5f184628e2cf06578dba/rules/shared/dom-events.js
Sources:
- https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes#list_of_global_event_handler_attributes
- https://github.com/mdn/browser-compat-data/blob/d5d5f2e21ef3f798784d1f5f75bde7c7f10f250e/api/Element.json
- https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/f915ac0c987300d75af41bfe4a34bb29a0fb941f/baselines/dom.generated.d.ts
I used AI to compare the lists since they're in such different formats and then checked against MDN to ensure the additions were actually real. Prompt for future reference, since I think the pattern is useful:
```
Are there any onX methods defined here:
\`\`\`
declare var onabort: ((this: Window, ev: UIEvent) => any) | null;
// and so on from here...
\`\`\`
That are not defined in this Rust array?:
\`\`\`
paste the DOM_EVENT_TYPE_NAMES array from the Rust file here
\`\`\`
Note that the list in rust strips out the `on` at the start. Capitalization differences matter. Link the MDN page for each function if it isn't found in the Rust list, please.
```
Will have to grab the first list from one of the sources above, I used the TS DOM lib generator because it tends to be quite up-to-date. Also remove the backslashes, obviously.
I also added a comment about sourcing this data for future reference.1 parent 65764fd commit 7a0e931
File tree
1 file changed
+25
-3
lines changed- crates/oxc_linter/src/rules/unicorn
1 file changed
+25
-3
lines changedLines changed: 25 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
74 | 82 | | |
75 | 83 | | |
76 | 84 | | |
| |||
104 | 112 | | |
105 | 113 | | |
106 | 114 | | |
107 | | - | |
108 | | - | |
| 115 | + | |
| 116 | + | |
109 | 117 | | |
| 118 | + | |
110 | 119 | | |
111 | 120 | | |
112 | 121 | | |
113 | 122 | | |
114 | 123 | | |
115 | 124 | | |
116 | 125 | | |
| 126 | + | |
117 | 127 | | |
118 | 128 | | |
| 129 | + | |
119 | 130 | | |
120 | 131 | | |
121 | 132 | | |
| |||
129 | 140 | | |
130 | 141 | | |
131 | 142 | | |
| 143 | + | |
132 | 144 | | |
| 145 | + | |
133 | 146 | | |
134 | 147 | | |
| 148 | + | |
135 | 149 | | |
136 | 150 | | |
137 | 151 | | |
| |||
157 | 171 | | |
158 | 172 | | |
159 | 173 | | |
| 174 | + | |
160 | 175 | | |
161 | 176 | | |
162 | 177 | | |
| |||
208 | 223 | | |
209 | 224 | | |
210 | 225 | | |
| 226 | + | |
211 | 227 | | |
212 | 228 | | |
213 | 229 | | |
| |||
219 | 235 | | |
220 | 236 | | |
221 | 237 | | |
| 238 | + | |
222 | 239 | | |
| 240 | + | |
223 | 241 | | |
224 | 242 | | |
225 | 243 | | |
226 | 244 | | |
227 | 245 | | |
228 | 246 | | |
229 | 247 | | |
| 248 | + | |
230 | 249 | | |
231 | 250 | | |
232 | 251 | | |
| |||
236 | 255 | | |
237 | 256 | | |
238 | 257 | | |
239 | | - | |
240 | 258 | | |
| 259 | + | |
241 | 260 | | |
242 | 261 | | |
243 | 262 | | |
244 | 263 | | |
245 | 264 | | |
246 | 265 | | |
| 266 | + | |
247 | 267 | | |
| 268 | + | |
| 269 | + | |
248 | 270 | | |
249 | 271 | | |
250 | 272 | | |
| |||
0 commit comments