UNPKG

eslint-plugin-readable-tailwind

Version:

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

53 lines 2.16 kB
import { isAttributesMatchers, isAttributesName, isAttributesRegex } from "../utils/matchers.js"; import { deduplicateLiterals, matchesName } from "../utils/utils.js"; export function getLiteralsByHTMLAttribute(ctx, attribute, attributes) { const literals = attributes.reduce((literals, attributes) => { if (isAttributesName(attributes)) { if (!matchesName(attributes.toLowerCase(), attribute.key.value.toLowerCase())) { return literals; } literals.push(...getLiteralsByHTMLAttributeNode(ctx, attribute)); } else if (isAttributesRegex(attributes)) { // console.warn("Regex not supported in HTML"); } else if (isAttributesMatchers(attributes)) { // console.warn("Matchers not supported in HTML"); } return literals; }, []); return deduplicateLiterals(literals); } export function getAttributesByHTMLTag(ctx, node) { return node.attributes; } export function getLiteralsByHTMLAttributeNode(ctx, attribute) { const value = attribute.value; if (!value) { return []; } const raw = attribute.startWrapper?.value + value.value + attribute.endWrapper?.value; const { closingQuote, openingQuote } = getQuotesByHTMLAttribute(ctx, attribute); return [{ closingQuote, content: value.value, loc: value.loc, // @ts-expect-error - Missing in types node: attribute, openingQuote, // @ts-expect-error - Missing in types parent: attribute.parent, range: [value.range[0] - 1, value.range[1] + 1], // include quotes in range raw, type: "StringLiteral" }]; } function getQuotesByHTMLAttribute(ctx, attribute) { const openingQuote = attribute.startWrapper?.value; const closingQuote = attribute.endWrapper?.value; return { closingQuote: closingQuote === "'" || closingQuote === '"' ? closingQuote : undefined, openingQuote: openingQuote === "'" || openingQuote === '"' ? openingQuote : undefined }; } //# sourceMappingURL=html.js.map