Joey Yi Zhao
Joey Yi Zhao

Reputation: 42576

How to enable `eslint` to parse spread operator?

I am using eslint for a javascript project. eslint failed to parse spread operator and I got this error 11:18 error Parsing error: Unexpected token ...

The code for above error is:

return { ...render }

The eslint configuration is yml file:

env:
  browser: true
  es6: true
extends: 'eslint:recommended'
parserOptions:
  ecmaVersion: 2017
  sourceType: module
  experimentalObjectRestSpread: true
rules:
  indent:
    - error
    - 4
  linebreak-style:
    - error
    - unix
  quotes:
    - error
    - single
  semi:
    - error
    - always
  no-console:
    - off
  prefer-spread: "error"

Upvotes: 8

Views: 4989

Answers (2)

holroy
holroy

Reputation: 3127

This is related to ESLint doesn't support spread operator in objects #10307, where full description of various alternatives on how to fix it is listed.

Essentially it boils down to changing to ecmaVersion: 2018 (or the equivalent ecmaVersion: 9), which is when it first was officially supported. With this change there is also no need for the experimentalObjectRestSpread: true any more.

Upvotes: 6

Joey Yi Zhao
Joey Yi Zhao

Reputation: 42576

The issue is fixed by add configuration: parser: 'babel-eslint'

Upvotes: -1

Related Questions