• This repository has been archived on 19/Aug/2021
  • Stars
    star
    2,963
  • Rank 15,284 (Top 0.4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

đŸ—ŧ A wrapper for Babel's parser used for ESLint (renamed to @babel/eslint-parser)

babel-eslint npm travis npm-downloads

NOTE: babel-eslint is now @babel/eslint-parser and has moved into the Babel monorepo.

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

Breaking changes in v11.x.x

As of the v11.x.x release, babel-eslint now requires Babel as a peer dependency and expects a valid Babel configuration file to exist. This ensures that the same Babel configuration is used during both linting and compilation.

v11 also changes some AST node types to match espree v6:

  • ExperimentalSpreadProperty became SpreadElement.
  • ExperimentalRestProperty became RestElement.
  • Literal became JSXText (for JSXText).

When should I use babel-eslint?

ESLint's default parser and core rules only support the latest final ECMAScript standard and do not support experimental (such as new features) and non-standard (such as Flow or TypeScript types) syntax provided by Babel. babel-eslint is a parser that allows ESLint to run on source code that is transformed by Babel.

Note: You only need to use babel-eslint if you are using Babel to transform your code. If this is not the case, please use the relevant parser for your chosen flavor of ECMAScript (note that the default parser supports all non-experimental syntax as well as JSX).

How does it work?

ESLint allows for the use of custom parsers. When using this plugin, your code is parsed by Babel's parser (using the configuration specified in your Babel configuration file) and the resulting AST is transformed into an ESTree-compliant structure that ESLint can understand. All location info such as line numbers, columns is also retained so you can track down errors with ease.

Note: ESLint's core rules do not support experimental syntax and may therefore not work as expected when using babel-eslint. Please use the companion eslint-plugin-babel plugin for core rules that you have issues with.

Usage

Installation

$ npm install eslint babel-eslint --save-dev
# or
$ yarn add eslint babel-eslint -D

Note: babel-eslint requires babel/core@>=7.2.0 and a valid Babel configuration file to run. If you do not have this already set up, please see the Babel Usage Guide.

Setup

To use babel-eslint, "babel-eslint" must be specified as the parser in your ESLint configuration file (see here for more detailed information).

.eslintrc.js

module.exports = {
  parser: "babel-eslint",
};

With the parser set, your configuration can be configured as described in the Configuring ESLint documentation.

Note: The parserOptions described in the official documentation are for the default parser and are not necessarily supported by babel-eslint. Please see the section directly below for supported parserOptions.

Additional parser configuration

Additional configuration options can be set in your ESLint configuration under the parserOptions key. Please note that the ecmaFeatures config property may still be required for ESLint to work properly with features not in ECMAScript 5 by default.

  • requireConfigFile (default true) can be set to false to allow babel-eslint to run on files that do not have a Babel configuration associated with them. This can be useful for linting files that are not transformed by Babel (such as tooling configuration files), though we recommend using the default parser via glob-based configuration. Note: babel-eslint will not parse any experimental syntax when no configuration file is found.
  • 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.
  • ecmaFeatures.globalReturn (default false) allow return statements in the global scope when used with sourceType: "script".
  • babelOptions passes through Babel's configuration loading and merging options (for instance, in case of a monorepo). When not defined, babel-eslint will use Babel's default configuration file resolution logic.

.eslintrc.js

module.exports = {
  parser: "babel-eslint",
  parserOptions: {
    sourceType: "module",
    allowImportExportEverywhere: false,
    ecmaFeatures: {
      globalReturn: false,
    },
    babelOptions: {
      configFile: "path/to/config.js",
    },
  },
};

.eslintrc.js using glob-based configuration

This configuration would use the default parser for all files except for those found by the "files/transformed/by/babel/*.js" glob.

module.exports = {
  rules: {
    indent: "error"
  },
  overrides: [
    {
      files: ["files/transformed/by/babel/*.js"],
      parser: "babel-eslint",
    }
  ]
};

Run

$ ./node_modules/.bin/eslint yourfile.js

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: ["error", { 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.

Questions and support

If you have an issue, please first check if it can be reproduced with the default parser and with the latest versions of eslint and babel-eslint. If it is not reproducible with the default parser, it is most likely an issue with babel-eslint.

For questions and support please visit the #discussion Babel Slack channel (sign up here) or the ESLint Gitter.

More Repositories

1

babel

🐠 Babel is a compiler for writing next generation JavaScript.
TypeScript
43,141
star
2

babel-loader

đŸ“Ļ Babel loader for webpack
JavaScript
4,824
star
3

minify

✂ī¸ An ES6+ aware minifier based on the Babel toolchain (beta)
JavaScript
4,391
star
4

babel-preset-env

PSA: this repo has been moved into babel/babel -->
JavaScript
3,500
star
5

babel-sublime

Syntax definitions for ES6 JavaScript with React JSX extensions.
JavaScript
3,256
star
6

example-node-server

Example Node Server w/ Babel
JavaScript
2,844
star
7

babylon

PSA: moved into babel/babel as @babel/parser -->
JavaScript
1,714
star
8

babelify

Browserify transform for Babel
JavaScript
1,680
star
9

gulp-babel

Gulp plugin for Babel
JavaScript
1,320
star
10

babel-upgrade

âŦ†ī¸ A tool for upgrading Babel versions (to v7): `npx babel-upgrade`
JavaScript
1,309
star
11

awesome-babel

😎A list of awesome Babel plugins, presets, etc.
864
star
12

babel-standalone

🎮 Now located in the Babel repo! Standalone build of Babel for use in non-Node.js environments, including browsers.
JavaScript
819
star
13

website

🌐 The Babel documentation website
TypeScript
749
star
14

preset-modules

A Babel preset that targets modern browsers by fixing engine bugs (will be merged into preset-env eventually)
JavaScript
739
star
15

kneden

Transpile ES2017 async/await to vanilla ES6 Promise chains: a Babel plugin
JavaScript
514
star
16

grunt-babel

Grunt plugin for Babel
JavaScript
437
star
17

proposals

✍ī¸ Tracking the status of Babel's implementation of TC39 proposals (may be out of date)
432
star
18

eslint-plugin-babel

An ESlint rule plugin companion to babel-eslint
JavaScript
389
star
19

generator-babel-boilerplate

A Yeoman generator to author libraries in ES2015 (and beyond!) for Node and the browser.
JavaScript
381
star
20

babel-time-travel

Time travel through babel transformations one by one (implemented in the Babel REPL now)
JavaScript
344
star
21

babel-polyfills

A set of Babel plugins that enable injecting different polyfills with different strategies in your compiled code.
TypeScript
330
star
22

babel-sublime-snippets

Next generation JavaScript and React snippets for Sublime
263
star
23

karma-babel-preprocessor

Karma plugin for Babel
JavaScript
167
star
24

ruby-babel-transpiler

Ruby Babel is a bridge to the JS Babel transpiler.
Ruby
159
star
25

babel-jest

Jest plugin for Babel (moved) ->
138
star
26

notes

â™Ŧ Notes from the @Babel Team (discuss in PRs)
122
star
27

generator-babel-plugin

Babel Plugin generator for Yeoman
JavaScript
118
star
28

babel-bridge

A placeholder package that bridges babel-core to @babel/core.
JavaScript
94
star
29

babel-bot

🤖 A helpful bot to automate common tasks on Babel Issues/PRs
JavaScript
75
star
30

babel-brunch

Brunch plugin for Babel
JavaScript
68
star
31

broccoli-babel-transpiler

Broccoli plugin for Babel
JavaScript
57
star
32

jade-babel

Jade plugin for Babel
JavaScript
40
star
33

sandboxes

Babel repl-like codesandbox: check out link =>
JavaScript
39
star
34

jekyll-babel

A Babel converter for Jekyll.
Ruby
34
star
35

acorn-to-esprima

(unmaintained) Converts acorn tokens to esprima tokens
JavaScript
33
star
36

babel-connect

Connect plugin for Babel
JavaScript
27
star
37

podcast.babeljs.io

The Babel Podcast site!
JavaScript
25
star
38

phabricator-to-github

A tool to migrate phabricator issues to github
JavaScript
24
star
39

actions

Babel specific github actions 🤖
JavaScript
24
star
40

rfcs

RFCs for changes to Babel
21
star
41

metalsmith-babel

A Metalsmith plugin to compile JavaScript with Babel
JavaScript
20
star
42

babel-configuration-examples

WIP
JavaScript
18
star
43

logo

Babel logo
15
star
44

duo-babel

Duo plugin for Babel
JavaScript
15
star
45

parser_performance

JavaScript
13
star
46

eslint-config-babel

ESLint config for all Babel repos
JavaScript
10
star
47

gobble-babel

Gobble plugin for Babel
JavaScript
9
star
48

babel-standalone-bower

Bower build of babel-standalone. See https://github.com/Daniel15/babel-standalone
JavaScript
9
star
49

eslint-plugin-babel-plugin

A set of eslint rules to enforce best practices in the development of Babel plugins.
JavaScript
8
star
50

babel-plugin-proposal-private-property-in-object

@babel/plugin-proposal-private-property-in-object, with an added warning for when depending on this package without explicitly listing it in dependencies or devDependencies
JavaScript
8
star
51

babel-archive

🗑 Packages that are deprecated or don't need to be updated
JavaScript
7
star
52

.github

Community health files for the Babel organization
7
star
53

flavortown

what else?
6
star
54

babel-test262-runner

Run test262 tests on Node 0.10 using Babel 7 and `core-js@3`.
JavaScript
6
star
55

babel-plugin-transform-async-functions

https://github.com/MatAtBread/fast-async/issues/46
4
star
56

phabricator-redirects

↩ī¸ Redirects for old phabricator urls
HTML
2
star
57

slack-invite-link

Source of slack.babeljs.io
1
star