Socket
Socket
Sign inDemoInstall

babel-eslint

Package Overview
Dependencies
5
Maintainers
2
Versions
135
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-eslint

Custom parser for ESLint


Version published
Maintainers
2
Install size
4.38 MB
Created

Package description

What is babel-eslint?

The babel-eslint npm package is a parser that allows you to lint all valid Babel code with the ESLint linter. It is designed to be used with ESLint and Babel, providing compatibility between the two and allowing developers to use ESLint on code that contains Babel-specific syntax.

What are babel-eslint's main functionalities?

Parsing Babel Code for ESLint

This feature allows developers to configure ESLint to use babel-eslint as the parser, enabling ESLint to understand and lint code that includes Babel-specific syntax that is not yet supported by ESLint's default parser.

module.exports = { parser: 'babel-eslint', rules: { /* ESLint rules */ } };

Experimental Syntax Support

babel-eslint can parse experimental syntax such as class properties and async functions, which might not be supported by ESLint's default parser. This allows developers to use ESLint on projects that make use of the latest JavaScript features.

class MyClass { async myMethod() { /* ... */ } }

Custom Babel Configuration

babel-eslint allows developers to specify a custom Babel configuration file, ensuring that the parser understands the code in the same way Babel does when it transpiles the code.

{ "parserOptions": { "babelOptions": { "configFile": "path/to/your/babel.config.js" } } }

Other packages similar to babel-eslint

Readme

Source

babel-eslint

Build Status

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 only using ES6/ES2015. ESLint actually supports ES6/ES7, JSX, and object rest/spread by default now.
At the moment, you'll need it if you use stuff like class properties, decorators, async/await, types.

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 #linting babel slack channel (sign up here)!

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-flow-vars: 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 such as (and more):

  • generator-star with async/await functions #78
  • object-shorthand with spread operator #131

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

Install

$ npm install eslint@1.x babel-eslint@5 --save-dev

$ npm install eslint@2.x babel-eslint@6 --save-dev

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 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-here

FAQs

Last updated on 09 Jul 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc