UNPKG

eslint-plugin-readable-tailwind

Version:

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

58 lines 2.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLiteralsByHTMLAttribute = getLiteralsByHTMLAttribute; exports.getAttributesByHTMLTag = getAttributesByHTMLTag; exports.getLiteralsByHTMLAttributeNode = getLiteralsByHTMLAttributeNode; const readable_tailwind_utils_matchers_js_1 = require("../utils/matchers.js"); const readable_tailwind_utils_utils_js_1 = require("../utils/utils.js"); function getLiteralsByHTMLAttribute(ctx, attribute, attributes) { const literals = attributes.reduce((literals, attributes) => { if ((0, readable_tailwind_utils_matchers_js_1.isAttributesName)(attributes)) { if (!(0, readable_tailwind_utils_utils_js_1.matchesName)(attributes.toLowerCase(), attribute.key.value.toLowerCase())) { return literals; } literals.push(...getLiteralsByHTMLAttributeNode(ctx, attribute)); } else if ((0, readable_tailwind_utils_matchers_js_1.isAttributesRegex)(attributes)) { // console.warn("Regex not supported in HTML"); } else if ((0, readable_tailwind_utils_matchers_js_1.isAttributesMatchers)(attributes)) { // console.warn("Matchers not supported in HTML"); } return literals; }, []); return (0, readable_tailwind_utils_utils_js_1.deduplicateLiterals)(literals); } function getAttributesByHTMLTag(ctx, node) { return node.attributes; } 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