DEV Community

Masato Ohba
Masato Ohba

Posted on

Use babel-eslint for code using not standardized specifications

Parsing error on ESLint

While writing code for review-waiting-list-bot, I came across the following Parsing error on eslint.

$ eslint .

/Users/ohbarye/.ghq/github.com/ohbarye/review-waiting-list-bot/src/App.js
  19:21  error  Parsing error: Unexpected token ..

✖ 1 problem (1 error, 0 warnings)

error Command failed with exit code 1.
Enter fullscreen mode Exit fullscreen mode

The cause seemed due to code using not standardized specifications like below. Yeah, Object Rest/Spread Properties is obviously still at stage 3 (as of 2018-04-30).

const { authors, ...conditions } = { authors: [], owner: '', repo: '' }
Enter fullscreen mode Exit fullscreen mode

Besides, eslint officially says that the default eslint parser SHOULD behave so.

ref: https://github.com/eslint/eslint/issues/6693

babel-eslint

When we'd like to use stage n specification, we need to use babel-eslint.

First, let's add it as a devDependency.

yarn add -D babel-eslint
Enter fullscreen mode Exit fullscreen mode

Then, specify a parser in .eslintrc.json.

# .eslintrc.json
{
  "parser": "babel-eslint",
  ...
}
Enter fullscreen mode Exit fullscreen mode

Now I could meet the sparkle again. ✨

$ eslint .
✨  Done in 1.45s.
Enter fullscreen mode Exit fullscreen mode

Environment

  • yarn v1.6.0
  • Node v8.3.0
  • eslint v4.4.1
  • babel-eslint v8.2.3

Top comments (0)