question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[no-void]: allow void arrow functions

See original GitHub issue

What rule do you want to change? no-void

Does this change cause the rule to produce more or fewer warnings? Fewer

How will the change be implemented? (New option, new default behavior, etc.)? Option - could also be implemented as standard behaviour depending on interpretation of the rules description.

Please provide some example code that this change will affect:

const log = x => void console.log(x);

What does the rule currently do for this code? Errors

What will the rule do after it’s changed? Not error

Are you willing to submit a pull request to implement this change? Yes


There are some legitimate uses for the void operator, one of which is even mentioned in the opening sentence of the no-void docs:

It can be used to ignore any side effects expression may produce

The description of the no-void rule to me seems to indicate that the rule is actually ideally about preventing the use of void to get a “pure” undefined back in the pre-ES5 days when undefined was mutable:

The common case of using void operator is to get a “pure” undefined value as prior to ES5 the undefined variable was mutable:

So it might be arguable that this is technically a bug? But I don’t have a major preference on if it’s an option or not 😃

Based off #12688, which was closed for not following the template.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
ljharbcommented, Mar 9, 2020

undefined is still mutable, post-ES5, just not in the global scope.

1reaction
G-Rathcommented, May 14, 2020

@kaicataldo sure thing 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

[no-void]: allow void arrow functions · Issue #13299 - GitHub
This doesn't seem like a new option, it seems allowAsStatement should allow an arrow function with void in the return value.
Read more >
no-void-expression - Rule
If ignore-arrow-function-shorthand is provided, () => returnsVoid() will be allowed. Otherwise, it must be written as () => { returnsVoid(); } .
Read more >
Void in single expression arrow functions - Stack Overflow
All that void does is: The void operator evaluates the given expression and then returns undefined. So, it's the same as returning undefined ......
Read more >
A case for using `void` in modern JavaScript - Reddit
Perhaps a better solution to the no-void ESLint rule would be a parameter to allow void only as the return on a bracketless...
Read more >
Disallow use of the void operator. (no-void) - ESLint - Breword 文档 ...
This rule has an object option: allowAsStatement set to true allows the void operator to be used as a statement (Default false )....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found