Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(eslint-plugin): [prefer-optional-chain] support suggesting!foo || !foo.bar
as a valid match for the rule#5266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
cfded63
741d5e3
5f6cb28
931274c
d0f7c3a
fdd99e0
92f4285
e63bd2f
393d182
7a1fa82
70319e9
aa0063f
54c2ba7
265a1e8
f946a99
078bd0d
6b1244c
1f35a88
cf8c41b
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
description: 'Enforce using concise optional chain expressions instead of chained logical ands, negated logical ors, or empty objects.' | ||
--- | ||
> 🛑 This file is source code, not the primary documentation location! 🛑 | ||
@@ -65,9 +65,15 @@ foo && foo.a && foo.a.b && foo.a.b.c; | ||
foo && foo['a'] && foo['a'].b && foo['a'].b.c; | ||
foo && foo.a && foo.a.b && foo.a.b.method && foo.a.b.method(); | ||
// With empty objects | ||
(((foo || {}).a || {}).b || {}).c; | ||
(((foo || {})['a'] || {}).b || {}).c; | ||
// With negated `or`s | ||
!foo || !foo.bar; | ||
!foo || !foo[bar]; | ||
!foo || !foo.bar || !foo.bar.baz || !foo.bar.baz(); | ||
Comment on lines +72 to +76 ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think the examples should be arranged in a table, need some opinions | ||
// this rule also supports converting chained strict nullish checks: | ||
foo && | ||
foo.a != null && | ||
@@ -85,6 +91,10 @@ foo?.['a']?.b?.c; | ||
foo?.a?.b?.method?.(); | ||
foo?.a?.b?.c?.d?.e; | ||
!foo?.bar; | ||
!foo?.[bar]; | ||
!foo?.bar?.baz?.(); | ||
``` | ||
**Note:** there are a few edge cases where this rule will false positive. Use your best judgement when evaluating reported errors. | ||
Uh oh!
There was an error while loading.Please reload this page.