UNPKG

eslint-plugin-readable-tailwind

Version:

auto-wraps tailwind classes after a certain print width or class count into multiple lines to improve readability.

72 lines 3 kB
import { getLiteralsByESMatchers, getLiteralsByESTemplateLiteral, getStringLiteralByESStringLiteral, isESNode, isESSimpleStringLiteral, isESTemplateLiteral } from "./es.js"; import { isAttributesMatchers, isAttributesName, isAttributesRegex } from "../utils/matchers.js"; import { getLiteralsByESNodeAndRegex } from "../utils/regex.js"; import { deduplicateLiterals, matchesName } from "../utils/utils.js"; export function getLiteralsByJSXAttribute(ctx, attribute, attributes) { const value = attribute.value; const literals = attributes.reduce((literals, attributes) => { if (!value) { return literals; } if (isAttributesName(attributes)) { if (typeof attribute.name.name !== "string" || !matchesName(attributes.toLowerCase(), attribute.name.name.toLowerCase())) { return literals; } literals.push(...getLiteralsByJSXAttributeValue(ctx, value)); } else if (isAttributesRegex(attributes)) { literals.push(...getLiteralsByESNodeAndRegex(ctx, attribute, attributes)); } else if (isAttributesMatchers(attributes)) { if (typeof attribute.name.name !== "string" || !matchesName(attributes[0].toLowerCase(), attribute.name.name.toLowerCase())) { return literals; } literals.push(...getLiteralsByESMatchers(ctx, value, attributes[1])); } return literals; }, []); return deduplicateLiterals(literals); } export function getAttributesByJSXElement(ctx, node) { return node.attributes.reduce((acc, attribute) => { if (isJSXAttribute(attribute)) { acc.push(attribute); } return acc; }, []); } function getLiteralsByJSXAttributeValue(ctx, value) { if (!value) { return []; } if (isESSimpleStringLiteral(value)) { const stringLiteral = getStringLiteralByESStringLiteral(ctx, value); if (stringLiteral) { return [stringLiteral]; } } if (isJSXExpressionContainerWithESSimpleStringLiteral(value)) { const stringLiteral = getStringLiteralByESStringLiteral(ctx, value.expression); if (stringLiteral) { return [stringLiteral]; } } if (isJSXExpressionContainerWithESTemplateLiteral(value)) { return getLiteralsByESTemplateLiteral(ctx, value.expression); } return []; } function isJSXExpressionContainerWithESSimpleStringLiteral(node) { return node.type === "JSXExpressionContainer" && "expression" in node && isESNode(node.expression) && isESSimpleStringLiteral(node.expression); } function isJSXExpressionContainerWithESTemplateLiteral(node) { return node.type === "JSXExpressionContainer" && "expression" in node && isESNode(node.expression) && isESTemplateLiteral(node.expression); } function isJSXAttribute(node) { return node.type === "JSXAttribute"; } //# sourceMappingURL=jsx.js.map