Registry / testing / eslint-compat-utils

eslint-compat-utils

JSON →
library0.6.5jsnpmunverified

Provides a backward-compatible API for ESLint custom rules that works with both ESLint v9 (flat config) and older ESLint versions (v6–v8). Current stable version is 0.6.5, released in 2024. The package is experimental but actively maintained with monthly patches. Key differentiator: it offers polyfills for new ESLint APIs (like getSourceCode, getScope, RuleTester shims) so rule authors can write modern code without dropping support for older ESLint installations. Ships TypeScript definitions.

npm install eslint-compat-utils
INSTALL
IMPORT
SIG · ESLINT-COMPAT-UTIL
E
eslint-compat-utils
testingjavascriptv0.6.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getSourceCode
const { getSourceCode } = require('eslint-compat-utils')
import { getSourceCode } from 'eslint-compat-utils'
Package does not ship native ESM; use CJS require or configure bundler to handle CJS. ESM support is planned but not yet implemented. Always use require().
getCwd
const { getCwd } = require('eslint-compat-utils')
const getCwd = require('eslint-compat-utils').default
No default export; import named exports only.
getFilename
const { getFilename } = require('eslint-compat-utils')
import { getFilename } from 'eslint-compat-utils'
Same as above — CJS only for now.

Shows an ESLint rule that uses getSourceCode and getFilename from eslint-compat-utils to remain compatible with ESLint v6–v9.

// eslint rule using eslint-compat-utils const { getSourceCode, getFilename } = require('eslint-compat-utils'); module.exports = { meta: { type: 'suggestion', docs: { description: 'disallow use of process.env', }, fixable: null, schema: [], }, create(context) { const sourceCode = getSourceCode(context); const filename = getFilename(context); return { MemberExpression(node) { if ( node.object.type === 'Identifier' && node.object.name === 'process' && node.property.type === 'Identifier' && node.property.name === 'env' ) { context.report({ node, message: 'Unexpected use of process.env in {{filename}}.', data: { filename }, }); } }, }; }, };
Debug
Known issues
deprecatedPackage is still experimental; API may change in minor versions.
fix
Pin to exact version or use stable alternatives like eslint-plugin-eslint-comments.
affects: >=0.0.0
breakinggetScope() and other modern source code methods may behave differently or throw on older ESLint versions.
fix
Test rules against target ESLint versions; consider using try-catch for fallback.
affects: >=0.0.0
gotchaNo ESM support – using import instead of require results in TypeError.
fix
Use CommonJS require() or set up bundler to handle CJS.
affects: >=0.0.0
gotchagetPhysicalFilename may return incorrect values for ESLint <7.28.0.
fix
Prefer getFilename() if physical filename is not critical.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'eslint-compat-utils'
Package not installed or missing from node_modules.
fix
Run: npm install eslint-compat-utils --save-dev
TypeError: eslint_compat_utils_1.getSourceCode is not a function
Trying to import ESM style with 'import', but package exports CJS only.
fix
Change to: const { getSourceCode } = require('eslint-compat-utils');
Error: eslint-compat-utils is not compatible with eslint version x.x.x
ESLint version is below 6.0.0 or above supported range.
fix
Upgrade eslint to >=6.0.0 and <10.0.0.
Upgrade
Version history
0.6.5latest on npm
Audit
Dependencies
eslintrequiredPeer dependency; requires eslint >=6.0.0
Agent activity
2 hits · last 30 days
node
2
Resources
eslint-compat-utils — npm install eslint-compat-utils · libregistry