sindresorhus/eslint-plugin-unicorn
Rule proposal: A rule checks optional chaining in logical expression
Closed
#1,801 opened on Apr 28, 2022
help wantednew rule
Repository metrics
- Stars
- (5,022 stars)
- PR merge metrics
- (Avg merge 1d 16h) (399 merged PRs in 30d)
Description
Description
For "logical or", the optional chaining should be consistent.
For "logical and", should not use unnecessary ?.(This may makes code harder to edit, need discussion).
Fail
foo?.bar || foo.baz;
// The right side should check foo
foo.bar || foo?.baz;
// The right side should not check foo
foo?.bar && foo?.baz;
// The right side `?.` is useless
foo.bar && foo?.baz;
// The right side `?.` is useless
Pass
foo?.bar || foo?.baz;
foo.bar || foo.baz;
foo?.bar && foo.baz;
foo.bar && foo.baz;
Additional Info
No response