# eslint-compat-utils

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

Latest version **0.6.5** (published 2025-04-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install eslint-compat-utils
pnpm add eslint-compat-utils
yarn add eslint-compat-utils
bun add eslint-compat-utils
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.6.5 |
| Published | 2025-04-02 |
| First published | 2023-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 1 |
| Unpacked size | 53.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Yosuke Ota |
| Maintainers | ota-meshi |
| Keywords | eslint |

## Links

- npm: https://www.npmjs.com/package/eslint-compat-utils
- Repository: https://github.com/ota-meshi/eslint-compat-utils
- Homepage: https://github.com/ota-meshi/eslint-compat-utils#readme
- Issues: https://github.com/ota-meshi/eslint-compat-utils/issues
- npm.io page: https://npm.io/package/eslint-compat-utils

## Dependencies (1)

- [semver](https://npm.io/package/semver.md) ^7.5.4

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@inrupt/eslint-config-base](https://npm.io/package/@inrupt/eslint-config-base.md) — 4.5K weekly downloads

## Recent versions

- 0.6.5 (latest) — 2025-04-02
- 0.6.4 — 2024-11-28
- 0.6.3 — 2024-11-17
- 0.6.2 — 2024-11-17
- 0.6.1 — 2024-11-17
- 0.6.0 — 2024-11-05
- 0.5.1 — 2024-06-01
- 0.5.0 — 2024-03-18
- 0.4.1 — 2024-01-16
- 0.4.0 — 2024-01-16
- 0.3.3 — 2024-01-16
- 0.3.2 — 2024-01-16
- 0.3.1 — 2024-01-16
- 0.3.0 — 2024-01-16
- 0.2.1 — 2024-01-15
- … 5 more at https://npm.io/package/eslint-compat-utils/versions

## 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

```bash
npm install eslint-compat-utils
```

## Usage

```js
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.

---
_Source: https://npm.io/package/eslint-compat-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
