oxlint-tailwindcss 1.14.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -78,6 +78,10 @@ A missing or wrong entry point is reported once per file as `designSystemUnavail
78
78
  fix; a misspelt setting as `invalidSetting`. [Setup](https://oxlint-tailwindcss.pages.dev/setup) has
79
79
  the recommended set, and how to map each package of a monorepo to its own CSS.
80
80
 
81
+ In an `oxlint.config.ts`, or in a shared config published as a package, `oxlint-tailwindcss/config`
82
+ registers the plugin by its own path, with the recommended rules, for `extends`:
83
+ [`oxlint.config.ts` and shared configs](https://oxlint-tailwindcss.pages.dev/setup#with-oxlint-config-ts-or-in-a-shared-config).
84
+
81
85
  ## Rules
82
86
 
83
87
  <!-- generated:rule-table -->
@@ -0,0 +1,84 @@
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ let node_url = require("node:url");
6
+ //#region src/recommended.ts
7
+ /**
8
+ * The recommended rules at their severities: what `oxlint-tailwindcss/config`
9
+ * turns on. A static map, so the config entry never loads the plugin itself;
10
+ * `tests/config/recommended.test.ts` holds it equal to each rule's
11
+ * `meta.docs.recommended`.
12
+ */
13
+ const RECOMMENDED_RULES = {
14
+ "tailwindcss/consistent-variant-order": "warn",
15
+ "tailwindcss/enforce-canonical": "warn",
16
+ "tailwindcss/enforce-consistent-important-position": "warn",
17
+ "tailwindcss/enforce-consistent-variable-syntax": "warn",
18
+ "tailwindcss/enforce-negative-arbitrary-values": "warn",
19
+ "tailwindcss/enforce-shorthand": "warn",
20
+ "tailwindcss/enforce-sort-order": "warn",
21
+ "tailwindcss/no-conflicting-classes": "error",
22
+ "tailwindcss/no-contradicting-variants": "warn",
23
+ "tailwindcss/no-dark-without-light": "warn",
24
+ "tailwindcss/no-deprecated-classes": "error",
25
+ "tailwindcss/no-duplicate-classes": "warn",
26
+ "tailwindcss/no-dynamic-classes": "error",
27
+ "tailwindcss/no-hardcoded-colors": "warn",
28
+ "tailwindcss/no-unknown-classes": "error",
29
+ "tailwindcss/no-unnecessary-arbitrary-value": "warn",
30
+ "tailwindcss/no-unnecessary-whitespace": "warn"
31
+ };
32
+ //#endregion
33
+ //#region src/config.ts
34
+ /**
35
+ * `oxlint-tailwindcss/config`: the plugin and its recommended rules as an
36
+ * oxlint config object, for `extends` in an `oxlint.config.ts` and in the
37
+ * shared configs that compose it (#218).
38
+ *
39
+ * import tailwindcss from 'oxlint-tailwindcss/config'
40
+ * export default defineConfig({
41
+ * extends: [tailwindcss()],
42
+ * settings: { tailwindcss: { entryPoint: 'src/styles.css' } },
43
+ * })
44
+ *
45
+ * A config that reaches oxlint through `extends` can't register its JS plugin
46
+ * by package name: oxlint resolves `"oxlint-tailwindcss"` from the project,
47
+ * where a shared config's own dependency isn't installed under pnpm, and it
48
+ * rejects a relative specifier there outright. This module knows where the
49
+ * plugin is — its sibling `index.mjs`, the file the bare name resolves to, so
50
+ * a project that also lists the name registers the same plugin — and hands
51
+ * oxlint that absolute path.
52
+ *
53
+ * It carries no settings, on purpose: oxlint never takes `settings` from an
54
+ * extended config (JSON or TS), so an `entryPoint` passed through here would be
55
+ * dropped in silence. The settings stay in the config that is linted with.
56
+ *
57
+ * It imports nothing at runtime from the plugin: the entry stays a few lines,
58
+ * the build keeps `dist/index.cjs` a single `module.exports = plugin`, and the
59
+ * recommended severities come from a static map a test holds equal to the
60
+ * rules' own metadata.
61
+ */
62
+ /** The plugin this config registers: the file a bare `"oxlint-tailwindcss"` resolves to. */
63
+ const PLUGIN_PATH = (0, node_url.fileURLToPath)(new URL("./index.mjs", require("url").pathToFileURL(__filename).href));
64
+ const OPTIONS = /* @__PURE__ */ new Set(["recommended"]);
65
+ /**
66
+ * The plugin and, unless `recommended: false`, the recommended rules. Throws
67
+ * on anything else: a setting such as `entryPoint` would be dropped by oxlint
68
+ * on its way through `extends`, and every rule that needs it would then report
69
+ * a missing entry point on every file, far from the line that caused it.
70
+ */
71
+ function tailwindcss(options = {}) {
72
+ if (typeof options !== "object" || options === null) throw new TypeError("oxlint-tailwindcss/config: tailwindcss() takes an options object.");
73
+ for (const key of Object.keys(options)) {
74
+ if (OPTIONS.has(key)) continue;
75
+ throw new TypeError(`oxlint-tailwindcss/config: unknown option "${key}". Settings such as \`entryPoint\` don't reach oxlint through \`extends\` — set them in your own config's \`settings.tailwindcss\`. See https://oxlint-tailwindcss.pages.dev/setup`);
76
+ }
77
+ return {
78
+ jsPlugins: [PLUGIN_PATH],
79
+ rules: options.recommended === false ? {} : { ...RECOMMENDED_RULES }
80
+ };
81
+ }
82
+ //#endregion
83
+ exports.default = tailwindcss;
84
+ exports.tailwindcss = tailwindcss;
@@ -0,0 +1,114 @@
1
+ //#region src/types.d.ts
2
+ interface ExtractorExclusions {
3
+ /** Default attribute names to exclude */
4
+ attributes?: string[];
5
+ /** Default callee names to exclude */
6
+ callees?: string[];
7
+ /** Default tag names to exclude */
8
+ tags?: string[];
9
+ /** Default variable pattern regex sources to exclude (matched against RegExp.source) */
10
+ variablePatterns?: string[];
11
+ }
12
+ /**
13
+ * One mapping in a monorepo `entryPoint` array. `files` is a glob (or array of
14
+ * globs) matched relative to the oxlint working directory; `use` is the CSS
15
+ * entry point to load for files matching that glob. Array order is the
16
+ * evaluation order — first match wins.
17
+ */
18
+ interface EntryPointMapping {
19
+ files: string | string[];
20
+ use: string;
21
+ }
22
+ /**
23
+ * The structured extractor a custom callee should be routed through
24
+ * (`settings.tailwindcss.calleeExtractors`). `tv`/`cva`/`classed` reuse the
25
+ * dedicated extractors that understand each helper's config shape; `flat` is
26
+ * the generic cn/clsx/twMerge-style extraction (every string argument plus
27
+ * object keys) — the same behaviour every plain `callees` entry already gets.
28
+ */
29
+ type CalleeExtractorKind = 'tv' | 'cva' | 'classed' | 'flat';
30
+ interface PluginSettings {
31
+ /**
32
+ * CSS entry point. Required in v1.0.0+ for any DS-dependent rule to run.
33
+ *
34
+ * - `string` — single CSS path for the whole project.
35
+ * - `EntryPointMapping[]` — monorepo mapping, evaluated in order; the
36
+ * first glob matching the linted file decides which CSS to load.
37
+ *
38
+ * The legacy `string[]` shape was removed in v1; it now triggers a fatal
39
+ * `DeprecatedEntryPointShapeError` with migration instructions.
40
+ */
41
+ entryPoint?: string | EntryPointMapping[];
42
+ /** Enable debug logging to stderr (also activable via DEBUG=oxlint-tailwindcss env var) */
43
+ debug?: boolean;
44
+ /**
45
+ * Run even when the resolved Tailwind engine is a major version newer than
46
+ * the one this plugin was built for (e.g. a future Tailwind 5), or drifts a
47
+ * major from the version your build uses. Off by default: those cases are
48
+ * fatal (`designSystemUnavailable`) because the plugin's results may not
49
+ * match your compiled CSS. Setting this to `true` downgrades them to a
50
+ * one-time stderr warning and lints best-effort. An engine older than v4.1.15 is
51
+ * never allowed — it stays fatal regardless of this flag.
52
+ */
53
+ allowUntestedEngine?: boolean;
54
+ /**
55
+ * Root font size in pixels for px→named conversion (default: 16). Used by
56
+ * enforce-canonical and prefer-scale-token.
57
+ */
58
+ rootFontSize?: number;
59
+ /** Timeout in milliseconds for design system loading (default: 60000) */
60
+ timeout?: number;
61
+ /** Additional JSX attribute names to scan for Tailwind classes (added to defaults) */
62
+ attributes?: string[];
63
+ /**
64
+ * Regex patterns (as strings) matched against JSX attribute NAMES, additive to
65
+ * the exact `attributes` list. Lets `*ClassName` conventions (React Native /
66
+ * Uniwind, component libraries) be scanned without listing every prop, e.g.
67
+ * `["ClassName$"]`. Note: `variablePatterns` matches variable declaration
68
+ * names only, NOT JSX attributes — use this for attributes.
69
+ */
70
+ attributePatterns?: string[];
71
+ /** Additional function names to scan for Tailwind classes (added to defaults) */
72
+ callees?: string[];
73
+ /**
74
+ * Route a custom callee through a known structured extractor by mapping its
75
+ * local name to `'tv' | 'cva' | 'classed' | 'flat'`. Lets a wrapper
76
+ * re-exported under another name (e.g. `defineStyles = createTV(config)`) be
77
+ * linted with the same deep extraction as `tv()` — without renaming imports
78
+ * at every call site (#155). Keys are auto-registered as callees (no need to
79
+ * also list them in `callees`); an unknown value is skipped rather than
80
+ * throwing, and the reserved names `tv`/`cva`/`classed` cannot be remapped
81
+ * (the built-in extractor wins). `'flat'` is the default cn/clsx-style
82
+ * extraction, offered so every custom callee can live in one map.
83
+ */
84
+ calleeExtractors?: Record<string, CalleeExtractorKind>;
85
+ /** Additional tagged template tag names to scan (added to defaults) */
86
+ tags?: string[];
87
+ /** Additional regex patterns (as strings) for variable names to scan (added to defaults) */
88
+ variablePatterns?: string[];
89
+ /** Remove specific items from the built-in defaults */
90
+ exclude?: ExtractorExclusions;
91
+ }
92
+ //#endregion
93
+ //#region src/config.d.ts
94
+ export type TailwindcssConfigOptions = {
95
+ /**
96
+ * Turn on the recommended rules at their severities (default `true`).
97
+ * `false` registers the plugin only, for a config that picks its own rules.
98
+ */
99
+ recommended?: boolean;
100
+ };
101
+ /** An oxlint config object for `extends`: the plugin and its rules. */
102
+ export type TailwindcssConfig = {
103
+ jsPlugins: string[];
104
+ rules: Record<string, 'error' | 'warn'>;
105
+ };
106
+ /**
107
+ * The plugin and, unless `recommended: false`, the recommended rules. Throws
108
+ * on anything else: a setting such as `entryPoint` would be dropped by oxlint
109
+ * on its way through `extends`, and every rule that needs it would then report
110
+ * a missing entry point on every file, far from the line that caused it.
111
+ */
112
+ export declare function tailwindcss(options?: TailwindcssConfigOptions): TailwindcssConfig;
113
+ //#endregion
114
+ export { type CalleeExtractorKind, type EntryPointMapping, type ExtractorExclusions, type PluginSettings, tailwindcss as default };
@@ -0,0 +1,114 @@
1
+ //#region src/types.d.ts
2
+ interface ExtractorExclusions {
3
+ /** Default attribute names to exclude */
4
+ attributes?: string[];
5
+ /** Default callee names to exclude */
6
+ callees?: string[];
7
+ /** Default tag names to exclude */
8
+ tags?: string[];
9
+ /** Default variable pattern regex sources to exclude (matched against RegExp.source) */
10
+ variablePatterns?: string[];
11
+ }
12
+ /**
13
+ * One mapping in a monorepo `entryPoint` array. `files` is a glob (or array of
14
+ * globs) matched relative to the oxlint working directory; `use` is the CSS
15
+ * entry point to load for files matching that glob. Array order is the
16
+ * evaluation order — first match wins.
17
+ */
18
+ interface EntryPointMapping {
19
+ files: string | string[];
20
+ use: string;
21
+ }
22
+ /**
23
+ * The structured extractor a custom callee should be routed through
24
+ * (`settings.tailwindcss.calleeExtractors`). `tv`/`cva`/`classed` reuse the
25
+ * dedicated extractors that understand each helper's config shape; `flat` is
26
+ * the generic cn/clsx/twMerge-style extraction (every string argument plus
27
+ * object keys) — the same behaviour every plain `callees` entry already gets.
28
+ */
29
+ type CalleeExtractorKind = 'tv' | 'cva' | 'classed' | 'flat';
30
+ interface PluginSettings {
31
+ /**
32
+ * CSS entry point. Required in v1.0.0+ for any DS-dependent rule to run.
33
+ *
34
+ * - `string` — single CSS path for the whole project.
35
+ * - `EntryPointMapping[]` — monorepo mapping, evaluated in order; the
36
+ * first glob matching the linted file decides which CSS to load.
37
+ *
38
+ * The legacy `string[]` shape was removed in v1; it now triggers a fatal
39
+ * `DeprecatedEntryPointShapeError` with migration instructions.
40
+ */
41
+ entryPoint?: string | EntryPointMapping[];
42
+ /** Enable debug logging to stderr (also activable via DEBUG=oxlint-tailwindcss env var) */
43
+ debug?: boolean;
44
+ /**
45
+ * Run even when the resolved Tailwind engine is a major version newer than
46
+ * the one this plugin was built for (e.g. a future Tailwind 5), or drifts a
47
+ * major from the version your build uses. Off by default: those cases are
48
+ * fatal (`designSystemUnavailable`) because the plugin's results may not
49
+ * match your compiled CSS. Setting this to `true` downgrades them to a
50
+ * one-time stderr warning and lints best-effort. An engine older than v4.1.15 is
51
+ * never allowed — it stays fatal regardless of this flag.
52
+ */
53
+ allowUntestedEngine?: boolean;
54
+ /**
55
+ * Root font size in pixels for px→named conversion (default: 16). Used by
56
+ * enforce-canonical and prefer-scale-token.
57
+ */
58
+ rootFontSize?: number;
59
+ /** Timeout in milliseconds for design system loading (default: 60000) */
60
+ timeout?: number;
61
+ /** Additional JSX attribute names to scan for Tailwind classes (added to defaults) */
62
+ attributes?: string[];
63
+ /**
64
+ * Regex patterns (as strings) matched against JSX attribute NAMES, additive to
65
+ * the exact `attributes` list. Lets `*ClassName` conventions (React Native /
66
+ * Uniwind, component libraries) be scanned without listing every prop, e.g.
67
+ * `["ClassName$"]`. Note: `variablePatterns` matches variable declaration
68
+ * names only, NOT JSX attributes — use this for attributes.
69
+ */
70
+ attributePatterns?: string[];
71
+ /** Additional function names to scan for Tailwind classes (added to defaults) */
72
+ callees?: string[];
73
+ /**
74
+ * Route a custom callee through a known structured extractor by mapping its
75
+ * local name to `'tv' | 'cva' | 'classed' | 'flat'`. Lets a wrapper
76
+ * re-exported under another name (e.g. `defineStyles = createTV(config)`) be
77
+ * linted with the same deep extraction as `tv()` — without renaming imports
78
+ * at every call site (#155). Keys are auto-registered as callees (no need to
79
+ * also list them in `callees`); an unknown value is skipped rather than
80
+ * throwing, and the reserved names `tv`/`cva`/`classed` cannot be remapped
81
+ * (the built-in extractor wins). `'flat'` is the default cn/clsx-style
82
+ * extraction, offered so every custom callee can live in one map.
83
+ */
84
+ calleeExtractors?: Record<string, CalleeExtractorKind>;
85
+ /** Additional tagged template tag names to scan (added to defaults) */
86
+ tags?: string[];
87
+ /** Additional regex patterns (as strings) for variable names to scan (added to defaults) */
88
+ variablePatterns?: string[];
89
+ /** Remove specific items from the built-in defaults */
90
+ exclude?: ExtractorExclusions;
91
+ }
92
+ //#endregion
93
+ //#region src/config.d.ts
94
+ export type TailwindcssConfigOptions = {
95
+ /**
96
+ * Turn on the recommended rules at their severities (default `true`).
97
+ * `false` registers the plugin only, for a config that picks its own rules.
98
+ */
99
+ recommended?: boolean;
100
+ };
101
+ /** An oxlint config object for `extends`: the plugin and its rules. */
102
+ export type TailwindcssConfig = {
103
+ jsPlugins: string[];
104
+ rules: Record<string, 'error' | 'warn'>;
105
+ };
106
+ /**
107
+ * The plugin and, unless `recommended: false`, the recommended rules. Throws
108
+ * on anything else: a setting such as `entryPoint` would be dropped by oxlint
109
+ * on its way through `extends`, and every rule that needs it would then report
110
+ * a missing entry point on every file, far from the line that caused it.
111
+ */
112
+ export declare function tailwindcss(options?: TailwindcssConfigOptions): TailwindcssConfig;
113
+ //#endregion
114
+ export { type CalleeExtractorKind, type EntryPointMapping, type ExtractorExclusions, type PluginSettings, tailwindcss as default };
@@ -0,0 +1,79 @@
1
+ import { fileURLToPath } from "node:url";
2
+ //#region src/recommended.ts
3
+ /**
4
+ * The recommended rules at their severities: what `oxlint-tailwindcss/config`
5
+ * turns on. A static map, so the config entry never loads the plugin itself;
6
+ * `tests/config/recommended.test.ts` holds it equal to each rule's
7
+ * `meta.docs.recommended`.
8
+ */
9
+ const RECOMMENDED_RULES = {
10
+ "tailwindcss/consistent-variant-order": "warn",
11
+ "tailwindcss/enforce-canonical": "warn",
12
+ "tailwindcss/enforce-consistent-important-position": "warn",
13
+ "tailwindcss/enforce-consistent-variable-syntax": "warn",
14
+ "tailwindcss/enforce-negative-arbitrary-values": "warn",
15
+ "tailwindcss/enforce-shorthand": "warn",
16
+ "tailwindcss/enforce-sort-order": "warn",
17
+ "tailwindcss/no-conflicting-classes": "error",
18
+ "tailwindcss/no-contradicting-variants": "warn",
19
+ "tailwindcss/no-dark-without-light": "warn",
20
+ "tailwindcss/no-deprecated-classes": "error",
21
+ "tailwindcss/no-duplicate-classes": "warn",
22
+ "tailwindcss/no-dynamic-classes": "error",
23
+ "tailwindcss/no-hardcoded-colors": "warn",
24
+ "tailwindcss/no-unknown-classes": "error",
25
+ "tailwindcss/no-unnecessary-arbitrary-value": "warn",
26
+ "tailwindcss/no-unnecessary-whitespace": "warn"
27
+ };
28
+ //#endregion
29
+ //#region src/config.ts
30
+ /**
31
+ * `oxlint-tailwindcss/config`: the plugin and its recommended rules as an
32
+ * oxlint config object, for `extends` in an `oxlint.config.ts` and in the
33
+ * shared configs that compose it (#218).
34
+ *
35
+ * import tailwindcss from 'oxlint-tailwindcss/config'
36
+ * export default defineConfig({
37
+ * extends: [tailwindcss()],
38
+ * settings: { tailwindcss: { entryPoint: 'src/styles.css' } },
39
+ * })
40
+ *
41
+ * A config that reaches oxlint through `extends` can't register its JS plugin
42
+ * by package name: oxlint resolves `"oxlint-tailwindcss"` from the project,
43
+ * where a shared config's own dependency isn't installed under pnpm, and it
44
+ * rejects a relative specifier there outright. This module knows where the
45
+ * plugin is — its sibling `index.mjs`, the file the bare name resolves to, so
46
+ * a project that also lists the name registers the same plugin — and hands
47
+ * oxlint that absolute path.
48
+ *
49
+ * It carries no settings, on purpose: oxlint never takes `settings` from an
50
+ * extended config (JSON or TS), so an `entryPoint` passed through here would be
51
+ * dropped in silence. The settings stay in the config that is linted with.
52
+ *
53
+ * It imports nothing at runtime from the plugin: the entry stays a few lines,
54
+ * the build keeps `dist/index.cjs` a single `module.exports = plugin`, and the
55
+ * recommended severities come from a static map a test holds equal to the
56
+ * rules' own metadata.
57
+ */
58
+ /** The plugin this config registers: the file a bare `"oxlint-tailwindcss"` resolves to. */
59
+ const PLUGIN_PATH = fileURLToPath(new URL("./index.mjs", import.meta.url));
60
+ const OPTIONS = /* @__PURE__ */ new Set(["recommended"]);
61
+ /**
62
+ * The plugin and, unless `recommended: false`, the recommended rules. Throws
63
+ * on anything else: a setting such as `entryPoint` would be dropped by oxlint
64
+ * on its way through `extends`, and every rule that needs it would then report
65
+ * a missing entry point on every file, far from the line that caused it.
66
+ */
67
+ function tailwindcss(options = {}) {
68
+ if (typeof options !== "object" || options === null) throw new TypeError("oxlint-tailwindcss/config: tailwindcss() takes an options object.");
69
+ for (const key of Object.keys(options)) {
70
+ if (OPTIONS.has(key)) continue;
71
+ throw new TypeError(`oxlint-tailwindcss/config: unknown option "${key}". Settings such as \`entryPoint\` don't reach oxlint through \`extends\` — set them in your own config's \`settings.tailwindcss\`. See https://oxlint-tailwindcss.pages.dev/setup`);
72
+ }
73
+ return {
74
+ jsPlugins: [PLUGIN_PATH],
75
+ rules: options.recommended === false ? {} : { ...RECOMMENDED_RULES }
76
+ };
77
+ }
78
+ //#endregion
79
+ export { tailwindcss as default, tailwindcss };