babel/babel-eslint


tokyo_tower A wrapper for Babel's parser used for ESLint

https://github.com/babel/babel-eslint/issues/88

License: MIT

Language: JavaScript

Keywords: babel, babel-eslint, eslint, javascript


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 eslint@4.x babel-eslint@8 --save-dev
# or
$ yarn add eslint@4.x babel-eslint@8 -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

Project Statistics

Sourcerank 23
Repository Size 761 KB
Stars 2,345
Forks 167
Watchers 60
Open issues 89
Dependencies 292
Contributors 53
Tags 111
Created
Last updated
Last pushed

Top Contributors See all

Henry Zhu Sebastian McKenzie Andres Suarez Brian Ng Toru Nagashima Benoît Zugmeyer greenkeeper[bot] Rubén Norte Kai Cataldo Greenkeeper Rafał Ruciński Joshua Peek Teddy Katz Kir Belevich Reyad Attiyat Logan Smyth Michael Ferris Brian Donovan Jordan Gensler Luís Couto

Packages Referencing this Repo

babel-eslint
Custom parser for ESLint
Latest release 10.0.1 - Updated - 2.35K stars
@gerhobbelt/babel-eslint
Custom parser for ESLint
Latest release 9.0.0-3 - Updated - 2.35K stars
@airdwing/babel-eslint
Custom parser for ESLint
Latest release 8.0.0-alpha.17 - Published - 2.35K stars
@alexjeffburke/babel-eslint
Custom parser for ESLint
Latest release 7.2.2-patch1 - Published - 2.35K stars
babel-to-estree
Translate a Babel AST to an ESTree-compliant AST. A "fork" of babel-eslint/babylon-to-espree.
Latest release 0.0.3 - Updated - 2.35K stars
org.webjars.npm:babel-eslint
WebJar for babel-eslint
Latest release 7.2.3 - Updated - 2.35K stars
babel-eslint
WebJar for babel-eslint
Latest release 7.2.3 - Updated - 2.35K stars

Recent Tags See all

v10.0.1 September 27, 2018
v10.0.0 September 25, 2018
v9.0.0 August 27, 2018
v8.2.6 July 12, 2018
v9.0.0-beta.3 July 12, 2018
v9.0.0-beta.2 July 06, 2018
v9.0.0-beta.1 June 29, 2018
v8.2.5 June 23, 2018
v8.2.4 June 22, 2018
v8.2.3 April 13, 2018
v8.2.2 February 20, 2018
v8.2.1 January 09, 2018
v8.2.0 January 08, 2018
v8.1.2 December 26, 2017
v8.1.1 December 25, 2017

Interesting Forks See all

niilante/babel-eslint
tokyo_tower ESLint using Babel as the parser.
JavaScript - Updated - 1 stars
tmcw/babel-eslint
ESLint using Babel as the parser.
JavaScript - Updated - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2018-06-23 13:45:42 UTC

Login to resync this repository