Lemuel Castro
Lemuel Castro

Reputation: 166

ESLint error when using optional catch binding

With this code:

try {

} catch {

}

ESLint gives this error:

Parsing error: Unexpected token {

Is there an ESLint rule to enable optional catch binding?

Upvotes: 6

Views: 1728

Answers (2)

Alex
Alex

Reputation: 2369

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

Upvotes: 1

CertainPerformance
CertainPerformance

Reputation: 370759

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.

Upvotes: 8

Related Questions