Skip to content
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

chore: [no-floating-promises] add missing suggestions on main #9569

Merged
merged 1 commit into from
Jul 17, 2024
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
183 changes: 133 additions & 50 deletions packages/eslint-plugin/tests/rules/no-floating-promises.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1796,9 +1796,9 @@ async function test() {
{
messageId: 'floatingFixVoid',
output: `
async function test() {
declare const promiseValue: Promise<number>;
declare const promiseValue: Promise<number>;

async function test() {
void promiseValue;
promiseValue.then(() => {});
promiseValue.catch();
Expand All @@ -1815,9 +1815,9 @@ async function test() {
{
messageId: 'floatingFixVoid',
output: `
async function test() {
declare const promiseValue: Promise<number>;
declare const promiseValue: Promise<number>;

async function test() {
promiseValue;
void promiseValue.then(() => {});
promiseValue.catch();
Expand All @@ -1834,9 +1834,9 @@ async function test() {
{
messageId: 'floatingFixVoid',
output: `
async function test() {
declare const promiseValue: Promise<number>;
declare const promiseValue: Promise<number>;

async function test() {
promiseValue;
promiseValue.then(() => {});
void promiseValue.catch();
Expand All @@ -1853,9 +1853,9 @@ async function test() {
{
messageId: 'floatingFixVoid',
output: `
async function test() {
declare const promiseValue: Promise<number>;
declare const promiseValue: Promise<number>;

async function test() {
promiseValue;
promiseValue.then(() => {});
promiseValue.catch();
Expand Down Expand Up @@ -1883,9 +1883,9 @@ async function test() {
{
messageId: 'floatingFixVoid',
output: `
async function test() {
declare const promiseUnion: Promise<number> | number;
declare const promiseUnion: Promise<number> | number;

async function test() {
void promiseUnion;
}
`,
Expand All @@ -1912,9 +1912,9 @@ async function test() {
{
messageId: 'floatingFixVoid',
output: `
async function test() {
declare const promiseIntersection: Promise<number> & number;
declare const promiseIntersection: Promise<number> & number;

async function test() {
void promiseIntersection;
promiseIntersection.then(() => {});
promiseIntersection.catch();
Expand All @@ -1930,9 +1930,9 @@ async function test() {
{
messageId: 'floatingFixVoid',
output: `
async function test() {
declare const promiseIntersection: Promise<number> & number;
declare const promiseIntersection: Promise<number> & number;

async function test() {
promiseIntersection;
void promiseIntersection.then(() => {});
promiseIntersection.catch();
Expand All @@ -1948,9 +1948,9 @@ async function test() {
{
messageId: 'floatingFixVoid',
output: `
async function test() {
declare const promiseIntersection: Promise<number> & number;
declare const promiseIntersection: Promise<number> & number;

async function test() {
promiseIntersection;
promiseIntersection.then(() => {});
void promiseIntersection.catch();
Expand Down Expand Up @@ -2415,13 +2415,13 @@ declare const promiseIntersection: Promise<number> & number;
{
messageId: 'floatingFixVoid',
output: `
(async function () {
declare const promiseIntersection: Promise<number> & number;
void promiseIntersection;
promiseIntersection.then(() => {});
promiseIntersection.catch();
promiseIntersection.finally();
})();
declare const promiseIntersection: Promise<number> & number;
(async function () {
void promiseIntersection;
promiseIntersection.then(() => {});
promiseIntersection.catch();
promiseIntersection.finally();
})();
`,
},
],
Expand All @@ -2433,13 +2433,13 @@ declare const promiseIntersection: Promise<number> & number;
{
messageId: 'floatingFixVoid',
output: `
(async function () {
declare const promiseIntersection: Promise<number> & number;
promiseIntersection;
void promiseIntersection.then(() => {});
promiseIntersection.catch();
promiseIntersection.finally();
})();
declare const promiseIntersection: Promise<number> & number;
(async function () {
promiseIntersection;
void promiseIntersection.then(() => {});
promiseIntersection.catch();
promiseIntersection.finally();
})();
`,
},
],
Expand All @@ -2451,13 +2451,13 @@ declare const promiseIntersection: Promise<number> & number;
{
messageId: 'floatingFixVoid',
output: `
(async function () {
declare const promiseIntersection: Promise<number> & number;
promiseIntersection;
promiseIntersection.then(() => {});
void promiseIntersection.catch();
promiseIntersection.finally();
})();
declare const promiseIntersection: Promise<number> & number;
(async function () {
promiseIntersection;
promiseIntersection.then(() => {});
void promiseIntersection.catch();
promiseIntersection.finally();
})();
`,
},
],
Expand All @@ -2469,13 +2469,13 @@ declare const promiseIntersection: Promise<number> & number;
{
messageId: 'floatingFixVoid',
output: `
(async function () {
declare const promiseIntersection: Promise<number> & number;
promiseIntersection;
promiseIntersection.then(() => {});
promiseIntersection.catch();
void promiseIntersection.finally();
})();
declare const promiseIntersection: Promise<number> & number;
(async function () {
promiseIntersection;
promiseIntersection.then(() => {});
promiseIntersection.catch();
void promiseIntersection.finally();
})();
`,
},
],
Expand Down Expand Up @@ -3933,7 +3933,22 @@ function* generator(): Generator<number, void, Promise<number>> {
yield x;
}
`,
errors: [{ messageId: 'floatingVoid' }],
errors: [
{
messageId: 'floatingVoid',
suggestions: [
{
messageId: 'floatingFixVoid',
output: `
declare const x: any;
function* generator(): Generator<number, void, Promise<number>> {
void (yield x);
}
`,
},
],
},
],
},
{
code: `
Expand All @@ -3942,32 +3957,100 @@ function* generator(): Generator<number, void, void> {
yield* x;
}
`,
errors: [{ messageId: 'floatingVoid' }],
errors: [
{
messageId: 'floatingVoid',
suggestions: [
{
messageId: 'floatingFixVoid',
output: `
declare const x: Generator<number, Promise<number>, void>;
function* generator(): Generator<number, void, void> {
void (yield* x);
}
`,
},
],
},
],
},
{
code: `
const value = {};
value as Promise<number>;
`,
errors: [{ messageId: 'floatingVoid', line: 3 }],
errors: [
{
messageId: 'floatingVoid',
line: 3,
suggestions: [
{
messageId: 'floatingFixVoid',
output: `
const value = {};
void (value as Promise<number>);
`,
},
],
},
],
},
{
code: `
({}) as Promise<number> & number;
`,
errors: [{ messageId: 'floatingVoid', line: 2 }],
errors: [
{
messageId: 'floatingVoid',
line: 2,
suggestions: [
{
messageId: 'floatingFixVoid',
output: `
void (({}) as Promise<number> & number);
`,
},
],
},
],
},
{
code: `
({}) as Promise<number> & { yolo?: string };
`,
errors: [{ messageId: 'floatingVoid', line: 2 }],
errors: [
{
messageId: 'floatingVoid',
line: 2,
suggestions: [
{
messageId: 'floatingFixVoid',
output: `
void (({}) as Promise<number> & { yolo?: string });
`,
},
],
},
],
},
{
code: `
<Promise<number>>{};
`,
errors: [{ messageId: 'floatingVoid', line: 2 }],
errors: [
{
messageId: 'floatingVoid',
line: 2,
suggestions: [
{
messageId: 'floatingFixVoid',
output: `
void (<Promise<number>>{});
`,
},
],
},
],
},
],
});
Loading