DEV Community

Masato Ohba
Masato Ohba

Posted on

2 1

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

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay