Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESLint error when using optional catch binding

Tags:

node.js

eslint

With this code:

try {

} catch {

}

ESLint gives this error:

Parsing error: Unexpected token {

Is there an ESLint rule to enable optional catch binding?

like image 364
Lemuel Castro Avatar asked Aug 08 '19 01:08

Lemuel Castro


2 Answers

It's an ES2019 feature, so make sure you set an ecmaVersion of 10. For example, your .eslintrc.json should have:

{
    "parserOptions": {
        "ecmaVersion": 10
    }
}

Setting parser options helps ESLint determine what is a parsing error.

Similarly, for the online demo, make sure to select 2019 from the "ECMA Version" dropdown list.

like image 190
CertainPerformance Avatar answered Oct 13 '22 20:10

CertainPerformance


For some reason

{
    "parserOptions": {
        "ecmaVersion": 10
    }
}

did not work for me.

But this did:

"rules": {
  "no-empty": ["error", { "allowEmptyCatch": true }]
},

For more info see https://eslint.org/docs/rules/no-empty#allowemptycatch

like image 36
Alex Avatar answered Oct 13 '22 20:10

Alex