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
New: no-unsafe-optional-chaining rule (fixes #13431) #13859
Conversation
I think all of these will also throw on
|
@mdjermanovic Thanks 👍 I added handling those. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great in general. I didn't review everything in detail yet, but noticed a couple of problems.
@mdjermanovic Thanks |
- add test cases (*=, /=) - improve Rule Details doc - fix wrong example - add unary, assignment operation test cases - edit test cases - move optional chain to right side - change to use Set - fix jsdoc typo and type - add examples on docs - handle conditional, sequence expressions - remove useless check - fix doc - add test cases - fix typo
@mdjermanovic Thanks for all reviews. It seems to be fixed but, I'll take a look once again and request a review. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! 🎉
no-unsafe-optional-chaining
rule (fixes #13431)
Hi @mdjermanovic I have a question :) Maybe this rule should handle (async function main() {
(await (foo?.bar))?.baz // ok
(await (foo?.bar)).baz; // Maybe error? It's lint free in current version.
})(); I marked it as |
Makes sense to me, we can handle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @yeonjuan!
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[x] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Added a new rule
no-unsafe-optional-chaining
which proposed by @mysticatea #13431This rule will catch cases that may possibly TypeError when using
optional chaining
.And by the option
disallowArithmeticOperators: true
it also catches the operation which possibly results in unexpected NaN. - commentIs there anything you'd like reviewers to focus on?
Maybe there are some other cases we should handle?