UNPKG

eslint-plugin-better-tailwindcss

Version:

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

70 lines 2.47 kB
import { resolve } from "node:path"; import { withCache } from "./cache.js"; import { findFileRecursive } from "./fs.js"; import { resolveCss } from "./resolvers.js"; import { TailwindcssVersion } from "./version.js"; export const getTailwindConfigPath = ({ configPath, cwd, version }) => withCache("config-path", configPath, () => { const { major } = version; if (major >= TailwindcssVersion.V4) { const potentialPaths = [ ...configPath ? [configPath] : [] ]; const foundConfigPath = findFileRecursive(cwd, potentialPaths); const warning = getEntryPointWarning(configPath, foundConfigPath); if (foundConfigPath) { return { path: foundConfigPath, warnings: [warning] }; } const defaultConfigPath = resolveCss("tailwindcss/theme.css", cwd); if (!defaultConfigPath) { throw new Error("No default tailwind config found. Please ensure you have Tailwind CSS installed."); } return { path: defaultConfigPath, warnings: [warning] }; } if (major <= TailwindcssVersion.V3) { const potentialPaths = [ ...configPath ? [configPath] : [], "tailwind.config.js", "tailwind.config.cjs", "tailwind.config.mjs", "tailwind.config.ts" ]; const foundConfigPath = findFileRecursive(cwd, potentialPaths); const warning = getConfigPathWarning(configPath, foundConfigPath); return { path: foundConfigPath ?? "default", warnings: [warning] }; } throw new Error(`Unsupported Tailwind CSS version: ${major}. Please use a version between 3 and 4.`); }); function getConfigPathWarning(configPath, foundConfigPath) { if (!configPath) { return; } if (foundConfigPath && resolve(configPath) === resolve(foundConfigPath)) { return; } return { option: "tailwindConfig", title: `No tailwind css config found at \`${configPath}\`` }; } function getEntryPointWarning(entryPoint, foundEntryPoint) { if (!entryPoint) { return; } if (foundEntryPoint && resolve(entryPoint) === resolve(foundEntryPoint)) { return; } return { option: "entryPoint", title: `No tailwind css entry point found at \`${entryPoint}\`` }; } //# sourceMappingURL=config.js.map