Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-traverse

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-traverse

Create a sub-traversal of an AST node in your ESLint plugin

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

eslint-traverse

Create a sub-traversal of an AST node in your ESLint plugin

  • Very fast
  • Supports "Skipping" & "Stopping" (See below)
  • Provides AST ancestor information for every node (Babel-style "Path" object)

Install

npm install --save eslint-traverse

Example

import traverse from "eslint-traverse"

export default function(context) {
  return {
    FunctionDeclaration(node) {
      traverse(context, node, path => {
        console.log(path)
        // Path {
        //   node: Node,
        //   parent: Node | null,
        //   parentKey: string | null
        //   parentPath: Path | null
        // }

        if (path.node.type === "FunctionDeclaration") {
          return traverse.SKIP
        }
      })
    }
  }
}

Skipping

If you want to completely ignore a branch of the AST, without visiting any of its children, you can return traverse.SKIP from the visitor.

traverse(context, node, path => {
  if (path.node.type === "FunctionDeclaration") {
    return traverse.SKIP
  }
  // ...
})

Stopping

If you want to stop the traversal completely, without visiting any more nodes anywhere in the AST, you can return traversal.STOP from the visitor.

traverse(context, node, path => {
  if (path.node.type === "Identifier" && path.node.name === "THING_I_WAS_SEARCHING_FOR") {
    return traverse.STOP
  }
  // ...
})

Keywords

FAQs

Package last updated on 04 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc