Registry / testing / enhance-visitors

enhance-visitors

JSON →
library1.0.0jsnpmunverified

A utility library (v1.0.0, last updated 2016) for merging ESLint visitor objects, enabling shared logic across multiple ESLint rules. It provides a `mergeVisitors` function that combines visitor objects so that all handlers for a given node type run in first-to-last order, with `:exit` handlers in reverse. Commonly used in ESLint plugin development to avoid duplicating common AST traversal logic (e.g., detecting a package import). Stable, but largely superseded by modern ESLint's native support for multiple visitors or `linter-utils`. The package has low maintenance and no known issues.

npm install enhance-visitors
INSTALL
IMPORT
SIG · ENHANCE-VISITORS
E
enhance-visitors
testingjavascriptv1.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

mergeVisitors
✓ import { mergeVisitors } from 'enhance-visitors'
✗ const mergeVisitors = require('enhance-visitors').mergeVisitors;
Exported as named export in a CJS-compatible module. The default export is the whole module object, but merging requires the named function.
enhance-visitors
✓ const enhance = require('enhance-visitors'); enhance.mergeVisitors([...])
✗ import enhance from 'enhance-visitors'
CommonJS library. Use `require` for full object or destructure. If using ESM, use default import (which gives the module object).
type imports (TypeScript)
✓ import { mergeVisitors } from 'enhance-visitors'
✗ import mergeVisitors from 'enhance-visitors'
No TypeScript types provided; treat as `any`. The named export is the intended usage.

Demonstrates merging a shared visitor (import detection) with a rule-specific visitor, avoiding duplicate logic.

const enhance = require('enhance-visitors'); // Shared logic: detect import of 'unicorn' function unicornSeeker(imports) { return { ImportDeclaration(node) { if (node.source.value === 'unicorn') { node.specifiers.forEach(spec => { if (spec.type === 'ImportDefaultSpecifier') { imports.unicorn = spec.local.name; } }); } } }; } // Rule that uses shared logic module.exports = function(context) { const imports = {}; return enhance.mergeVisitors([ unicornSeeker(imports), { CallExpression(node) { if ( node.callee.type === 'MemberExpression' && node.callee.object.type === 'Identifier' && node.callee.object.name === imports.unicorn ) { context.report({ node, message: 'Use unicorn with caution' }); } } } ]); };
Debug
Known issues
gotchaVisitor order for `:exit` is reversed: last-to-first instead of first-to-last.
fix
Be aware of the reverse exit order. If you need consistent ordering, consider using separate listeners or a different merging strategy.
affects: >=1.0.0
deprecatedPackage is unmaintained since 2017; no updates for ESLint 6+.
fix
Consider using ESLint's built-in rule composition or linter-utils for new projects.
affects: >=1.0.0
gotchaThe function is named `mergeVisitors` but often mistakenly called as `mergeVisitors([...])` without the array wrapper.
fix
Always pass an array: `mergeVisitors([obj1, obj2])`. If you pass multiple arguments, behavior is undefined.
affects: >=1.0.0
gotchaNo TypeScript definitions; using with TypeScript requires `@ts-ignore` or custom types.
fix
Manually declare module or use `any` type.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: enhance.mergeVisitors is not a function
Using default import in ESM incorrectly.
fix
Use `import { mergeVisitors } from 'enhance-visitors'` or `const enhance = require('enhance-visitors');`
ReferenceError: exports is not defined in ES module scope
Using `module.exports` inside an ESM file.
fix
Switch to CommonJS or use `export default` if the package supports it (it does not).
Error: Cannot find module 'enhance-visitors'
Package not installed or missing from dependencies.
fix
Run `npm install --save enhance-visitors`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
enhance-visitors — npm install enhance-visitors · libregistry