Skip to content
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

Rules for nullish coalescing and optional chaining #2146

Open
tao-liu-liftoff opened this issue Dec 20, 2019 · 6 comments
Open

Rules for nullish coalescing and optional chaining #2146

tao-liu-liftoff opened this issue Dec 20, 2019 · 6 comments

Comments

@tao-liu-liftoff
Copy link

I noticed that babel-preset-airbnb added the following stage 4 proposals in v4.2.0:

  • @babel/plugin-proposal-nullish-coalescing-operator
  • @babel/plugin-proposal-optional-chaining

Are there any rules/guidelines for these features?

@ljharb
Copy link
Collaborator

ljharb commented Dec 20, 2019

Once they're added to babel-preset-airbnb by airbnb folks, and once appropriate eslint rules for them exist, then they'll be added to this guide.

@braco
Copy link

braco commented May 22, 2020

Doesn't this exist now?

@ljharb
Copy link
Collaborator

ljharb commented May 24, 2020

The former has happened; I don't believe there's been any new eslint rules for them.

If there's changes needed in the configs to allow the syntax (other than #2223), happy to review a PR that adds them.

@travi
Copy link

travi commented Nov 14, 2020

If there's changes needed in the configs to allow the syntax (other than #2223), happy to review a PR that adds them.

it looks like syntax support for optional-chaining was added to eslint in v7.5.0, so to avoid the need to use babel-eslint, it looks like the ecmaVersion needs to be set to 2020 (or 11).

if i were to send a PR, would this be the proper place to apply that update?

i dont think setting the ecmaVersion would require changing peerDependencies, but getting the optional-chaining support would obviously require using v7.5.0 or newer.

@ljharb
Copy link
Collaborator

ljharb commented Nov 25, 2020

es6 wouldn't be appropriate, since ES6 doesn't have optional chaining.

Which version of eslint started supporting an ecmaVersion of 2020? https://eslint.org/blog/2019/08/eslint-v6.2.0-released implies v6.2 but doesn't explicitly mention nullish coalescing or optional chaining; https://eslint.org/blog/2020/07/eslint-v7.5.0-released however specifically talks about optional chaining.

Since we currently allow eslint v5.16, v6.8, or v7.2, it would indeed be a breaking change to change the ecmaVersion to 2020.

In the meantime, it seems pretty simple to set that yourself in your own config?

@travi
Copy link

travi commented Nov 26, 2020

In the meantime, it seems pretty simple to set that yourself in your own config?

yep, and I've already done so: https://github.com/form8ion/eslint-config/blob/f332890c401b1d796dc459322a3f7cbc646f4d44/index.js#L11-L13, but was hoping to help here if it could be useful.

es6 wouldn't be appropriate, since ES6 doesn't have optional chaining.

yeah, that makes sense

Which version of eslint started supporting an ecmaVersion of 2020? eslint.org/blog/2019/08/eslint-v6.2.0-released implies v6.2

yeah, that seems like the earliest introduction, so it seems this would be premature until the lowest supported version here is raised.

sounds like it's best to continue with this just in my own config for now. thanks for all of your efforts here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
@ljharb @travi @braco @tao-liu-liftoff and others