UNPKG

eslint-plugin-svelte-tailwindcss

Version:
112 lines (105 loc) 3.69 kB
import { Rule, ESLint, Linter } from 'eslint'; /** * Intended usage: * * ```javascript * // eslint.config.js * export default [{ * settings: { * tailwindcss: { * // These are the default values but feel free to customize * callees: ["classnames", "clsx", "ctl"], * config: "tailwind.config.js", * cssFiles: [ * "**\/*.css", * "!**\/node_modules", * "!**\/.*", * "!**\/dist", * "!**\/build", * ], * cssFilesRefreshRate: 5_000, * removeDuplicates: true, * skipClassAttribute: false, * whitelist: [], * tags: [], * ignoredKeys: ['compoundVariants', 'defaultVariants'], * classRegex: undefined, * }, * }, * }]; * ``` */ type SVTPluginConfiguration = { /** * Names of the functions that are called such as `clsx` or `twMerge`` */ callees?: string[]; /** * Can be modified to support custom attributes. E.g. "^tw$" for `twin.macro` */ classRegex?: string; skipClassAttribute?: boolean; /** * TODO: Implement TaggedExpression * Can be set to e.g. ['tw'] for use in tw`bg-blue` */ tags?: string[]; whitelist?: string[]; /** * Returned from `loadConfig()` utility if not provided */ config?: string; /** * Possible prefixes, suffixes and names that will be used to check if a * variable declaration should be evaluated. For example, if you use an * object to store variants, and you want the properties of that object to be * evaluated, you should define the object name/prefix/suffix here. This is * done so that the plugin can skip most of the declarations with literals * that are no relevant. Also works for function and arrow function * declarations. */ declarations?: { names?: string[]; prefix?: string[]; suffix?: string[]; }; ignoredKeys?: string[]; /** * If set to true, in order to find the tailwind config file, the plugin will * traverse up the directory tree until it finds a valid tailwind config * file. This will ignore the `config` option, for simplicity. * The check will be done always upwards, at folder level, without digging * into each nested folder. * * Important to note that the traverse will go as high to as * [`RuleContext#cwd`](https://github.com/typescript-eslint/typescript-eslint/blob/c1b1106da2807646c6579ddad2c8452db78eb9c6/packages/utils/src/ts-eslint/Rule.ts#L262-L266) */ monorepo?: boolean; /** * If set to `true`, the plugin will remove duplicate classes from the final * class attribute. */ removeDuplicates?: boolean; }; type SVTPluginOptions = Partial<SVTPluginConfiguration>; type SVTRuleModule<T extends readonly Partial<SVTPluginConfiguration>[]> = { defaultOptions: T; } & Rule.RuleModule; type OptionList = Options[]; type Options = Pick<SVTPluginOptions, 'callees' | 'config' | 'declarations' | 'ignoredKeys' | 'monorepo' | 'removeDuplicates' | 'tags'>; declare const _default: { 'at-apply-require-postcss': SVTRuleModule<[]>; 'no-literal-mustache-mix': SVTRuleModule<[]>; 'sort-classes': SVTRuleModule<OptionList>; }; declare const plugin: ESLint.Plugin; type PluginSettings = SVTPluginConfiguration; type RuleOptions = { [K in keyof RuleDefinitions]: RuleDefinitions[K]['defaultOptions']; }; type Rules = { [K in keyof RuleDefinitions]: Linter.RuleEntry<RuleOptions[K]>; }; type RuleDefinitions = typeof _default; export { plugin as default }; export type { PluginSettings, RuleOptions, Rules };