| # ESLintRC Library |
|
|
| This repository contains the legacy ESLintRC configuration file format for ESLint. This package is not intended for use outside of the ESLint ecosystem. It is ESLint-specific and not intended for use in other programs. |
|
|
| **Note:** This package is frozen except for critical bug fixes as ESLint moves to a new config system. |
|
|
| ## Installation |
|
|
| You can install the package as follows: |
|
|
| ```shell |
| npm install @eslint/eslintrc -D |
| # or |
| yarn add @eslint/eslintrc -D |
| # or |
| pnpm install @eslint/eslintrc -D |
| # or |
| bun install @eslint/eslintrc -D |
| ``` |
|
|
| ## Usage (ESM) |
|
|
| The primary class in this package is `FlatCompat`, which is a utility to translate ESLintRC-style configs into flat configs. Here's how you use it inside of your `eslint.config.js` file: |
|
|
| ```js |
| import { FlatCompat } from "@eslint/eslintrc"; |
| import js from "@eslint/js"; |
| import path from "path"; |
| import { fileURLToPath } from "url"; |
| |
| // mimic CommonJS variables -- not needed if using CommonJS |
| const __filename = fileURLToPath(import.meta.url); |
| const __dirname = path.dirname(__filename); |
| |
| const compat = new FlatCompat({ |
| baseDirectory: __dirname, // optional; default: process.cwd() |
| resolvePluginsRelativeTo: __dirname, // optional |
| recommendedConfig: js.configs.recommended, // optional unless you're using "eslint:recommended" |
| allConfig: js.configs.all, // optional unless you're using "eslint:all" |
| }); |
| |
| export default [ |
| |
| // mimic ESLintRC-style extends |
| ...compat.extends("standard", "example", "plugin:react/recommended"), |
| |
| // mimic environments |
| ...compat.env({ |
| es2020: true, |
| node: true |
| }), |
| |
| // mimic plugins |
| ...compat.plugins("jsx-a11y", "react"), |
| |
| // translate an entire config |
| ...compat.config({ |
| plugins: ["jsx-a11y", "react"], |
| extends: "standard", |
| env: { |
| es2020: true, |
| node: true |
| }, |
| rules: { |
| semi: "error" |
| } |
| }) |
| ]; |
| ``` |
|
|
| ## Usage (CommonJS) |
|
|
| Using `FlatCompat` in CommonJS files is similar to ESM, but you'll use `require()` and `module.exports` instead of `import` and `export`. Here's how you use it inside of your `eslint.config.js` CommonJS file: |
|
|
| ```js |
| const { FlatCompat } = require("@eslint/eslintrc"); |
| const js = require("@eslint/js"); |
| |
| const compat = new FlatCompat({ |
| baseDirectory: __dirname, // optional; default: process.cwd() |
| resolvePluginsRelativeTo: __dirname, // optional |
| recommendedConfig: js.configs.recommended, // optional unless using "eslint:recommended" |
| allConfig: js.configs.all, // optional unless using "eslint:all" |
| }); |
| |
| module.exports = [ |
| |
| // mimic ESLintRC-style extends |
| ...compat.extends("standard", "example", "plugin:react/recommended"), |
| |
| // mimic environments |
| ...compat.env({ |
| es2020: true, |
| node: true |
| }), |
| |
| // mimic plugins |
| ...compat.plugins("jsx-a11y", "react"), |
| |
| // translate an entire config |
| ...compat.config({ |
| plugins: ["jsx-a11y", "react"], |
| extends: "standard", |
| env: { |
| es2020: true, |
| node: true |
| }, |
| rules: { |
| semi: "error" |
| } |
| }) |
| ]; |
| ``` |
|
|
| ## Troubleshooting |
|
|
| **TypeError: Missing parameter 'recommendedConfig' in FlatCompat constructor** |
|
|
| The `recommendedConfig` option is required when any config uses `eslint:recommended`, including any config in an `extends` clause. To fix this, follow the example above using `@eslint/js` to provide the `eslint:recommended` config. |
|
|
| **TypeError: Missing parameter 'allConfig' in FlatCompat constructor** |
|
|
| The `allConfig` option is required when any config uses `eslint:all`, including any config in an `extends` clause. To fix this, follow the example above using `@eslint/js` to provide the `eslint:all` config. |
|
|
| ## License |
|
|
| MIT License |
|
|
| <!-- NOTE: This section is autogenerated. Do not manually edit.--> |
| <!--sponsorsstart--> |
|
|
| ## Sponsors |
|
|
| The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://eslint.org/donate) |
| to get your logo on our READMEs and [website](https://eslint.org/sponsors). |
|
|
| <h3>Platinum Sponsors</h3> |
| <p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a></p><h3>Gold Sponsors</h3> |
| <p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a></p><h3>Silver Sponsors</h3> |
| <p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/d472863/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/2d6c3b6/logo.png" alt="Liftoff" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3> |
| <p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://opensource.sap.com"><img src="https://avatars.githubusercontent.com/u/2531208" alt="SAP" height="32"></a> <a href="https://www.crawljobs.com/"><img src="https://images.opencollective.com/crawljobs-poland/fa43a17/logo.png" alt="CrawlJobs" height="32"></a> <a href="https://depot.dev"><img src="https://images.opencollective.com/depot/39125a1/logo.png" alt="Depot" height="32"></a> <a href="https://www.n-ix.com/"><img src="https://images.opencollective.com/n-ix-ltd/575a7a5/logo.png" alt="N-iX Ltd" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="TestMu AI Open Source Office (Formerly LambdaTest)" height="32"></a></p> |
| <h3>Technology Sponsors</h3> |
| Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work. |
| <p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p> |
| <!--sponsorsend--> |
|
|