{"id":20006,"library":"eslint-traverse","title":"eslint-traverse","description":"ESLint utility (v1.0.1) for creating sub-traversals of AST nodes within ESLint plugin rules. It provides a fast, lightweight traversal with 'SKIP' and 'STOP' controls, and a Path object containing node, parent, parentKey, and parentPath for ancestor tracking. Unlike manual recursive walks, it integrates directly with ESLint's context and offers Babel-style path objects. Minimal maintenance; last release 2018.","status":"maintenance","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/discord/eslint-traverse","tags":["javascript","eslint","es","ecmascript","lint","linter","traverse","visitor","visit"],"install":[{"cmd":"npm install eslint-traverse","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-traverse","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-traverse","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package provides ESM default export; CJS require works but is not the advertised pattern.","wrong":"const traverse = require('eslint-traverse')","symbol":"default","correct":"import traverse from 'eslint-traverse'"},{"note":"SKIP is a property on the default export, not a string literal.","wrong":"return 'skip'","symbol":"traverse.SKIP","correct":"import traverse from 'eslint-traverse'; return traverse.SKIP"},{"note":"STOP is a unique symbol; returning falsy values does not stop traversal.","wrong":"return false","symbol":"traverse.STOP","correct":"import traverse from 'eslint-traverse'; return traverse.STOP"}],"quickstart":{"code":"import traverse from 'eslint-traverse';\n\nexport default function(context) {\n  return {\n    FunctionDeclaration(node) {\n      traverse(context, node, (path) => {\n        if (path.node.type === 'FunctionDeclaration') {\n          return traverse.SKIP;\n        }\n        if (path.node.type === 'Identifier' && path.node.name === 'x') {\n          return traverse.STOP;\n        }\n        console.log(path.node.type);\n      });\n    }\n  };\n}","lang":"javascript","description":"Shows how to use traverse inside an ESLint rule, skipping child functions and stopping at 'x' identifier."},"warnings":[{"fix":"Use traverse.SKIP and traverse.STOP after importing traverse as default.","message":"traverse.SKIP and traverse.STOP are properties on the default export, not imported directly","severity":"gotcha","affected_versions":"*"},{"fix":"Check path.parent to skip root processing if needed.","message":"The traversal includes the starting node itself; the visitor is called for the root node.","severity":"gotcha","affected_versions":"*"},{"fix":"Consider forking or using eslint-plugin-query if you need newer features.","message":"Package has not been updated since 2018; may not support latest ESLint AST changes (e.g., experimental syntax).","severity":"deprecated","affected_versions":"1.0.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install --save-dev eslint-traverse`.","cause":"Missing dependency in package.json.","error":"Cannot find module 'eslint-traverse'"},{"fix":"Use `import traverse from 'eslint-traverse'` instead of `import { traverse } from 'eslint-traverse'`.","cause":"Incorrect import (named import vs default import).","error":"TypeError: traverse is not a function"},{"fix":"Import default: `import traverse from 'eslint-traverse'` and access its properties.","cause":"Using a namespace or named import instead of default import.","error":"traverse.SKIP is undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}