-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Update: optional chaining support (fixes #12642) #13416
Conversation
@mysticatea would it be possible to merge and release this without the |
I feel that the rule should report
I don't think it's a blocker of this PR. @mdjermanovic I appreciate your exhaustive review. Thank you very much! I should address your review, but please tell me if not enough. |
I'd also vote to merge this without the It seems that only some rarely used selectors (those that internally use |
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! 🎉
PR to upgrade Espree: #13501. |
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.
Thanks for working on this!
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[X] Other, please explain: Add support for optional chaining syntax. Fixes #12642.
What changes did you make? (Give an overview)
This PR adds support for optional chaining syntax into ESLint. It includes the following changes:
esquery
update: Added support for ChainExpression node estools/estraverse#113 and for it.eslint-utils
update: Supports for Optional chaining & Nullish coalescing mysticatea/eslint-utils#8eslint-visitor-keys
update: Update: addChainExpression
node eslint-visitor-keys#12espree
update: Update: support optional chaining js#446 (not released yet)accessor-pairs
9125cf1 ... It handlesChainExpression
nodes.array-callback-return
102c4db ... It handlesChainExpression
nodes.camelcase
3de0a1c ... Some tests are added.computed-property-spacing
f2dc7f2 ... Some tests are added.constructor-super
80e5e92 ... It handlesChainExpression
nodes.dot-location
33e4986, b91d17b ... It fixes code with?.
correctly.dot-notation
f66ce6c ... It fixes code with?.
correctly.func-call-spacing
31412c2 ... It fixes code with ?. correctly.func-name-matching
206d25f ... It handlesChainExpression
nodes.getter-return
276526b ... Some tests are added.global-require
2824b22 ... It handlesChainExpression
nodes.indent
9a14a09 ... It handlesChainExpression
nodes and?.
tokens correctly.new-cap
7574cfd ... It handlesChainExpression
nodes.newline-per-chained-call
ed71bd4 ... It handlesChainExpression
nodes and?.
tokens correctly.no-alert
9fd0338 ... It handlesChainExpression
nodes.no-eval
abcceae ... It handleseval?.(code)
as indirect eval as per the spec. It handlesChainExpression
nodes.no-extend-native
45c5aea ... It handlesChainExpression
nodes. And it fixes a bug of edge cases.no-extra-bind
38592d2 ... It handlesChainExpression
nodes and?.
tokens correctly. And it fixes a bug of edge cases.no-extra-boolean-cast
d0c2f82 ... It handlesChainExpression
nodes.no-extra-parens
a395b10 ... It recognizes necessary parentheses of avoiding syntax errors (e.g.,new (obj?.p)()
,(obj?.p)`template`
, etc) and necessary parentheses of disconnecting chaining. It handlesChainExpression
nodes.no-implicit-coercion
e550194 ... It creates the proper error message for~foo?.indexOf(bar)
-like code. It handlesChainExpression
nodes.no-implicit-eval
248faf1 ... It handlesChainExpression
nodes.no-import-assign
b3dee67, f65df75 ... It handlesChainExpression
nodes.no-magic-numbers
c63d3c1 ... It handlesChainExpression
nodes.no-obj-calls
e13059f ... It handlesChainExpression
nodes.no-prototype-builtins
5286f83 ... It handlesChainExpression
nodes.no-restricted-syntax
8a0097a ... Some tests are added. We need to fixesquery
to support optional chaining with some selectors (Added support for ChainExpression node estools/estraverse#113).no-self-assign
d12b2be ... It handlesChainExpression
nodes.no-setter-return
a31e04c ... It handlesChainExpression
nodes.no-unexpected-multiline
6c6bd95, 776e96b ... It handles?.
tokens correctly. Should this rule ignore the case the previous line ends with?.
token?no-unused-expression
6c00e33, 9a91ba1 ... It recognizesChainExpression
nodes. I updated this rule to enumerate disallowed node types rather than allowed node types in order to ignore unknown nodes.no-useless-call
f7fd797 ... It handlesChainExpression
nodes.no-whitespace-before-property
b5fa99a ... It handles?.
tokens correctly.operator-assignment
6468c0c ... It handlesChainExpression
nodes.padding-line-between-statements
5740538 ... It handlesChainExpression
nodes.prefer-arrow-callback
d0fc1b1 ... It handlesChainExpression
nodes.prefer-destructuring
a443a1e ... Some tests are added.prefer-exponentiation-operator
ca0b2a8 ... It handlesChainExpression
nodes.prefer-numeric-literals
d978d36 ... It handlesChainExpression
nodes.prefer-promise-reject-errors
5c7368c ... It handlesChainExpression
nodes.prefer-regex-literals
651bac3 ... It handlesChainExpression
nodes.prefer-spread
a3cbe6e ... It handlesChainExpression
nodes.use-isnan
17ec3d0 ... It handlesChainExpression
nodes.wrap-iife
233e737 ... It handlesChainExpression
nodes.yoda
89b65bf ... It handlesChainExpression
nodes.Is there anything you'd like reviewers to focus on?
ChainExpression
nodes that are at thecallee|object
properties. And some rules needed fixing autofix logic for the?.
token.dot-location
forobj?.[key]
? The rule ignores computed properties currently, but we can insert line breaks between?.
and[
, so we can choose eitherobj?.\n[key]
orobj\n?.[key]
. I guess we have to add a new option for that.Remaining steps:
espree
.espree
.