no-unused-expressions rule should allow `foo && foo()`
See original GitHub issueFrom the rule docs, This rule aims to eliminate unused expressions. The value of an expression should always be used, except in the case of expressions that side effect: function calls, assignments, and the new operator.
.
I believe the syntax ``foo && foo()` should be considered valid here as it’s a function call with potential side effects. This syntax allows for quite clean truthfulness checks inside code, and it would be nice if I could use this syntax with the rest of the rules inside no-unused-expressions. (If not, please let me opt out of just this one use-case)
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 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 >no-unused-expression - Rule
Rule: no-unused-expression. Disallows unused expression statements. Unused expressions are expression statements which are not assignments or function calls ...
Read more >eslint/eslint - Gitter
it seems like this should be allowed get foo() { if (condition) { return 'foo'; } }. but it's telling me I need...
Read more >expected assignment or function call: no-unused-expressions ...
In my case I used commas instead of semicolons in constructor. Example with errors: class foo(bar1, bar2, bar3){ this.bar1=bar1, ...
Read more >consistent-type-imports | typescript-eslint
TypeScript allows specifying a type keyword on imports to indicate that the export ... type-imports will enforce that you always use import type...
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
@ilyavolodin - How would I submit a feature request then to split this check out from
no-unused-expressions
?I think you should be able to have something which warns on
"Hello world";
, but does not warn onfoo && foo()
.+1. I recommend creating a new rule,
no-ussless-expressions
as well, which would have a subset of the original functionality of theno-unused-expressions
rule. I think this is the best course of action for the core project, so I will file an issue for a feature request and see what happens.