[d565449] | 1 | # ESLintRC Library
|
---|
| 2 |
|
---|
| 3 | 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.
|
---|
| 4 |
|
---|
| 5 | **Note:** This package is frozen except for critical bug fixes as ESLint moves to a new config system.
|
---|
| 6 |
|
---|
| 7 | ## Installation
|
---|
| 8 |
|
---|
| 9 | You can install the package as follows:
|
---|
| 10 |
|
---|
| 11 | ```
|
---|
| 12 | npm install @eslint/eslintrc --save-dev
|
---|
| 13 |
|
---|
| 14 | # or
|
---|
| 15 |
|
---|
| 16 | yarn add @eslint/eslintrc -D
|
---|
| 17 | ```
|
---|
| 18 |
|
---|
| 19 | ## Usage (ESM)
|
---|
| 20 |
|
---|
| 21 | 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:
|
---|
| 22 |
|
---|
| 23 | ```js
|
---|
| 24 | import { FlatCompat } from "@eslint/eslintrc";
|
---|
| 25 | import js from "@eslint/js";
|
---|
| 26 | import path from "path";
|
---|
| 27 | import { fileURLToPath } from "url";
|
---|
| 28 |
|
---|
| 29 | // mimic CommonJS variables -- not needed if using CommonJS
|
---|
| 30 | const __filename = fileURLToPath(import.meta.url);
|
---|
| 31 | const __dirname = path.dirname(__filename);
|
---|
| 32 |
|
---|
| 33 | const compat = new FlatCompat({
|
---|
| 34 | baseDirectory: __dirname, // optional; default: process.cwd()
|
---|
| 35 | resolvePluginsRelativeTo: __dirname, // optional
|
---|
| 36 | recommendedConfig: js.configs.recommended, // optional
|
---|
| 37 | allConfig: js.configs.all, // optional
|
---|
| 38 | });
|
---|
| 39 |
|
---|
| 40 | export default [
|
---|
| 41 |
|
---|
| 42 | // mimic ESLintRC-style extends
|
---|
| 43 | ...compat.extends("standard", "example"),
|
---|
| 44 |
|
---|
| 45 | // mimic environments
|
---|
| 46 | ...compat.env({
|
---|
| 47 | es2020: true,
|
---|
| 48 | node: true
|
---|
| 49 | }),
|
---|
| 50 |
|
---|
| 51 | // mimic plugins
|
---|
| 52 | ...compat.plugins("airbnb", "react"),
|
---|
| 53 |
|
---|
| 54 | // translate an entire config
|
---|
| 55 | ...compat.config({
|
---|
| 56 | plugins: ["airbnb", "react"],
|
---|
| 57 | extends: "standard",
|
---|
| 58 | env: {
|
---|
| 59 | es2020: true,
|
---|
| 60 | node: true
|
---|
| 61 | },
|
---|
| 62 | rules: {
|
---|
| 63 | semi: "error"
|
---|
| 64 | }
|
---|
| 65 | })
|
---|
| 66 | ];
|
---|
| 67 | ```
|
---|
| 68 |
|
---|
| 69 | ## Usage (CommonJS)
|
---|
| 70 |
|
---|
| 71 | 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:
|
---|
| 72 |
|
---|
| 73 | ```js
|
---|
| 74 | const { FlatCompat } = require("@eslint/eslintrc");
|
---|
| 75 | const js = require("@eslint/js");
|
---|
| 76 |
|
---|
| 77 | const compat = new FlatCompat({
|
---|
| 78 | baseDirectory: __dirname, // optional; default: process.cwd()
|
---|
| 79 | resolvePluginsRelativeTo: __dirname, // optional
|
---|
| 80 | recommendedConfig: js.configs.recommended, // optional
|
---|
| 81 | allConfig: js.configs.all, // optional
|
---|
| 82 | });
|
---|
| 83 |
|
---|
| 84 | module.exports = [
|
---|
| 85 |
|
---|
| 86 | // mimic ESLintRC-style extends
|
---|
| 87 | ...compat.extends("standard", "example"),
|
---|
| 88 |
|
---|
| 89 | // mimic environments
|
---|
| 90 | ...compat.env({
|
---|
| 91 | es2020: true,
|
---|
| 92 | node: true
|
---|
| 93 | }),
|
---|
| 94 |
|
---|
| 95 | // mimic plugins
|
---|
| 96 | ...compat.plugins("airbnb", "react"),
|
---|
| 97 |
|
---|
| 98 | // translate an entire config
|
---|
| 99 | ...compat.config({
|
---|
| 100 | plugins: ["airbnb", "react"],
|
---|
| 101 | extends: "standard",
|
---|
| 102 | env: {
|
---|
| 103 | es2020: true,
|
---|
| 104 | node: true
|
---|
| 105 | },
|
---|
| 106 | rules: {
|
---|
| 107 | semi: "error"
|
---|
| 108 | }
|
---|
| 109 | })
|
---|
| 110 | ];
|
---|
| 111 | ```
|
---|
| 112 |
|
---|
| 113 | ## License
|
---|
| 114 |
|
---|
| 115 | MIT License
|
---|