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
Weekly downloads
64M
decreased by-8.96%
Maintainers
2
Install size
30.7 kB
Created
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

Changelog

Source

3.4.1 (2023-05-05)

Bug Fixes

  • correct types for node16 resolution (#47) (7bd1fc1)

Chores

v3.4.0 - March 27, 2023

  • e9a070f fix: remove useless sourcemap url (fixes #43) (#44) (余腾靖)
  • 0398109 chore: add triage action (#42) (Milos Djermanovic)
  • bcffbe5 ci: add Node v19 (#41) (Milos Djermanovic)
  • c24f2e4 chore: update github actions and add funding field (#40) (Deepshika S)
  • 81c0732 build: add node v18 (#39) (唯然)
  • 6ece4bd feat: add JSXSpreadChild and tool to build keys out of AST definitions (#36) (Brett Zamir)
  • 4beb7a7 docs: update badges (#37) (Milos Djermanovic)

v3.3.0 - February 11, 2022

  • 7f10327 feat: Bundle JSDoc-built TypeScript declaration file (#34) (Brett Zamir)

v3.2.0 - January 15, 2022

  • 5c53218 feat: add missing JSXOpeningFragment and JSXClosingFragment (#33) (Richard Huang)
  • 2a5c9a6 docs: readme add syntax highlighting (#32) (coderaiser)

v3.1.0 - November 8, 2021

  • 5e3e687 build: upgrade eslint-release to v3.2.0 to support conventional commits (#31) (Milos Djermanovic)
  • 53d3939 Build: add node v17 (#30) (唯然)
  • 5f5b232 Update: add StaticBlock (#29) (Milos Djermanovic)
  • e89bff9 Chore: use actions/setup-node@v2 (薛定谔的猫)
  • 7b756cd Docs: Update the minimum Node.js version requirement (#26) (0uep)

v3.0.0 - June 24, 2021

  • 701b67d Breaking: drop node v10/v13/v15 (refs eslint/eslint#14023) (#23) (薛定谔的猫)
  • f584b12 Breaking: Switch to ESM (#24) (Brett Zamir)
  • 7279e73 Build: Update branch reference in CI (#25) (Milos Djermanovic)
  • c6846d6 Upgrade: eslint-release (#21) (Nicholas C. Zakas)

v2.1.0 - May 3, 2021

  • 908fdf8 Update: add PrivateIdentifier and PropertyDefinition (#20) (Toru Nagashima)
  • 2d7be11 Chore: No longer test in Node.js 13 (#17) (Michaël De Boey)
  • b41b509 Docs: Update required Node.js version (#15) (Michaël De Boey)

v2.0.0 - August 14, 2020

  • fb86ca3 Breaking: drop support for Node <10 (#13) (Kai Cataldo)
  • 69383b3 Chore: move to GitHub Actions (#14) (Kai Cataldo)

v1.3.0 - June 19, 2020

  • c92dd7f Update: add ChainExpression node (#12) (Toru Nagashima)

v1.2.0 - June 4, 2020

  • 21f28bf Update: added exported in exportAllDeclaration key (#10) (Anix)

v1.1.0 - August 13, 2019

  • 9331cc0 Update: add ImportExpression (#8) (Toru Nagashima)
  • 5967f58 Chore: add supported Node.js versions to CI (#7) (Kai Cataldo)
  • 6f7c60f Upgrade: eslint-release@1.0.0 (#5) (Teddy Katz)

v1.0.0 - December 18, 2017

  • 1f6bd38 Breaking: update keys (#4) (Toru Nagashima)

v0.1.0 - November 17, 2017

  • 17b4a88 Chore: update repository field in package.json (#3) (Toru Nagashima)
  • a5a026b New: eslint-visitor-keys (#1) (Toru Nagashima)
  • a1a48b8 Update: Change license to Apache 2 (#2) (Ilya Volodin)
  • 2204715 Initial commit (Toru Nagashima)

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 27 Mar 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