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-unused-expressions` has no way to warn on `void foo`

See original GitHub issue

What version are you using? latest

What did you do? enabled no-unused-expressions, and expected void String; to be an error.

What happened? It was not an error.

What did you expect to happen? An error.

Looking at the exceptions in the docs, new C makes sense because constructors can have side effects (as could any function invocation or property access); delete a.b makes sense because delete has an effect; assignment makes sense. However, while some people might want void a to be used, that statement has no actual effect, and I’d like to be able to warn against it.

Could we add an option?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
taioncommented, Jan 14, 2018

BTW, this came up in the context of my wanting to find a way to mark variables as intentionally unused to avoid having to enable ignoreRestSiblings for no-unused. My intended pattern was:

const { foo, bar, ...rest } = whatever;
void bar;

But actually this is an ugly pattern and I’m not going to use it.

1reaction
not-an-aardvarkcommented, Jan 14, 2018

You’re right, it seems like this was intentional – it was introduced in https://github.com/eslint/eslint/commit/928b6aeb1d499628212b44b486cca3557e53bc35 as a fix for https://github.com/eslint/eslint/issues/431.

I don’t really agree with the reasoning in that issue – it seems like void is being used to work around the no-new rule, but a disable comment would probably be a better way to do that because the use of void doesn’t really make sense here. However, if we do fix this by default it would be a breaking change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-unused-expressions - ESLint - Pluggable JavaScript Linter
This rule aims to eliminate unused expressions which have no effect on the state of the program. This rule does not apply to...
Read more >
Nice way to get rid of no-unused-expressions linter error with ...
I've made a small plugin called eslint-plugin-chai-friendly that overrides the default no-unused-expressions rule and makes it friendly towards chai.
Read more >
no-meaningless-void-operator - TypeScript ESLint
This rule helps an authors catch API changes where previously a value was being discarded at a call site, but the callee changed...
Read more >
no-unused-expression - Rule
Disallows unused expression statements. Unused expressions are expression statements which are not assignments or function calls (and thus usually no-ops).
Read more >
66425 – (void) cast doesn't suppress __attribute__ ...
It is fairly easy to use -Wno-unused-result or "#pragma GCC ... Then please explain to me how this: (void) foo(); is any worse...
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