Socket
Socket
Sign inDemoInstall

eslint-visitor-keys

Package Overview
Dependencies
0
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-visitor-keys

Constants and utilities about visitor keys to traverse AST.


Version published
Maintainers
2
Weekly downloads
66,640,480
decreased by-8.11%

Weekly downloads

Package description

What is eslint-visitor-keys?

The eslint-visitor-keys package is designed to provide a list of keys that ESLint uses to visit properties in an Abstract Syntax Tree (AST). This is particularly useful for developers working on tools that need to manipulate or analyze JavaScript code, as it helps in navigating the structure of the code in a predictable manner.

What are eslint-visitor-keys's main functionalities?

Retrieving Visitor Keys

This feature allows you to retrieve a comprehensive list of visitor keys used by ESLint. These keys represent the properties of AST nodes that ESLint will traverse. The code sample demonstrates how to import and log the visitor keys.

const visitorKeys = require('eslint-visitor-keys').KEYS;
console.log(visitorKeys);

Union With Custom Keys

This feature enables the combination of ESLint's default visitor keys with custom keys defined by the user. This is useful for tools that work with custom syntax or AST nodes not covered by the default set. The code sample shows how to merge custom keys with the default ones.

const { unionWith } = require('eslint-visitor-keys');
const customKeys = { CustomNode: ['property'] };
const combinedKeys = unionWith(customKeys);
console.log(combinedKeys);

Other packages similar to eslint-visitor-keys

Readme

Source

eslint-visitor-keys

npm version Downloads/month Build Status

Constants and utilities about visitor keys to traverse AST.

💿 Installation

Use npm to install.

$ npm install eslint-visitor-keys

Requirements

  • Node.js ^12.22.0, ^14.17.0, or >=16.0.0

📖 Usage

To use in an ESM file:

import * as evk from "eslint-visitor-keys"

To use in a CommonJS file:

const evk = require("eslint-visitor-keys")

evk.KEYS

type: { [type: string]: string[] | undefined }

Visitor keys. This keys are frozen.

This is an object. Keys are the type of ESTree nodes. Their values are an array of property names which have child nodes.

For example:

console.log(evk.KEYS.AssignmentExpression) // → ["left", "right"]

evk.getKeys(node)

type: (node: object) => string[]

Get the visitor keys of a given AST node.

This is similar to Object.keys(node) of ES Standard, but some keys are excluded: parent, leadingComments, trailingComments, and names which start with _.

This will be used to traverse unknown nodes.

For example:

const node = {
    type: "AssignmentExpression",
    left: { type: "Identifier", name: "foo" },
    right: { type: "Literal", value: 0 }
}
console.log(evk.getKeys(node)) // → ["type", "left", "right"]

evk.unionWith(additionalKeys)

type: (additionalKeys: object) => { [type: string]: string[] | undefined }

Make the union set with evk.KEYS and the given keys.

  • The order of keys is, additionalKeys is at first, then evk.KEYS is concatenated after that.
  • It removes duplicated keys as keeping the first one.

For example:

console.log(evk.unionWith({
    MethodDefinition: ["decorators"]
})) // → { ..., MethodDefinition: ["decorators", "key", "value"], ... }

📰 Change log

See GitHub releases.

🍻 Contributing

Welcome. See ESLint contribution guidelines.

Development commands

  • npm test runs tests and measures code coverage.
  • npm run lint checks source codes with ESLint.
  • npm run coverage opens the code coverage report of the previous test with your default browser.
  • npm run release publishes this package to npm registory.

FAQs

Last updated on 05 May 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc