eslint-ast-utils is a utility library designed to simplify common Abstract Syntax Tree (AST) manipulations specifically for ESLint rule development. It provides helper functions to analyze AST nodes, such as identifying CommonJS `require()` calls, extracting their sources, checking for variable references within a node's scope, and safely getting property names from `MemberExpression` nodes. The current stable version is 1.1.0, released in 2017. The project appears to be in maintenance mode, with infrequent updates since its last major release. Its primary differentiation lies in providing pre-built checks for patterns frequently encountered when writing custom ESLint rules, abstracting some of the complexities of direct ESTree traversal.
npm install eslint-ast-utilsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing a JavaScript code snippet into an AST using 'espree' and then traversing the AST to identify static `require` calls and extract property names from `MemberExpression` nodes, showcasing typical use cases for `eslint-ast-utils` in an ESLint rule context.
For ESM projects, use dynamic `import()` or a CommonJS wrapper. Example: `const astUtils = await import('eslint-ast-utils');` or create a `.cjs` file to `require()` and then re-export.Thoroughly test its behavior with ASTs generated from modern JavaScript syntax. Consider alternatives or custom AST traversal logic for full support of the latest ECMAScript features or direct ESLint-provided utilities.
Refer to the documentation for `containsIdentifier` and thoroughly test scenarios with nested scopes and shadowed variables to ensure it behaves as expected for your specific rule logic. Consider using ESLint's `ScopeManager` for more robust scope analysis if needed.
In an ESM context, use a dynamic `import()`: `const astUtilsModule = await import('eslint-ast-utils'); const astUtils = astUtilsModule.default || astUtilsModule;`. Alternatively, if possible, switch the file to CommonJS (`.cjs` extension or remove `"type": "module"` from `package.json`).Import the entire module as a default object and access its properties: `import astUtils from 'eslint-ast-utils'; astUtils.isStaticRequire(node);`. For TypeScript, you might need `import astUtils = require('eslint-ast-utils');` or `import * as astUtils from 'eslint-ast-utils';` with `esModuleInterop: true`.No dependency data recorded yet.