{"id":19465,"library":"enhance-visitors","title":"enhance-visitors","description":"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.","status":"maintenance","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/jfmengels/enhance-visitors","tags":["javascript","eslint","plugin","eslint-plugin","eslintplugin","enhance","visitor","visitors","ast"],"install":[{"cmd":"npm install enhance-visitors","lang":"bash","label":"npm"},{"cmd":"yarn add enhance-visitors","lang":"bash","label":"yarn"},{"cmd":"pnpm add enhance-visitors","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Exported as named export in a CJS-compatible module. The default export is the whole module object, but merging requires the named function.","wrong":"const mergeVisitors = require('enhance-visitors').mergeVisitors;","symbol":"mergeVisitors","correct":"import { mergeVisitors } from 'enhance-visitors'"},{"note":"CommonJS library. Use `require` for full object or destructure. If using ESM, use default import (which gives the module object).","wrong":"import enhance from 'enhance-visitors'","symbol":"enhance-visitors","correct":"const enhance = require('enhance-visitors'); enhance.mergeVisitors([...])"},{"note":"No TypeScript types provided; treat as `any`. The named export is the intended usage.","wrong":"import mergeVisitors from 'enhance-visitors'","symbol":"type imports (TypeScript)","correct":"import { mergeVisitors } from 'enhance-visitors'"}],"quickstart":{"code":"const enhance = require('enhance-visitors');\n\n// Shared logic: detect import of 'unicorn'\nfunction unicornSeeker(imports) {\n  return {\n    ImportDeclaration(node) {\n      if (node.source.value === 'unicorn') {\n        node.specifiers.forEach(spec => {\n          if (spec.type === 'ImportDefaultSpecifier') {\n            imports.unicorn = spec.local.name;\n          }\n        });\n      }\n    }\n  };\n}\n\n// Rule that uses shared logic\nmodule.exports = function(context) {\n  const imports = {};\n\n  return enhance.mergeVisitors([\n    unicornSeeker(imports),\n    {\n      CallExpression(node) {\n        if (\n          node.callee.type === 'MemberExpression' &&\n          node.callee.object.type === 'Identifier' &&\n          node.callee.object.name === imports.unicorn\n        ) {\n          context.report({ node, message: 'Use unicorn with caution' });\n        }\n      }\n    }\n  ]);\n};","lang":"javascript","description":"Demonstrates merging a shared visitor (import detection) with a rule-specific visitor, avoiding duplicate logic."},"warnings":[{"fix":"Be aware of the reverse exit order. If you need consistent ordering, consider using separate listeners or a different merging strategy.","message":"Visitor order for `:exit` is reversed: last-to-first instead of first-to-last.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider using ESLint's built-in rule composition or linter-utils for new projects.","message":"Package is unmaintained since 2017; no updates for ESLint 6+.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Always pass an array: `mergeVisitors([obj1, obj2])`. If you pass multiple arguments, behavior is undefined.","message":"The function is named `mergeVisitors` but often mistakenly called as `mergeVisitors([...])` without the array wrapper.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Manually declare module or use `any` type.","message":"No TypeScript definitions; using with TypeScript requires `@ts-ignore` or custom types.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use `import { mergeVisitors } from 'enhance-visitors'` or `const enhance = require('enhance-visitors');`","cause":"Using default import in ESM incorrectly.","error":"TypeError: enhance.mergeVisitors is not a function"},{"fix":"Switch to CommonJS or use `export default` if the package supports it (it does not).","cause":"Using `module.exports` inside an ESM file.","error":"ReferenceError: exports is not defined in ES module scope"},{"fix":"Run `npm install --save enhance-visitors`.","cause":"Package not installed or missing from dependencies.","error":"Error: Cannot find module 'enhance-visitors'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}