Issue with eslint-config-airbnb-base and `optional chaining` operator
- Vorherrschende Sprache
- JavaScript
- Sterne
- 148k
- Forks
- 26.6k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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
```
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Den Parsing-Fehler mithilfe der .eslintrc.js-Konfigurationen und des optional-chaining-Beispiels reproduzieren und airbnb-base mit der Konfiguration ohne airbnb-base vergleichen. Untersuche, wie airbnb-base Parser-Optionen festlegt; abgeschlossen ist die Aufgabe, wenn optional chaining mit env es2021 ohne ein explizites ecmaVersion geparst wird oder die erforderliche Konfiguration eindeutig dokumentiert ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- eslint, javascript
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100