babylon-eslint v1.0.0
babel-eslint

babel-eslint allows you to lint ALL valid Babel code with the fantastic ESLint.
Note: You don't need to use babel-eslint if you are using ES2015 (ES6), ES2016 (ES7) or ES2017 (ES8). ESLint actually supports ES2015/ES2016/ES2017, JSX, and object rest/spread by default now.
At the moment, you'll need it if you use stuff like class properties, decorators, types.
If there is an issue, first check if it can be reproduced with the regular parser or with the latest versions of
eslintandbabel-eslint!
For questions and support please visit the #linting babel slack channel (sign up here)!
Note that the
ecmaFeaturesconfig property may still be required for ESLint to work properly with features not in ECMAScript 5 by default. Examples areglobalReturnandmodules).
Known Issues
Flow:
Check out eslint-plugin-flowtype: An
eslintplugin that makes flow type annotations global variables and marks declarations as used. Solves the problem of false positives withno-undefandno-unused-vars.
Modules/strict mode
no-unused-vars: [2, {vars: local}]#136
Please check out eslint-plugin-react for React/JSX issues
no-unused-varswith jsx
Please check out eslint-plugin-babel for other issues such as (and more):
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 |
|---|---|
| 1.x | <= 5.x |
| 2.x | >= 6.x |
| 3.x | >= 6.x |
Install
$ npm install eslint@1.x babel-eslint@5 --save-dev
$ npm install eslint@2.x babel-eslint@6 --save-dev
$ npm install eslint@3.x babel-eslint@6 --save-devSetup
.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 can be set to true to allow import and export declarations to appear anywhere a statement is allowed if your build environment supports that. By default, import and export declarations can only appear at a program's top level.
.eslintrc
{
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": false
}
}Run
$ eslint your-files-here9 years ago