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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule Proposal: no-unsafe-optional-chaining #13431
Comments
👍 these all look like very possible errors.
I'm not sure about this, it could be part of a valid code that is going to check for |
@mdjermanovic How about behind an option like |
Makes sense to me 👍 |
Should we also report chain expression used as a destructuring source: var { a } = b?.c; // no-unsafe-optional-chaining error? if not, /* eslint prefer-destructuring: error */
var a = (b?.c).a; // autofix -> var {a} = b?.c; |
Maybe also array spread and spread in function calls: [...obj?.foo];
bar(...obj?.foo);
new Bar(...obj?.foo); |
Hi :) @mysticatea Could I work on it? |
Please describe what the rule should do:
Disallow the unsafe uses of optional chaining.
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] Warns about a potential error (problem)
Provide 2-3 code examples that this rule will warn about:
[EDIT] With
disallowArithmeticOperators: true
(defaults tofalse
), additionally disallows operators+
,-
,*
,/
, and**
because will generateNaN
(or unexpected text). It still allows the operators of comparison, bitwise, logical, and relational.Why should this rule be included in ESLint (instead of a plugin)?
The parentheses around optional chaining disconnect chaining and change the behavior. This is different behavior from well-known non-optional member accesses. This rule warns potential TypeError risks around the difference. This is about a language feature.
Are you willing to submit a pull request to implement this rule?
Yes.
The text was updated successfully, but these errors were encountered: