What is @typescript-eslint/experimental-utils?
The @typescript-eslint/experimental-utils package provides various utilities for working with TypeScript and ESLint. It is part of the TypeScript ESLint project, which aims to enable ESLint to support TypeScript. The utilities in this package are considered experimental and are primarily intended for use by developers creating custom ESLint rules for TypeScript codebases.
What are @typescript-eslint/experimental-utils's main functionalities?
AST Utilities
Provides utility functions to work with Abstract Syntax Trees (AST), such as checking if a node is an identifier.
const { ASTUtils } = require('@typescript-eslint/experimental-utils');
const { isIdentifier } = ASTUtils;
ESLint Rule Creation
Facilitates the creation of custom ESLint rules with TypeScript support, including a rule creator function that helps define metadata for rules.
const { ESLintUtils } = require('@typescript-eslint/experimental-utils');
const createRule = ESLintUtils.RuleCreator(name => `https://example.com/rule/${name}`);
Type Information
Provides utilities to retrieve type information from TypeScript code, which can be used in custom ESLint rules to perform type-aware linting.
const { TypeScriptUtils } = require('@typescript-eslint/experimental-utils');
const { getParserServices } = TypeScriptUtils;
const parserServices = getParserServices(context);
const checker = parserServices.program.getTypeChecker();
Other packages similar to @typescript-eslint/experimental-utils
eslint-plugin-import
This package provides a set of ESLint rules that help validate proper imports. It is similar to @typescript-eslint/experimental-utils in that it extends ESLint's capabilities, but it focuses specifically on import/export syntax rather than providing a general set of TypeScript utilities.
eslint-utils
Similar to @typescript-eslint/experimental-utils, eslint-utils provides utility functions for working with ESLint and ASTs. However, it is not specifically tailored to TypeScript and does not provide type information utilities.
tsutils
Tsutils is a utility library that provides functions for working with TypeScript's AST and type checker. While it offers some similar functionality to @typescript-eslint/experimental-utils, it is not designed specifically for creating ESLint rules and does not integrate with ESLint out of the box.
@typescript-eslint/experimental-utils
(Experimental) Utilities for working with TypeScript + ESLint together.
Note
This package has inherited its version number from the @typescript-eslint project.
Meaning that even though this package is 1.x.y
, you shouldn't expect 100% stability between minor version bumps.
i.e. treat it as a 0.x.y
package.
Feel free to use it now, and let us know what utilities you need or send us PRs with utilities you build on top of it.
Once it is stable, it will be renamed to @typescript-eslint/util
for a 2.0.0
release.
Exports
Name | Description |
---|
[TSESTree ] | Types for the TypeScript flavour of ESTree created by @typescript-eslint/typescript-estree . |
[AST_NODE_TYPES ] | An enum with the names of every single node found in TSESTree . |
[AST_TOKEN_TYPES ] | An enum with the names of every single token found in TSESTree . |
[TSESLint ] | Types for ESLint, correctly typed to work with the types found in TSESTree . |
[ESLintUtils ] | Tools for creating eslint rules with TypeScript. |
[ESLintUtils.RuleCreator ] | A function for creating strictly typed eslint rules with TypeScript. |
[ParserServices ] | The parser services provided when parsing a file using @typescript-eslint/typescript-estree . |
AST_NODE_TYPES
AST_TOKEN_TYPES
ESLintUtils
ESLintUtils.createRule
ParserServices
TSESTree
TSESLint