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 · 1 comment
Open

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.

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

2 participants