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

Package detail

eslint-compat-utils

ota-meshi9mMIT0.6.4TypeScript support: included

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

eslint

readme

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.

changelog

eslint-compat-utils

0.6.4

Patch Changes

  • fix: wrong shim for esm (#60)

0.6.3

Patch Changes

  • fix(rule-tester): setDefaultConfig (take2) (#58)

0.6.2

Patch Changes

  • fix(rule-tester): setDefaultConfig (#56)

0.6.1

Patch Changes

  • fix(rule-tester): cannot destructure property error with eslint v8 (#54)

0.6.0

Minor Changes

  • feat: support private class fields on source code (#51)

0.5.1

Patch Changes

  • fix: resolve globals (#44)

0.5.0

Minor Changes

  • fix: support for array overrideConfig (#37)

0.4.1

Patch Changes

  • fix: getESLint (#32)

0.4.0

Minor Changes

  • feat: improve getLinter/getRuleTester (#30)

0.3.3

Patch Changes

  • fix: getRuleTester (#28)

0.3.2

Patch Changes

  • fix: getRuleTester (#24)

0.3.1

Patch Changes

  • fix: add getRuleIdPrefix (#22)

0.3.0

Minor Changes

  • feat: improve getESLint (#20)

  • feat: improve getRuleTester (#20)

0.2.1

Patch Changes

  • feat: add getLegacyESLint (#18)

0.2.0

Minor Changes

  • feat!: move getESLint to ./eslint namespace (#16)

  • feat: improve getESLint (#16)

  • feat: add getLinter (#16)

0.1.2

Patch Changes

  • fix: build target to es2019 (#11)

0.1.1

Patch Changes

  • feat: improve getESLint (#9)

0.1.0

Minor Changes

  • feat: caching getSourceCode (#7)

0.0.2

Patch Changes

  • fix: release workflow (#5)

0.0.1

Patch Changes

  • Implement eslint-compat-utils (#3)