UNPKG

eslint-plugin-readable-tailwind

Version:

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

73 lines 2.71 kB
import { DEFAULT_ATTRIBUTE_NAMES, DEFAULT_CALLEE_NAMES, DEFAULT_TAG_NAMES, DEFAULT_VARIABLE_NAMES } from "../options/default-options.js"; import { ATTRIBUTE_SCHEMA, CALLEE_SCHEMA, TAG_SCHEMA, VARIABLE_SCHEMA } from "../options/descriptions.js"; import { createRuleListener } from "../utils/rule.js"; import { getCommonOptions, getExactClassLocation, splitClasses } from "../utils/utils.js"; const defaultOptions = { attributes: DEFAULT_ATTRIBUTE_NAMES, callees: DEFAULT_CALLEE_NAMES, restrict: [], tags: DEFAULT_TAG_NAMES, variables: DEFAULT_VARIABLE_NAMES }; const DOCUMENTATION_URL = "https://github.com/schoero/eslint-plugin-better-tailwindcss/blob/main/docs/rules/no-restricted-classes.md"; export const noRestrictedClasses = { name: "no-restricted-classes", rule: { create: ctx => createRuleListener(ctx, getOptions(ctx), lintLiterals), meta: { docs: { description: "Disallow restricted classes.", recommended: false, url: DOCUMENTATION_URL }, schema: [ { additionalProperties: false, properties: { ...CALLEE_SCHEMA, ...ATTRIBUTE_SCHEMA, ...VARIABLE_SCHEMA, ...TAG_SCHEMA, restrict: { items: { type: "string" }, type: "array" } }, type: "object" } ], type: "problem" } } }; function lintLiterals(ctx, literals) { const { restrict: restrictions } = getOptions(ctx); for (const literal of literals) { const classes = literal.content; const classNames = splitClasses(classes); const restrict = classNames.filter(className => { return restrictions.some(restriction => className.match(restriction)); }); for (const restrictedClass of restrict) { ctx.report({ data: { restrictedClass }, loc: getExactClassLocation(literal, restrictedClass), message: "Restricted class: \"{{ restrictedClass }}\"." }); } } } export function getOptions(ctx) { const options = ctx.options[0] ?? {}; const common = getCommonOptions(ctx); const restrict = options.restrict ?? defaultOptions.restrict; return { ...common, restrict }; } //# sourceMappingURL=no-restricted-classes.js.map