You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

eslint-type-tracer

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-type-tracer

The type tracer for ESLint rules.

0.4.0
latest
Source
npmnpm
Version published
Weekly downloads
2.8K
217.49%
Maintainers
1
Weekly downloads
 
Created
Source

Introduction

eslint-type-tracer is the type tracer for ESLint rules.

NPM license NPM version NPM downloads NPM downloads NPM downloads NPM downloads NPM downloads Build Status

📛 Features

Trace and infer types of expression nodes for ESLint rules.

🚧 Limitations

This tool cannot always infer the complete or exact type of an expression. In particular, ESLint analyzes one file at a time, so types that are defined or imported from other files cannot be inferred. As a result, type inference is limited to what can be determined within the current file only.

💿 Installation

npm install eslint-type-tracer

Requirements

  • ESLint v8.57.0 and above
  • Node.js v14.18.0, v16.0.0 and above

📖 Usage

API

buildTypeTracer

import { buildTypeTracer } from "eslint-type-tracer";

Builds a type tracer function for use in ESLint rules. This function infers the type name of a given AST expression node.

Signature:

function buildTypeTracer(
  sourceCode: SourceCode
): (node: TSESTree.Expression) => TypeName[];
  • sourceCode: The ESLint SourceCode object.

Returns:

A function that takes an expression node and returns an array of inferred type names (e.g., ["Array"]). If the type cannot be determined, it returns an empty array []

Example:

const typeTrace = buildTypeTracer(context.sourceCode);
const typeNames = typeTrace(node);
if (typeNames.includes("Array")) {
  // node is inferred as Array
}

buildTypeChecker

import { buildTypeChecker } from "eslint-type-tracer";

Builds a type checker function for use in ESLint rules. This function helps you determine if a given AST node is of a specific type.

Signature:

function buildTypeChecker(
  sourceCode: SourceCode,
  options?: { aggressive?: boolean }
): (
  node: TSESTree.Expression,
  className: TypeName,
  memberAccessNode?: TSESTree.MemberExpression | TSESTree.Property
) => boolean | "aggressive";
  • sourceCode: The ESLint SourceCode object.
  • options.aggressive: If set to true, returns "aggressive" when the type cannot be determined. Default is false.

Returns:

A function that takes an expression node, a type name, and optionally a member access node, and returns true if the node is of the specified type, false if not, or "aggressive" if undetermined and the option is set.

Example:

const typeChecker = buildTypeChecker(context.sourceCode);
if (typeChecker(node, "Array")) {
  // node is an Array
}

🍻 Contributing

Welcome contributing!

Please use GitHub's Issues/PRs.

Development Tools

  • npm run test runs tests.

🔒 License

See the LICENSE file for license rights and limitations (MIT).

Keywords

eslint

FAQs

Package last updated on 16 Jun 2025

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