@shayanthenerd/eslint-config
Version:
A modern, flexible ESLint configuration for enforcing best practices and maintaining a consistent coding style
80 lines (79 loc) • 2.91 kB
JavaScript
import { isTruthy } from "../utils/isTruthy.mjs";
import { globs } from "../helpers/globs.mjs";
import { isEnabled } from "../utils/isEnabled.mjs";
import { defaultOptions } from "../helpers/options/defaultOptions.mjs";
import { getTailwindRules } from "../rules/tailwind.mjs";
import { mergeConfigs } from "eslint-flat-config-utils";
import path from "node:path";
import eslintPluginTailwind from "eslint-plugin-better-tailwindcss";
import { getDefaultSelectors } from "eslint-plugin-better-tailwindcss/defaults";
import { MatcherType, SelectorKind } from "eslint-plugin-better-tailwindcss/types";
//#region src/configs/tailwind.ts
const astroAttributes = {
kind: SelectorKind.Attribute,
name: "^class:list$",
match: [{ type: MatcherType.String }, { type: MatcherType.ObjectKey }]
};
const vueAttributes = {
kind: SelectorKind.Attribute,
name: "^(?:v-bind:)?(exactActiveClass|activeClass|inactiveClass|active-class|inactive-class)$",
match: [{ type: MatcherType.String }, { type: MatcherType.ObjectKey }]
};
const nuxtUiAttributes = {
kind: SelectorKind.Attribute,
name: "^v-bind:ui$",
match: [{ type: MatcherType.ObjectValue }]
};
const nuxtUiAppConfigClassPathPattern = [
"ui\\.",
"(?!(?:colors|icons)(?:\\.|\\[|$))",
"(?!.*\\.defaultVariants(?:\\.|\\[|$))",
"(?!.*\\.compoundVariants\\[\\d+\\]\\.(?!(?:class|className)(?:\\.|\\[|$))[^.\\[]+(?:\\.|\\[|$))",
".+"
].join("");
const nuxtUiAppConfigUiFields = {
kind: SelectorKind.Callee,
name: "^defineAppConfig$",
match: [{
type: MatcherType.ObjectValue,
path: `^${nuxtUiAppConfigClassPathPattern}$`
}, {
type: MatcherType.AnonymousFunctionReturn,
match: [{ type: MatcherType.String }, { type: MatcherType.ObjectKey }]
}]
};
function getTailwindConfig(options) {
const { tsConfig, configs: { vue, nuxt, html, astro, tailwind } } = options;
const { cwd, config, overrides, entryPoint } = isEnabled(tailwind) ? tailwind : defaultOptions.configs.tailwind;
const tsconfigPath = tsConfig ? path.resolve(tsConfig.rootDir, tsConfig.filename) : void 0;
const isNuxtUiEnabled = isEnabled(nuxt) && isEnabled(nuxt.ui);
const selectors = [
...getDefaultSelectors(),
isEnabled(astro) ? astroAttributes : void 0,
isEnabled(vue) ? vueAttributes : void 0,
isNuxtUiEnabled ? nuxtUiAttributes : void 0,
isNuxtUiEnabled ? nuxtUiAppConfigUiFields : void 0
].filter(isTruthy);
return mergeConfigs({
name: "shayanthenerd/tailwind",
files: [
globs.src,
globs.jsxTsx,
isEnabled(vue) ? globs.vue : "",
isEnabled(html) ? globs.html : "",
isEnabled(astro) ? globs.astro : ""
].filter(isTruthy),
plugins: { "better-tailwindcss": eslintPluginTailwind },
settings: { "better-tailwindcss": {
cwd,
selectors,
entryPoint,
tailwindConfig: config,
tsconfig: tsconfigPath,
detectComponentClasses: true
} },
rules: getTailwindRules(options)
}, overrides);
}
//#endregion
export { getTailwindConfig };