Skip to content

fix(eslint-plugin): [no-floating-promises] add suggestions to tests from #9263 checkThenables #9515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 84 additions & 5 deletions packages/eslint-plugin/tests/rules/no-floating-promises.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3760,7 +3760,21 @@ void myTag\`abc\`;
declare const createPromise: () => PromiseLike<number>;
createPromise();
`,
errors: [{ line: 3, messageId: 'floatingVoid' }],
errors: [
{
line: 3,
messageId: 'floatingVoid',
suggestions: [
{
messageId: 'floatingFixVoid',
output: `
declare const createPromise: () => PromiseLike<number>;
void createPromise();
`,
},
],
},
],
options: [{ checkThenables: true }],
},
{
Expand All @@ -3773,15 +3787,48 @@ declare function createMyThenable(): MyThenable;

createMyThenable();
`,
errors: [{ line: 8, messageId: 'floatingVoid' }],
errors: [
{
line: 8,
messageId: 'floatingVoid',
suggestions: [
{
messageId: 'floatingFixVoid',
output: `
interface MyThenable {
then(onFulfilled: () => void, onRejected: () => void): MyThenable;
}

declare function createMyThenable(): MyThenable;

void createMyThenable();
`,
},
],
},
],
options: [{ checkThenables: true }],
},
{
code: `
declare const createPromise: () => Promise<number>;
createPromise();
`,
errors: [{ line: 3, messageId: 'floatingVoid' }],
errors: [
{
line: 3,
messageId: 'floatingVoid',
suggestions: [
{
messageId: 'floatingFixVoid',
output: `
declare const createPromise: () => Promise<number>;
void createPromise();
`,
},
],
},
],
options: [{ checkThenables: false }],
},
{
Expand All @@ -3790,7 +3837,22 @@ class MyPromise<T> extends Promise<T> {}
declare const createMyPromise: () => MyPromise<number>;
createMyPromise();
`,
errors: [{ line: 4, messageId: 'floatingVoid' }],
errors: [
{
line: 4,
messageId: 'floatingVoid',
suggestions: [
{
messageId: 'floatingFixVoid',
output: `
class MyPromise<T> extends Promise<T> {}
declare const createMyPromise: () => MyPromise<number>;
void createMyPromise();
`,
},
],
},
],
options: [{ checkThenables: false }],
},
{
Expand All @@ -3801,7 +3863,24 @@ class MyPromise<T> extends Promise<T> {
declare const createMyPromise: () => MyPromise<number>;
createMyPromise();
`,
errors: [{ line: 6, messageId: 'floatingVoid' }],
errors: [
{
line: 6,
messageId: 'floatingVoid',
suggestions: [
{
messageId: 'floatingFixVoid',
output: `
class MyPromise<T> extends Promise<T> {
additional: string;
}
declare const createMyPromise: () => MyPromise<number>;
void createMyPromise();
`,
},
],
},
],
options: [{ checkThenables: false }],
},
],
Expand Down
Loading