UNPKG

eslint-plugin-perfectionist

Version:

ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.

27 lines (26 loc) 980 B
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js' import { AST_NODE_TYPES } from '@typescript-eslint/utils' /** * Determines whether the given AST node is a side-effect import. * * @param props - The parameters object. * @param props.sourceCode - ESLint source code object for text extraction. * @param props.node - The AST node representing an import-like declaration. * @returns True if the node is a side-effect import; otherwise, false. */ function isSideEffectImport({ sourceCode, node }) { switch (node.type) { case AST_NODE_TYPES.TSImportEqualsDeclaration: case AST_NODE_TYPES.VariableDeclaration: return false case AST_NODE_TYPES.ImportDeclaration: return ( node.specifiers.length === 0 && !/\}\s*from\s+/u.test(sourceCode.getText(node)) ) /* v8 ignore next 2 -- @preserve Exhaustive guard. */ default: throw new UnreachableCaseError(node) } } export { isSideEffectImport }