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

no-useless-undefined `: allow return undefined in promise. #2494

Closed
christopher-buss opened this issue Nov 12, 2024 · 2 comments
Closed

no-useless-undefined `: allow return undefined in promise. #2494

christopher-buss opened this issue Nov 12, 2024 · 2 comments

Comments

@christopher-buss
Copy link

Description

In an async function, I want to be able to do return undefined at the end, to denote that I am intentionally not returning a value. Some ESLint Promise rules expect a return statement to silence specific warnings.

This could be added as an option, checkPromises.

For example, if I do:

const promise = somePromise.then(async () => {
	// some work
});
// `Each then() should return a value or throw - eslint-plugin-promise no-return`

To silence this warning, I would just do:

const promise = somePromise.then(async () => {
	// some work
	return undefined;
});
// `Do not use useless `undefined` - unicorn/no-useless-undefined`

Fail

"unicorn/no-useless-undefined": [ "error", { checkPromises: false }]
const promise = somePromise.then(async () => {
	// some work
	return undefined;
});
//

Pass

"unicorn/no-useless-undefined": [ "error", { checkPromises: true }]
const promise = somePromise.then(async () => {
	// some work
	return undefined;
});
//

Additional Info

No response

@github-actions github-actions bot changed the title no-useless-undefined : allow return undefined in promise. no-useless-undefined `: allow return undefined in promise. Nov 12, 2024
@fregante
Copy link
Collaborator

I don’t think it makes a difference whether the function is sync or async, it's unnecessary in both cases. If you disagree, you can disable the rule.

@christopher-buss
Copy link
Author

It's necessary due to conflicts with other ESLint packages, and I don't want to disable the rule because I think it's useful. But I guess there will be no resolution here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants