Open
Description
opened on Jun 21, 2020
Please describe what the rule should do:
The new rule warns obj && obj.prop
-like notations to suggest obj?.prop
.
What new ECMAScript feature does this rule relate to?
Optional chaining
What category of rule is this? (place an "X" next to just one item)
[X] Suggests an alternate way of doing something (suggestion)
Provide 2-3 code examples that this rule will warn about:
//✖ BAD
obj && obj.prop
obj != null ? obj.prop : undefined
obj && obj[key]
obj != null ? obj[key] : undefined
func && func()
func != null ? func() : undefined
if (func) func()
if (func) { func() }
//✔ GOOD
obj?.prop
obj?.[key]
func?.()
Why should this rule be included in ESLint (instead of a plugin)?
obj && obj.prop
-like notation is a popular practice. This rule will help people to learn the new syntax Optional Chaining. This is about a language feature rather than third-party platforms or libraries.
Are you willing to submit a pull request to implement this rule?
Yes.
Metadata
Assignees
Labels
Type
Projects
Status
Ready to Implement
Activity