`no-unused-expressions` has no way to warn on `void foo`
See original GitHub issueWhat 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:
- Created 6 years ago
- Comments:8 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:But actually this is an ugly pattern and I’m not going to use it.
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 theno-new
rule, but a disable comment would probably be a better way to do that because the use ofvoid
doesn’t really make sense here. However, if we do fix this by default it would be a breaking change.