🌜
🌞
babel-eslint

babel-eslint

v10.1.0

Custom parser for ESLint

npm install babel-eslint

README

babel-eslint npm travis npm-downloads

babel-eslint allows you to lint ALL valid Babel code with the fantastic ESLint.

Why Use babel-eslint

You only need to use babel-eslint if you are using types (Flow) or experimental features not supported in ESLint itself yet. Otherwise try the default parser (you don't have to use it just because you are using Babel).


If there is an issue, first check if it can be reproduced with the regular parser or with the latest versions of eslint and babel-eslint!

For questions and support please visit the #discussion babel slack channel (sign up here) or eslint gitter!

Note that the ecmaFeatures config property may still be required for ESLint to work properly with features not in ECMAScript 5 by default. Examples are globalReturn and modules).

Known Issues

Flow:

Check out eslint-plugin-flowtype: An eslint plugin that makes flow type annotations global variables and marks declarations as used. Solves the problem of false positives with no-undef and no-unused-vars.

  • no-undef for global flow types: ReactElement, ReactClass #130
    • Workaround: define types as globals in .eslintrc or define types and import them import type ReactElement from './types'
  • no-unused-vars/no-undef with Flow declarations (declare module A {}) #132

Modules/strict mode

  • no-unused-vars: [2, {vars: local}] #136

Please check out eslint-plugin-react for React/JSX issues

  • no-unused-vars with jsx

Please check out eslint-plugin-babel for other issues

How does it work?

ESLint allows custom parsers. This is great but some of the syntax nodes that Babel supports aren't supported by ESLint. When using this plugin, ESLint is monkeypatched and your code is transformed into code that ESLint can understand. All location info such as line numbers, columns is also retained so you can track down errors with ease.

Basically babel-eslint exports an index.js that a linter can use. It just needs to export a parse method that takes in a string of code and outputs an AST.

Usage

Supported ESLint versions

ESLint babel-eslint
4.x >= 6.x
3.x >= 6.x
2.x >= 6.x
1.x >= 5.x

Install

Ensure that you have substituted the correct version lock for eslint and babel-eslint into this command:

$ npm install [email protected] [email protected] --save-dev
# or
$ yarn add [email protected] [email protected] -D

Setup

.eslintrc

{
  "parser": "babel-eslint",
  "rules": {
    "strict": 0
  }
}

Check out the ESLint docs for all possible rules.

Configuration

  • sourceType can be set to 'module'(default) or 'script' if your code isn't using ECMAScript modules.
  • allowImportExportEverywhere (default false) can be set to true to allow import and export declarations to appear anywhere a statement is allowed if your build environment supports that. Otherwise import and export declarations can only appear at a program's top level.
  • codeFrame (default true) can be set to false to disable the code frame in the reporter. This is useful since some eslint formatters don't play well with it.

.eslintrc

{
  "parser": "babel-eslint",
  "parserOptions": {
    "sourceType": "module",
    "allowImportExportEverywhere": false,
    "codeFrame": true
  }
}

Run

$ eslint your-files-here

Release Notes

11.0.0-beta.0
By Henry Zhu • Published on January 21, 2019

v11.0.0-beta.0

Major version bump! Mostly #711 which requires that you have a Babel config file and babel-eslint will read from that to enable the correct syntax.

10.1.0
By Brian Ng • Published on February 26, 2020
  • Added ability to parse Flow enums #812 (@gkz)
10.0.3
By Henry Zhu • Published on August 25, 2019

Fixes https://github.com/babel/babel-eslint/issues/791, also https://github.com/eslint/eslint/issues/12117

Some context: https://github.com/babel/babel-eslint/pull/793#issuecomment-524435971

We ended up going with @JLHwung's PR https://github.com/babel/babel-eslint/pull/794 which uses ESLint's deps instead of going with peerDeps since it really depends on the version being used and we don't want users to have to install it directly on their own.

babel-eslint is patching patches of the dependencies of ESLint itself so these kinds of issues have happened in the past. We'll need to look into figuring out how to have a more solid way of modifying behavior instead of this monkeypatching type of thing for future releases.

10.0.2
By Henry Zhu • Published on June 17, 2019
10.0.1
By Henry Zhu • Published on September 27, 2018

v10.0.1

The TypeAlias "conversion" to a function has issues. Sounds like we need to rethink the change, most likely we can just actually change the scoping rather than hardcode an AST change.

10.0.0
By Henry Zhu • Published on September 25, 2018

v10.0.0

Small breaking change: add a peerDependency starting from the ESLint version that added a parser feature that we were monkeypatching before (and drop that code). If already using ESLint 5 shouldn't be any different.

/* @flow */
type Node<T> = { head: T; tail: Node<T> }

// or 

type File = {chunks: Array<Chunk>}
type Chunk = {file: File}
9.0.0
By Henry Zhu • Published on August 27, 2018

v9.0.0

We've released v7: https://twitter.com/left_pad/status/1034204330352500736, so this just updates babel-eslint to use those versions internally. That in itself doesn't break anything but:

  • Babel now supports the new decorators proposal by default, so we need to switch between the new and the old proposal. This is a breaking change.

To enable the legacy decorators proposal users should add a specific parser option:

{
  parserOptions: {
    ecmaFeatures: {
      legacyDecorators: true
    }
  }
}
  • Babel removed the support for Node 4 , so I propagated that here.
8.1.0
By Teddy Katz • Published on December 24, 2017

Use ESLint's API to customize scope analysis and avoid monkeypatching: https://github.com/babel/babel-eslint/pull/542

8.0.1
By Henry Zhu • Published on September 26, 2017

v8.0.1

Handle optionalCatchBinding: https://github.com/babel/babel-eslint/pull/521

8.0.0
By Henry Zhu • Published on September 12, 2017

8.0.0

No major changes, just updating babel deps to v7

General

License
MIT
Typescript Types
None found
Tree-shakeable
No

Popularity

GitHub Stargazers
2,969
Community Interest
3,376
Number of Forks
235

Maintenance

Commits
10/219/2201
Last Commit
Oct 10, 2020
Open Issues
0
Closed Issues
493
Open Pull Requests
4
Closed Pull Requests
130

Versions

Versions Released
10/219/2201
Latest Version Released
Feb 26, 2020
Current Tags
latest10.1.0
next11.0.0-beta.2

Contributors

hzoo
hzoo
Commits: 222
sebmck
sebmck
Commits: 66
danez
danez
Commits: 30
zertosh
zertosh
Commits: 17
kaicataldo
kaicataldo
Commits: 17
existentialism
existentialism
Commits: 16
mysticatea
mysticatea
Commits: 9
BenoitZugmeyer
BenoitZugmeyer
Commits: 8
greenkeeper[bot]
greenkeeper[bot]
Commits: 7
greenkeeperio-bot
greenkeeperio-bot
Commits: 5
rubennorte
rubennorte
Commits: 5
josh
josh
Commits: 4
loganfsmyth
loganfsmyth
Commits: 4
fatfisz
fatfisz
Commits: 4
soda0289
soda0289
Commits: 3