Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@eslint/eslintrc

eslint127.6mMIT3.2.0TypeScript support: definitely-typed

The legacy ESLintRC config file format for ESLint

ESLint, ESLintRC, Configuration

readme

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:

npm install @eslint/eslintrc --save-dev

# or

yarn add @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:

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:

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

changelog

Changelog

3.2.0 (2024-11-14)

Features

  • merge rule.meta.defaultOptions before validation (#166) (d02f914)

3.1.0 (2024-05-17)

Features

Chores

3.0.2 (2024-02-12)

Chores

  • maintenance update of globals to v14 (#152) (4151865)

3.0.1 (2024-02-09)

Documentation

Chores

3.0.0 (2023-12-27)

⚠ BREAKING CHANGES

  • Require Node.js ^18.18.0 || ^20.9.0 || >=21.1.0 (#142)
  • Set default schema: [], drop support for function-style rules (#139)

Features

  • Require Node.js ^18.18.0 || ^20.9.0 || >=21.1.0 (#142) (737eb25)
  • Set default schema: [], drop support for function-style rules (#139) (a6c240d)

Chores

2.1.4 (2023-11-27)

Bug Fixes

  • Use original plugin from disk in FlatCompat (#137) (1c4cf6a)

2.1.3 (2023-11-01)

Documentation

Chores

2.1.2 (2023-08-05)

Bug Fixes

  • Ensure environments in overrides respect files patterns (#126) (6745421), closes #125

Chores

2.1.1 (2023-07-27)

Chores

2.1.0 (2023-06-30)

Features

Chores

2.0.3 (2023-05-05)

Chores

v2.0.2 - March 28, 2023

v2.0.1 - March 10, 2023

v2.0.0 - February 25, 2023

  • 013bdf3 feat!: Require eslint:all and eslint:recommended as parameters. (#103) (Nicholas C. Zakas)
  • f7d0f33 chore: Add triage action (#101) (Nicholas C. Zakas)

v1.4.1 - December 30, 2022

  • 5be711e fix: Update FlatCompat docs + typings to reflect Array (#99) (Wes Bos)

v1.4.0 - December 16, 2022

  • 89c504f feat: update globals (#98) (Sébastien Règne)
  • 5438c6b ci: add Node v19 (#96) (Milos Djermanovic)

v1.3.3 - October 7, 2022

  • adafd11 docs: Update README (#92) (Nicholas C. Zakas)
  • 56755d9 chore: cascading-config-array: createBaseConfigArray not expect resolver (#95) (coderaiser)

v1.3.2 - September 12, 2022

  • 2a2bef1 fix: Plugins should always use the same reference (#91) (Nicholas C. Zakas)

v1.3.1 - August 26, 2022

  • 495af93 chore: Upgrade to espree@9.4.0 (#87) (Milos Djermanovic)
  • 2632367 docs: Update README with FlatCompat options (#86) (Nicholas C. Zakas)
  • ffba0c5 ci: update github actions (#85) (Amaresh S M)
  • 9ff004e chore: add funding field (#84) (Amaresh S M)

v1.3.0 - May 20, 2022

  • aefa2a7 feat: update globals (#81) (Milos Djermanovic)

v1.2.3 - May 6, 2022

  • c9047b4 chore: Upgrade espree@9.3.2 (#80) (Milos Djermanovic)
  • baf145f chore: bump version of minimatch due to security issue PRISMA-2022-0039 (#76) (Jan Opravil)
  • 44415d3 chore: update license copyright (#79) (唯然)

v1.2.2 - April 22, 2022

  • 18b15ac fix: use custom Rollup plugin for import.meta.url (#77) (Milos Djermanovic)
  • a6e12e4 build: add node v18 (#78) (唯然)

v1.2.1 - March 11, 2022

  • 98fb12d chore: upgrade ignore to v5.2.0 (#72) (Nitin Kumar)

v1.2.0 - February 25, 2022

  • 9b71981 feat: Avoid dirname for built-in configs (#71) (DoZerg)

v1.1.0 - February 11, 2022

v1.0.5 - December 3, 2021

v1.0.4 - November 5, 2021

  • f0b528b build: upgrade eslint-release to v3.2.0 to support conventional commits (#62) (Milos Djermanovic)
  • 731fa49 chore: update js-yaml dependency (#61) (Nitin Kumar)
  • b657cea Build: add node v17 (#58) (唯然)

v1.0.3 - October 13, 2021

  • 6b5fc8b Fix: add universal export to root (#57) (Simen Bekkhus)

v1.0.2 - October 9, 2021

  • 347fe40 Build: Don't freeze Rollup output (#56) (Nicholas C. Zakas)
  • 3b8ae43 Chore: ignore package manager lock files (#55) (Nitin Kumar)

v1.0.1 - September 10, 2021

  • f2e2c33 Upgrade: espree@9.0.0 (#54) (Milos Djermanovic)
  • c5d4919 Fix: ConfigArrayFactory was ignoring the resolver option in some places (#53) (Stéphane Goetz)

v1.0.0 - August 6, 2021

  • aaf282e Update: Add /universal entrypoint (fixes #50) (#51) (Nicholas C. Zakas)
  • 3c6cfe6 Upgrade: debug@4.3.2 (#52) (Milos Djermanovic)
  • 3983fde Upgrade: Espree (fixes #41) (#49) (Nicholas C. Zakas)
  • 7e5e4e5 Update: Export environments (#46) (Nicholas C. Zakas)
  • 348e889 Chore: Use actions/setup-node@v2 (#47) (薛定谔的猫)
  • bbcef88 Breaking: drop node v10/v13/v15 (refs eslint/eslint#14023) (#37) (薛定谔的猫)
  • bdce01a Breaking: Switch to ESM (fixes #35) (#39) (Brett Zamir)

v0.4.3 - July 17, 2021

v0.4.2 - June 4, 2021

  • cc79a4d Upgrade: update globals to version 13.6 (#32) (Rouven Weßling)

v0.4.1 - May 7, 2021

  • aa38ef4 Fix: Properly export module resolver (#34) (Richie Bendall)
  • 62ea4bd Build: add node v16 (#33) (薛定谔的猫)
  • 7c43d77 Chore: add tests for built-in rules config schema validation (fixes #15) (#31) (Milos Djermanovic)
  • d8ea601 Chore: Test on Node 15.x (#30) (Milos Djermanovic)
  • 0b2f80d Chore: lint test files (#18) (Milos Djermanovic)

v0.4.0 - February 27, 2021

  • d9a527b New: Implement DotCompat class (#20) (Nicholas C. Zakas)
  • dac76c0 Chore: Replace usage of lodash with cache set (#29) (Tim van der Lippe)
  • 3ae2d77 Update: add AggregateError global to es2021 environment (#28) (Milos Djermanovic)

v0.3.0 - January 15, 2021

  • 5184490 Upgrade: lodash@4.17.20 (#24) (Milos Djermanovic)
  • f1179c5 Update: Implement missing functionality from ESLint port (fixes #12) (#23) (Nicholas C. Zakas)

v0.2.2 - December 5, 2020

  • 1746840 Fix: include loadRules in internalSlotsMap cache (#19) (Henry Q. Dineen)
  • f30bb49 Chore: Test fixes for CascadingConfigArrayFactory (#17) (Nicholas C. Zakas)
  • 4440df8 Chore: Fix config-array tests (#16) (Nicholas C. Zakas)
  • 7890e02 Chore: Test fixes for config-array-factory.js (#13) (Nicholas C. Zakas)

v0.2.1 - October 26, 2020

  • 8b202ff Fix: validate schema for built-in rules (#14) (Milos Djermanovic)
  • 04f3cae Fix: cache compiled config schema (#9) (Milos Djermanovic)

v0.2.0 - October 16, 2020

  • cb12255 Update: Allow eslint:all and eslint:recommended paths to be passed in (#11) (Nicholas C. Zakas)
  • a75bacd Chore: use GitHub Actions (#10) (Milos Djermanovic)

v0.1.3 - September 1, 2020

  • 8647a61 Fix: version number and eslint-release version (refs #6) (Nicholas C. Zakas)