eslint-codemod-utils
Version:
A collection of AST helper functions for more complex ESLint rule fixes.
59 lines (58 loc) • 2.05 kB
TypeScript
import * as ESTree from 'estree-jsx';
import type { StringableASTNode } from '../types';
export declare function hasJSXAttribute(node: ESTree.JSXElement, attributeName: string): boolean;
export declare function hasJSXChild(node: ESTree.JSXElement, childIdentifier: string): boolean;
/**
* Whether a declaration does or does not include a specified source.
*
* @param declaration
* @param source
* @returns
*/
export declare function hasImportDeclaration(declaration: ESTree.ImportDeclaration, source: string): boolean;
/**
*
* @param declaration
* @param specifierId
*/
export declare function hasImportSpecifier(declaration: ESTree.ImportDeclaration, importName: string | 'default'): boolean;
/**
* Appends or adds an import specifier to an existing import declaration.
*
* Does not validate whether the insertion is already present.
*
* @param declaration
* @param importName
* @param specifierAlias
* @returns {StringableASTNode<ImportDeclaration>}
*/
export declare function insertImportSpecifier(declaration: ESTree.ImportDeclaration, importName: string | 'default', specifierAlias?: string): StringableASTNode<ESTree.ImportDeclaration>;
/**
* @example
* ```tsx
* insertImportDeclaration('source', ['specifier', 'second'])
*
* // produces
* import { specifier, second } from 'source'
* ```
*
* @example
* ```tsx
* * insertImportDeclaration('source', ['specifier', { imported: 'second', local: 'other' }])
*
* // produces
* import { specifier, second as other } from 'source'
* ```
*/
export declare function insertImportDeclaration(source: string, specifiers: (string | {
local: string;
imported: string;
})[]): StringableASTNode<ESTree.ImportDeclaration>;
/**
* Removes an import specifier to an existing import declaration.
*
* @param declaration
* @param importName
* @returns {StringableASTNode<ESTree.ImportDeclaration>}
*/
export declare function removeImportSpecifier(declaration: ESTree.ImportDeclaration, importName: string | 'default'): StringableASTNode<ESTree.ImportDeclaration>;