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

Update: no-void add an option to allow void as a statement #12613

Merged
merged 2 commits into from Dec 23, 2019
Merged

Update: no-void add an option to allow void as a statement #12613

merged 2 commits into from Dec 23, 2019

Conversation

bradzacher
Copy link
Contributor

What is the purpose of this pull request?
Changes an existing rule

What rule do you want to change?
no-void

Does this change cause the rule to produce more or fewer warnings?
Fewer, when the option is turned on

How will the change be implemented? (New option, new default behavior, etc.)?
New option

Please provide some example code that this change will affect:
Code that will now be valid, when the option is turned on:

/*eslint no-void: ["error", { "allowAsStatement": true }]*/

void foo;
void someFunction();

What does the rule currently do for this code?
Errors for all void operator usage, regardless of context

What will the rule do after it's changed?
When the option is on, it will allow the void when used as a statement.

Why?
A common usage pattern I've seen out in the world is to use the void operator to mark promises as "consumed" without awaiting them.
I.e. it's a way for users to say "I am intentionally not awaiting this promise".

async function returnsPromise(): Promise<void> {}

void returnsPromise();

This pattern works well with our rule @typescript-eslint/no-floating-promises, which would otherwise error on the above promise if the void operator was omitted.

Feel free to push back, we could potentially extend this rule within @typescript-eslint, and make it type aware to only allow it for thenable values, but I thought I'd see if you guys thought there was value in this before forking.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Nov 27, 2019
@bradzacher bradzacher changed the title Feat: no-void add an option to allow void as a statement Update: no-void add an option to allow void as a statement Nov 28, 2019
@aladdin-add aladdin-add added enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Nov 30, 2019
@kaicataldo
Copy link
Member

Sorry for the delay! I'm supportive of this change and will champion it. We just need one more 👍 from the team to mark it as accepted.

@kaicataldo kaicataldo self-assigned this Dec 21, 2019
@platinumazure platinumazure added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Dec 21, 2019
@mdjermanovic
Copy link
Member

It would be nice to have a test with an empty options object, to ensure that the default value in schema is false. Maybe also one with the option explicitly set to false.

Semi-related, it's interesting that no-unused-expressions already allows 'void statements', so there will be no problems with this.

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@kaicataldo kaicataldo merged commit 8f1020f into eslint:master Dec 23, 2019
@kaicataldo
Copy link
Member

Thanks for contributing!

@bradzacher bradzacher deleted the no-void-statement branch December 23, 2019 23:55
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jun 22, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jun 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants