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

Issue with eslint-config-airbnb-base and optional chaining operator #2541

Open
kayomarz opened this issue Jan 17, 2022 · 10 comments
Open

Issue with eslint-config-airbnb-base and optional chaining operator #2541

kayomarz opened this issue Jan 17, 2022 · 10 comments

Comments

@kayomarz
Copy link

kayomarz commented Jan 17, 2022

Issue with eslint-config-airbnb-base and optional chaining operator ?. (JavaScript)

// .eslintrc.js
module.exports = {
  env: { es2021: true },
  extends: [ 'airbnb-base' ]
};
const o = {};
const a = o?.a;

For the above code, ESLint reports Parsing error: Unexpected token at the optional chaining operator ?.

ESLint rules for optional chaining should work with parserOption: {ecmaVersion: 2020} or higher and which eslint automatically sets because env: {es2021: true} is used in the config above.

However when airbnb-base is used, an explicit parserOption: ecmaVersion: 12 seems to be required to resolve the above issue as such:

// .eslintrc.js
module.exports = {
  env: { es2021: true },
  extends: [ 'airbnb-base' ],
  parserOptions: { ecmaVersion: 12 }
};

(Note: ecmaVersion: 11 should also work)

The error does not occur without airbnb-base as below:

// .eslintrc.js
module.exports = {
  env: { es2021: true }
};

Although the fix is simply to explicitly state ecmaVersion it can take a while to figure out that the Parsing error: Unexpected token is because of airbnb-base.

When this issue occors, all other lint errors in the file are not reported which means eslint stops working!

For a better developer experience, this issue could be looked into or documented well.

The above issue occurred with:

Local ESLint version: ^8.7.0
Global ESLint version: ^8.7.0
Node version: v14.17.3
npm version: 6.14.13
Operating System: Linux
@ljharb
Copy link
Collaborator

ljharb commented Jan 17, 2022

Does babel-preset-airbnb transform that yet? If so, then

can be updated.

@Vivek-04022001

This comment was marked as off-topic.

@ljharb

This comment was marked as resolved.

@Vivek-04022001

This comment was marked as resolved.

@bhyxen
Copy link

bhyxen commented Aug 24, 2023

Hello,

I'm having the same issue with eslint-config-airbnb.

Also, when using the option:

  • "env": { "shared-node-browser": true}

It does not recognize browser global variables like document.

This issue does not happen if I remove airbnb from my extends configuration.

@ljharb
Copy link
Collaborator

ljharb commented Aug 24, 2023

@branzdev we don't set that env value so i'm not sure why that would affect it. what's your eslint config?

@martijnhjk
Copy link

I am also having to add parserOptions: { ecmaVersion: 12 }, any developments on this topic?

@ljharb
Copy link
Collaborator

ljharb commented Nov 29, 2023

@martijnhjk thats expected pending #2541 (comment)

@martijnhjk
Copy link

@ljharb I am not sure I understand. That comment was made over a year and a half ago. Will the ecmaVersion be updated in the config? Or is overriding parserOptions the final recommended practice?

@ljharb
Copy link
Collaborator

ljharb commented Nov 30, 2023

Time doesn’t change whether it’s correct.

Overriding parserOptions is the current only option, and nothing is final.

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

No branches or pull requests

5 participants