Issue with eslint-config-airbnb-base and `optional chaining` operator
- Lingua principale
- JavaScript
- Stelle
- 148k
- Fork
- 26.6k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Issue with `eslint-config-airbnb-base` and [optional chaining](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) operator `?.` `(JavaScript)`
```javascript
// .eslintrc.js
module.exports = {
env: { es2021: true },
extends: [ 'airbnb-base' ]
};
```
```javascript
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](https://eslint.org/docs/user-guide/configuring/language-options) 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:
```javascript
// .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:
```javascript
// .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
```
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Riprodurre l’errore di parsing usando le configurazioni .eslintrc.js e l’esempio optional-chaining, confrontando airbnb-base con la configurazione senza airbnb-base. Esaminare come airbnb-base imposta le opzioni del parser; il lavoro è completo quando optional chaining viene analizzato con env es2021 senza un ecmaVersion esplicito, oppure quando la configurazione richiesta è documentata chiaramente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- eslint, javascript
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100