Commit a3013ae
committed
test(linter): Port additional tests for two unicorn rules. (#20099)
See https://raw.githubusercontent.com/sindresorhus/eslint-plugin-unicorn/main/test/prefer-array-some.js and https://raw.githubusercontent.com/sindresorhus/eslint-plugin-unicorn/609d4870f3731d39bd5b5f184628e2cf06578dba/test/no-single-promise-in-promise-methods.js
I used Claude for help porting the tests for `prefer-array-some`, mostly as a test, and then used a script to compare the tests that were ported to the original to make sure it ported everything correctly (and skipped some <template> tests that we can't handle anyway). I did the same for the other rule.
The reason I didn't use the rulegen tooling is because these tests are not handled adequately currently due to being generated dynamically or in separate sets.
One nice thing is that it also ported the comments for each set of tests.
For reference, the verification script's output, the tests that it couldn't find are due to being commented out (or template tests that were excluded).
<details>
<summary>test comparisons</summary>
```
node tasks/rulegen/compare-tests.mjs prefer-array-some unicorn
Downloading https://raw.githubusercontent.com/sindresorhus/eslint-plugin-unicorn/main/test/prefer-array-some.js ...
Reading Rust file: /Users/connorshea/code/oxc/crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs
Comparing test cases for unicorn/prefer-array-some...
Upstream (Node.js evaluated): 72 valid, 52 invalid
Oxlint (Rust file): 70 valid, 46 invalid
Missing valid cases (6):
1. if (foo["find"](fn)) {}
2. if (foo["findLast"](fn)) {}
3. if (foo[`find`](fn)) {}
4. if (foo[`findLast`](fn)) {}
5. if (foo.find(...argumentsArray)) {}
6. if (foo.findLast(...argumentsArray)) {}
Missing invalid cases (8):
1. const bar = Boolean(foo.find(fn))
2. const bar = Boolean(foo.findLast(fn))
3. if ( (( (( (( (( array )) .filter(what_ever_here) )) .length )) > (( 0 )) )) );
4. <template><div v-if="foo.find(fn)"></div></template>
5. <script>if (foo.findLast(fn));</script>
6. <template><div v-if="foo.filter(fn).length > 0"></div></template>
7. <template><div v-if="foo.filter(fn).length !== 0"></div></template>
8. <script>if (foo.filter(fn).length > 0);</script>
Extra valid cases in oxlint not in upstream (4):
1. new foo.findLastIndex(bar) !== -1
2. foo.findLastIndex(bar, extraArgument) !== -1
3. foo.findLastIndex(bar) instanceof -1
4. foo.findLastIndex(...bar) !== -1
Extra invalid cases in oxlint not in upstream (2):
1. foo.findLastIndex(bar) !== (( - 1 ))
2. foo.findLastIndex(element => element.bar === 1) !== (( - 1 ))
```
```
node tasks/rulegen/compare-tests.mjs no-single-promise-in-promise-methods unicorn
Downloading https://raw.githubusercontent.com/sindresorhus/eslint-plugin-unicorn/main/test/no-single-promise-in-promise-methods.js ...
Reading Rust file: /Users/connorshea/code/oxc/crates/oxc_linter/src/rules/unicorn/no_single_promise_in_promise_methods.rs
Comparing test cases for unicorn/no-single-promise-in-promise-methods...
Upstream (Node.js evaluated): 18 valid, 62 invalid
Oxlint (Rust file): 15 valid, 67 invalid
Missing valid cases (3):
1. Promise?.race([promise])
2. Promise.race?.([promise])
3. Promise["race"]([promise])
Extra invalid cases in oxlint not in upstream (5):
1. Promise.all([x] as const).then()
2. Promise.all([x] satisfies any[]).then()
3. Promise.all([x as const]).then()
4. Promise.all([x!]).then()
5. Promise.all(['one']).then(something);
```
</details>1 parent 9870467 commit a3013ae
File tree
4 files changed
+551
-237
lines changed- crates/oxc_linter/src
- rules/unicorn
- snapshots
4 files changed
+551
-237
lines changedLines changed: 88 additions & 64 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
178 | | - | |
179 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
191 | 198 | | |
192 | | - | |
193 | 199 | | |
194 | 200 | | |
195 | 201 | | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
225 | 230 | | |
226 | 231 | | |
227 | | - | |
228 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
229 | 235 | | |
230 | | - | |
| 236 | + | |
231 | 237 | | |
232 | 238 | | |
233 | | - | |
| 239 | + | |
| 240 | + | |
234 | 241 | | |
235 | 242 | | |
236 | | - | |
| 243 | + | |
237 | 244 | | |
238 | 245 | | |
239 | 246 | | |
240 | | - | |
| 247 | + | |
241 | 248 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
258 | 280 | | |
259 | 281 | | |
260 | 282 | | |
| |||
263 | 285 | | |
264 | 286 | | |
265 | 287 | | |
266 | | - | |
| 288 | + | |
267 | 289 | | |
268 | 290 | | |
269 | 291 | | |
| |||
280 | 302 | | |
281 | 303 | | |
282 | 304 | | |
| 305 | + | |
| 306 | + | |
283 | 307 | | |
284 | 308 | | |
285 | 309 | | |
| |||
0 commit comments