eslint-plugin-perfectionist
Version:
ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
21 lines (20 loc) • 674 B
JavaScript
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
/**
* Computes the name of a JSX attribute node.
*
* @param node - The JSX attribute node.
* @returns The computed name of the JSX attribute.
*/
function computeNodeName(node) {
switch (node.name.type) {
case AST_NODE_TYPES.JSXNamespacedName:
return `${node.name.namespace.name}:${node.name.name.name}`
case AST_NODE_TYPES.JSXIdentifier:
return node.name.name
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
default:
throw new UnreachableCaseError(node.name)
}
}
export { computeNodeName }