Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eslint - Optional chaining error with vscode

I am seeing a a red underline when I'm using an optional chain, but the code runs fine as I am on node 14

Here's my setup:

node 14.1.0 eslint "^6.8.0" 

.eslintrc.js

module.exports = {     "env": {         "node": true     },     "extends": [         "eslint:recommended",     ],     "parserOptions": {         "sourceType": "module",         "ecmaVersion": 2020     },     "rules": {     }, } 

enter image description here

like image 998
A. L Avatar asked May 06 '20 06:05

A. L


People also ask

Does ESLint support optional chaining?

Support for optional chaining was added in ESLint 7.5. 0. Also, @typescript-eslint/prefer-optional-chain can be used in JavaScript projects.

Is optional chaining safe?

Optional chaining is a safe and concise way to perform access checks for nested object properties. The optional chaining operator ?. takes the reference to its left and checks if it is undefined or null.

How do I check ESLint version?

Go to C:\Users\\{YourWindowsUsername}\AppData\Local\Microsoft\TypeScript\ESLint . Open the package. json file. You should see the version of ESLint that is installed, in my case it is "eslint": "4.19.


1 Answers

You no longer need @babel/eslint-parser as eslint@^7.5 now supports optional chanining.

Run the following to update eslint within your project:

npm

npm install --save-dev eslint@^7.5 

yarn

yarn add -D eslint@^7.5 

And then, ensure your config is as follows:

.eslintrc

{   "parserOptions": {     "ecmaVersion": 2020   } } 

.eslint.js

module.exports = {     "parserOptions": {         "ecmaVersion": 2020     } }  

See https://eslint.org/blog/2020/07/eslint-v7.5.0-released#optional-chaining-support for more information.

like image 106
steadweb Avatar answered Sep 25 '22 00:09

steadweb