mirror-rhinstaller-node-cache/eslint-compat-utils
2026-10-07 10:34:07 +00:00
..
dist a849e6d8b651bb6fdbd1e21acf1d96c0de79c64b1b3684e3b75151221afc6f4e package.json 2026-10-07 10:34:07 +00:00
node_modules a849e6d8b651bb6fdbd1e21acf1d96c0de79c64b1b3684e3b75151221afc6f4e package.json 2026-10-07 10:34:07 +00:00
LICENSE a849e6d8b651bb6fdbd1e21acf1d96c0de79c64b1b3684e3b75151221afc6f4e package.json 2026-10-07 10:34:07 +00:00
package.json a849e6d8b651bb6fdbd1e21acf1d96c0de79c64b1b3684e3b75151221afc6f4e package.json 2026-10-07 10:34:07 +00:00
README.md a849e6d8b651bb6fdbd1e21acf1d96c0de79c64b1b3684e3b75151221afc6f4e package.json 2026-10-07 10:34:07 +00:00

eslint-compat-utils

This package is still in the experimental stage.

Provides an API for ESLint custom rules that is compatible with the latest ESLint even when using older ESLint.

Installation

npm install eslint-compat-utils

Usage

const { getSourceCode } = require("eslint-compat-utils");
module.exports = {
  meta: { /* ... */ },
  create(context) {
    const sourceCode = getSourceCode(context)
    return {
      "Program"(node) {
        const scope = sourceCode.getScope(node);
      },
    };
  },
}

API

getSourceCode(context)

Returns an extended instance of context.sourceCode or the result of context.getSourceCode(). Extended instances can use new APIs such as getScope(node) even with old ESLint.

getCwd(context)

Gets the value of context.cwd, but for older ESLint it returns the result of context.getCwd(). Versions older than v6.6.0 return a value from the result of process.cwd().

getFilename(context)

Gets the value of context.filename, but for older ESLint it returns the result of context.getFilename().

getPhysicalFilename(context)

Gets the value of context.physicalFilename, but for older ESLint it returns the result of context.getPhysicalFilename(). Versions older than v7.28.0 return a value guessed from the result of context.getFilename(), but it may be incorrect.