@babel/eslint-parser (2024)

@babel/eslint-parser allows you to lint ALL valid Babel code with the fantasticESLint.

When should I use @babel/eslint-parser?

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-parser is a parser that allows ESLint to run on source code that is transformed by Babel.

Note: You only need to use @babel/eslint-parser 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 istransformed 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-parser. Please use the companion @babel/eslint-plugin plugin for core rules that you have issues with.

Installation

$ npm install eslint @babel/core @babel/eslint-parser --save-dev# or$ yarn add eslint @babel/core @babel/eslint-parser -D

Note: @babel/eslint-parser 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-parser, "@babel/eslint-parser" must be specified as the parser in your ESLint configuration file (see here for more detailed information).

.eslintrc.js

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

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-parser. 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-parser 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: When requireConfigFile is false, @babel/eslint-parser will still try to load the root babel config. If no configuration file is found, @babel/eslint-parser will not parse any experimental syntax. Though not recommended, if you have a babel config, but would like to prevent @babel/eslint-parser from loading Babel config, please specify.eslintrc.js
module.exports = { parser: "@babel/eslint-parser", parserOptions: { requireConfigFile: false, babelOptions: { babelrc: false, configFile: false, // your babel options presets: ["@babel/preset-env"], }, },};
  • 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 is an object containing Babel configuration options that are passed to Babel's parser at runtime. For cases where users might not want to use a Babel configuration file or are running Babel through another tool (such as Webpack with babel-loader).

.eslintrc.js

module.exports = { parser: "@babel/eslint-parser", 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-parser", }, ],};

Monorepo configuration

This configuration is useful for monorepo, when you are running ESLint on every package and not from the monorepo root folder, as it avoids to repeat the Babel and ESLint configuration on every package.

module.exports = { parser: "@babel/eslint-parser", parserOptions: { babelOptions: { rootMode: "upward", }, },};

Run

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

TypeScript

While @babel/eslint-parser can parse TypeScript, we don't currently support linting TypeScript using the rules in @babel/eslint-plugin. This is because the TypeScript community has centered around @typescript-eslint and we want to avoid duplicate work. Additionally, since @typescript-eslint uses TypeScript under the hood, its rules can be made type-aware, which is something Babel doesn't have the ability to do.

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-parser. If it is not reproducible with the default parser, it is most likely an issue with @babel/eslint-parser.

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

@babel/eslint-parser (2024)
Top Articles
Benefits of Not Getting Married Legally [Pros & Cons] | White Coat Investor
Ratings analysts: Salary, career path, job outlook, education and more - RaiseMe
It’s Time to Answer Your Questions About Super Bowl LVII (Published 2023)
Hotels Near 625 Smith Avenue Nashville Tn 37203
Lakers Game Summary
Kathleen Hixson Leaked
Best Team In 2K23 Myteam
What Happened To Dr Ray On Dr Pol
When is streaming illegal? What you need to know about pirated content
Fnv Turbo
Pbr Wisconsin Baseball
Wmlink/Sspr
A.e.a.o.n.m.s
Cranberry sauce, canned, sweetened, 1 slice (1/2" thick, approx 8 slices per can) - Health Encyclopedia
Dusk
WWE-Heldin Nikki A.S.H. verzückt Fans und Kollegen
House Of Budz Michigan
Gino Jennings Live Stream Today
Tamilrockers Movies 2023 Download
Paychex Pricing And Fees (2024 Guide)
Airrack hiring Associate Producer in Los Angeles, CA | LinkedIn
Music Go Round Music Store
Masterkyngmash
Pasco Telestaff
Rochester Ny Missed Connections
Boston Dynamics’ new humanoid moves like no robot you’ve ever seen
Understanding Gestalt Principles: Definition and Examples
Chime Ssi Payment 2023
Booknet.com Contract Marriage 2
Kimoriiii Fansly
Restaurants In Shelby Montana
Pacman Video Guatemala
Waters Funeral Home Vandalia Obituaries
Dl.high Stakes Sweeps Download
Elijah Streams Videos
Miss America Voy Board
Autotrader Bmw X5
Dreamcargiveaways
Nicole Wallace Mother Of Pearl Necklace
Ixl Lausd Northwest
Tamil Play.com
Movies123.Pick
Today's Final Jeopardy Clue
Carespot Ocoee Photos
Final Exam Schedule Liberty University
Tds Wifi Outage
Ktbs Payroll Login
How To Customise Mii QR Codes in Tomodachi Life?
Skyward Cahokia
Displacer Cub – 5th Edition SRD
Dietary Extras Given Crossword Clue
Ingersoll Greenwood Funeral Home Obituaries
Latest Posts
Article information

Author: Kelle Weber

Last Updated:

Views: 5346

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.