|
1 |
| -import { RuleTester } from '@typescript-eslint/rule-tester'; |
| 1 | +import { noFormat, RuleTester } from '@typescript-eslint/rule-tester'; |
2 | 2 |
|
3 | 3 | import rule from '../../src/rules/no-array-delete';
|
4 | 4 | import { getFixturesRootDir } from '../RuleTester';
|
@@ -481,5 +481,109 @@ ruleTester.run('no-array-delete', rule, {
|
481 | 481 | },
|
482 | 482 | ],
|
483 | 483 | },
|
| 484 | + |
| 485 | + { |
| 486 | + code: ` |
| 487 | + declare const a: number[]; |
| 488 | + declare const b: number; |
| 489 | +
|
| 490 | + delete [...a, ...a][b]; |
| 491 | + `, |
| 492 | + errors: [ |
| 493 | + { |
| 494 | + messageId: 'noArrayDelete', |
| 495 | + suggestions: [ |
| 496 | + { |
| 497 | + messageId: 'useSplice', |
| 498 | + output: ` |
| 499 | + declare const a: number[]; |
| 500 | + declare const b: number; |
| 501 | +
|
| 502 | + [...a, ...a].splice(b, 1); |
| 503 | + `, |
| 504 | + }, |
| 505 | + ], |
| 506 | + }, |
| 507 | + ], |
| 508 | + }, |
| 509 | + |
| 510 | + { |
| 511 | + code: noFormat` |
| 512 | + declare const a: number[]; |
| 513 | + declare const b: number; |
| 514 | +
|
| 515 | + delete /* multi |
| 516 | + line */ a[(( |
| 517 | + // single-line |
| 518 | + b /* inline */ /* another-inline */ ) |
| 519 | + ) /* another-one */ ]; |
| 520 | + `, |
| 521 | + errors: [ |
| 522 | + { |
| 523 | + messageId: 'noArrayDelete', |
| 524 | + suggestions: [ |
| 525 | + { |
| 526 | + messageId: 'useSplice', |
| 527 | + output: ` |
| 528 | + declare const a: number[]; |
| 529 | + declare const b: number; |
| 530 | +
|
| 531 | + a.splice(b, 1); |
| 532 | + `, |
| 533 | + }, |
| 534 | + ], |
| 535 | + }, |
| 536 | + ], |
| 537 | + }, |
| 538 | + |
| 539 | + { |
| 540 | + code: noFormat` |
| 541 | + declare const a: number[]; |
| 542 | + declare const b: number; |
| 543 | +
|
| 544 | + delete ((a[((b))])); |
| 545 | + `, |
| 546 | + errors: [ |
| 547 | + { |
| 548 | + messageId: 'noArrayDelete', |
| 549 | + suggestions: [ |
| 550 | + { |
| 551 | + messageId: 'useSplice', |
| 552 | + output: ` |
| 553 | + declare const a: number[]; |
| 554 | + declare const b: number; |
| 555 | +
|
| 556 | + a.splice(b, 1); |
| 557 | + `, |
| 558 | + }, |
| 559 | + ], |
| 560 | + }, |
| 561 | + ], |
| 562 | + }, |
| 563 | + |
| 564 | + { |
| 565 | + code: ` |
| 566 | + declare const a: number[]; |
| 567 | + declare const b: number; |
| 568 | +
|
| 569 | + delete a[(b + 1) * (b + 2)]; |
| 570 | + `, |
| 571 | + errors: [ |
| 572 | + { |
| 573 | + messageId: 'noArrayDelete', |
| 574 | + suggestions: [ |
| 575 | + { |
| 576 | + messageId: 'useSplice', |
| 577 | + output: ` |
| 578 | + declare const a: number[]; |
| 579 | + declare const b: number; |
| 580 | +
|
| 581 | + a.splice((b + 1) * (b + 2), 1); |
| 582 | + `, |
| 583 | + }, |
| 584 | + ], |
| 585 | + }, |
| 586 | + ], |
| 587 | + }, |
484 | 588 | ],
|
485 | 589 | });
|
0 commit comments