Registry / testing / eslint-utils

eslint-utils

JSON →
library3.0.0jsnpmunverified

Utility functions and classes for developing ESLint custom rules, stable version 3.0.0, released occasionally with major version bumps. Provides static evaluation on AST nodes, reference tracking for modules/globals, and helper functions like getStaticValue(), ReferenceTracker, and PatternMatcher. Differentiators: comprehensive AST utility for ESLint plugin authors, well-documented, and actively maintained by a seasoned contributor. Current version drops support for older Node.js and adds exports field.

npm install eslint-utils
INSTALL
IMPORT
SIG · ESLINT-UTILS
E
eslint-utils
testingjavascriptv3.0.0
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.

getStaticValue
import { getStaticValue } from 'eslint-utils'
const getStaticValue = require('eslint-utils').getStaticValue
ESM-only since v3; CommonJS require() fails due to exports field restriction
ReferenceTracker
import { ReferenceTracker } from 'eslint-utils'
Class for tracking references to globals/modules
PatternMatcher
import { PatternMatcher } from 'eslint-utils'
import PatternMatcher from 'eslint-utils/PatternMatcher'
Direct import of internal file paths is disallowed since v3 due to exports field

Shows usage of getStaticValue and ReferenceTracker in an ESLint rule to detect member expressions with static value 'click'.

import { getStaticValue, ReferenceTracker } from 'eslint-utils'; export default { create(context) { const tracker = new ReferenceTracker(context.getScope()); return { MemberExpression(node) { const value = getStaticValue(node, context.getScope()); if (value && value.value === 'click') { context.report({ node, message: 'Avoid using "click" as property.' }); } } }; } };
Debug
Known issues
breakingDirect access to internal files (e.g., 'eslint-utils/ast-utils') is disallowed in v3.0.0 due to the 'exports' field.
fix
Use only the package root imports as documented.
affects: >=3.0.0
breakingNode.js versions <10.0.0, 11.0.0-13.0.0 are no longer supported in v3.0.0.
fix
Upgrade Node.js to ^10.0.0 || ^12.0.0 || >=14.0.0.
affects: >=3.0.0
breakinggetFunctionNameWithKind(node) result changed in some cases in v3.0.0.
fix
Review rule logic relying on that function's output.
affects: >=3.0.0
deprecatedReferenceTracker#iterateGlobalReferences() behavior changed in v2.0.0 to recognize globalThis by default.
fix
If using globalThis tracking, adjust expectations.
affects: >=2.0.0
gotchagetStringIfConstant() fails on BigInt and RegExp literals on runtimes without BigInt support (<v1.4.1).
fix
Update to v1.4.1 or later.
affects: <1.4.1
Errors
Common errors & fixes
Cannot find module 'eslint-utils/ast-utils'
ESM-only package with exports field restricts subpath imports since v3.0.0.
fix
Import from root: import { getStaticValue } from 'eslint-utils'
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/eslint-utils/index.mjs not supported.
Package is ESM-only since v3.0.0; require() fails.
fix
Use import syntax or dynamic import(). If using CommonJS project, consider an older version.
Cannot read property 'getStaticValue' of undefined
Misunderstood that getStaticValue is exported as default or internal property.
fix
Use named import: import { getStaticValue } from 'eslint-utils'
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
eslintrequiredpeer dependency, required for using the utilities in ESLint plugin context
Agent activity
8 hits · last 30 days
node
6
Amazon
1
Resources
eslint-utils — npm install eslint-utils · libregistry