Skip to content

Commit

Permalink
test(eslint-plugin): add extra tests (typescript-eslint#10587)
Browse files Browse the repository at this point in the history
* test(eslint-plugin): add extra tests

Adds a couple of extra test cases for these rules:

- `class-methods-use-this`
- `consistent-type-assertions`
- `no-array-delete`

* test: update no-array-delete test to remove comment

Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>

---------

Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
  • Loading branch information
43081j and JoshuaKGoldberg authored Jan 7, 2025
1 parent e697cfa commit 03d9639
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,22 @@ class Foo implements Bar {
},
],
},
{
code: `
function fn() {
this.foo = 303;
class Foo {
method() {}
}
}
`,
errors: [
{
messageId: 'missingThis',
},
],
},
],
valid: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ ruleTester.run('consistent-type-assertions', rule, {
},
},
},
{
code: `
const x = { key: 'value' } as any;
`,
options: [{ assertionStyle: 'as', objectLiteralTypeAssertions: 'never' }],
},
{
code: `
const x = { key: 'value' } as unknown;
`,
options: [{ assertionStyle: 'as', objectLiteralTypeAssertions: 'never' }],
},
],
invalid: [
...dedupeTestCases(
Expand Down
26 changes: 26 additions & 0 deletions packages/eslint-plugin/tests/rules/no-array-delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ ruleTester.run('no-array-delete', rule, {
declare const test: never;
delete test[0];
`,
`
delete console.log();
`,
],

invalid: [
Expand Down Expand Up @@ -596,5 +599,28 @@ ruleTester.run('no-array-delete', rule, {
},
],
},
{
code: `
declare const arr: string & Array<number>;
delete arr[0];
`,
errors: [
{
column: 9,
endColumn: 22,
line: 3,
messageId: 'noArrayDelete',
suggestions: [
{
messageId: 'useSplice',
output: `
declare const arr: string & Array<number>;
arr.splice(0, 1);
`,
},
],
},
],
},
],
});

0 comments on commit 03d9639

Please sign in to comment.