UNPKG

eslint-plugin-readable-tailwind

Version:

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

86 lines 3.66 kB
import { getUnregisteredClasses } from "../tailwind/async/unregistered-classes.sync.js"; import { DEFAULT_ATTRIBUTE_NAMES, DEFAULT_CALLEE_NAMES, DEFAULT_TAG_NAMES, DEFAULT_VARIABLE_NAMES } from "../options/default-options.js"; import { ATTRIBUTE_SCHEMA, CALLEE_SCHEMA, ENTRYPOINT_SCHEMA, TAG_SCHEMA, TAILWIND_CONFIG_SCHEMA, VARIABLE_SCHEMA } from "../options/descriptions.js"; import { createRuleListener } from "../utils/rule.js"; import { augmentMessageWithWarnings, display, getCommonOptions, getExactClassLocation, splitClasses } from "../utils/utils.js"; export const DEFAULT_IGNORED_UNREGISTERED_CLASSES = [ "^group(?:\\/(\\S*))?$", "^peer(?:\\/(\\S*))?$" ]; const defaultOptions = { attributes: DEFAULT_ATTRIBUTE_NAMES, callees: DEFAULT_CALLEE_NAMES, ignore: DEFAULT_IGNORED_UNREGISTERED_CLASSES, tags: DEFAULT_TAG_NAMES, variables: DEFAULT_VARIABLE_NAMES }; const DOCUMENTATION_URL = "https://github.com/schoero/eslint-plugin-better-tailwindcss/blob/main/docs/rules/no-unregistered-classes.md"; export const tailwindNoUnregisteredClasses = { name: "no-unregistered-classes", rule: { create: ctx => createRuleListener(ctx, getOptions(ctx), lintLiterals), meta: { docs: { description: "Disallow any css classes that are not registered in tailwindcss.", recommended: false, url: DOCUMENTATION_URL }, fixable: "code", schema: [ { additionalProperties: false, properties: { ...CALLEE_SCHEMA, ...ATTRIBUTE_SCHEMA, ...VARIABLE_SCHEMA, ...TAG_SCHEMA, ...ENTRYPOINT_SCHEMA, ...TAILWIND_CONFIG_SCHEMA, ignore: { description: "A list of classes that should be ignored by the rule.", items: { type: "string" }, type: "array" } }, type: "object" } ], type: "problem" } } }; function lintLiterals(ctx, literals) { for (const literal of literals) { const { ignore, tailwindConfig } = getOptions(ctx); const classes = splitClasses(literal.content); const [unregisteredClasses, warnings] = getUnregisteredClasses({ classes, configPath: tailwindConfig, cwd: ctx.cwd }); const unregisteredClassesWarnings = warnings.map(warning => ({ ...warning, url: DOCUMENTATION_URL })); if (unregisteredClasses.length === 0) { continue; } for (const unregisteredClass of unregisteredClasses) { if (ignore.some(ignoredClass => unregisteredClass.match(ignoredClass))) { continue; } ctx.report({ data: { unregistered: display(unregisteredClass) }, loc: getExactClassLocation(literal, unregisteredClass), message: augmentMessageWithWarnings("Unregistered class detected: {{ unregistered }}", unregisteredClassesWarnings) }); } } } export function getOptions(ctx) { const options = ctx.options[0] ?? {}; const common = getCommonOptions(ctx); const ignore = options.ignore ?? defaultOptions.ignore; return { ...common, ignore }; } //# sourceMappingURL=tailwind-no-unregistered-classes.js.map