oxlint-tailwindcss 0.1.8 → 0.1.10

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
@@ -2,6 +2,8 @@
2
2
 
3
3
  22 Tailwind CSS linting rules for [oxlint](https://oxc.rs/docs/guide/usage/linter). Built for Tailwind CSS v4 with zero-config auto-detection, typo suggestions, and autofixes.
4
4
 
5
+ Read the story behind this plugin: [oxlint-tailwindcss: The Linting Plugin Tailwind v4 Needed](https://sergioazocar.com/en/blog/oxlint-tailwindcss-the-linting-plugin-tailwind-v4-needed)
6
+
5
7
  ## Highlights
6
8
 
7
9
  - **Zero config** — Auto-detects your Tailwind CSS entry point. Works out of the box.
package/dist/index.cjs CHANGED
@@ -536,6 +536,9 @@ var DesignSystemCache = class DesignSystemCache {
536
536
  get validClasses() {
537
537
  return this._validClasses;
538
538
  }
539
+ get maxOrder() {
540
+ return this._maxOrder;
541
+ }
539
542
  canonicalize(className) {
540
543
  const cached = this.canonicalMap.get(className);
541
544
  if (cached !== void 0) return cached;
@@ -656,6 +659,11 @@ var DesignSystemCache = class DesignSystemCache {
656
659
  baseOrder = this.findOrderByPrefix(prefix);
657
660
  }
658
661
  }
662
+ if (baseOrder === void 0) {
663
+ const stripped = stripImportant(utility).bare;
664
+ const numericMatch = /^(.+)-(\d+\.?\d*)$/.exec(stripped);
665
+ if (numericMatch && this.getKnownPrefixes().has(numericMatch[1])) baseOrder = this.findOrderByPrefix(numericMatch[1] + "-");
666
+ }
659
667
  if (baseOrder === void 0) return null;
660
668
  if (!hasVariant) return baseOrder;
661
669
  const variants = extractVariants(className);
@@ -856,18 +864,93 @@ async function main() {
856
864
  if (val !== null) order[name] = val.toString();
857
865
  }
858
866
 
859
- // CSS properties per class — extract only from the class rule block, skip @property descriptors
867
+ // CSS properties per class — extract only from the ROOT selector, not descendant selectors.
868
+ // Plugin classes like "prose" generate CSS for both the root element (.prose { color: ...; })
869
+ // and descendant selectors (:where(.prose pre) { overflow-x: auto; }).
870
+ // Only root-level properties should be used for conflict detection.
860
871
  const cssProps = {};
861
872
  const atPropertyDescriptors = new Set(['syntax', 'inherits', 'initial-value']);
862
- const propRegex = /^\\s+([\\w-]+)\\s*:/gm;
863
- for (let i = 0; i < classNames.length; i++) {
864
- if (cssResults[i]) {
873
+
874
+ function extractRootCssProps(cssText, className) {
875
+ const rootProps = [];
876
+ const allProps = [];
877
+ // CSS-escape special chars in class name for selector matching
878
+ const escapedName = className.replace(/([^\\w-])/g, '\\\\$1');
879
+ const classSelector = '.' + escapedName;
880
+ const rawSelector = '.' + className;
881
+ const propRe = /^\\s+([\\w-]+)\\s*:/gm;
882
+
883
+ function isRoot(sel) {
884
+ for (const s of [classSelector, rawSelector]) {
885
+ if (sel === s) return true;
886
+ if (sel.length > s.length && sel.startsWith(s) && sel[s.length] === ':') return true;
887
+ }
888
+ return false;
889
+ }
890
+
891
+ // Extract only top-level declarations from a block body (skip nested blocks).
892
+ // For CSS nesting like .prose { color: ...; :where(a) { color: ...; } },
893
+ // only extracts "color" from the top level, not from the nested :where(a) block.
894
+ function extractTopLevelProps(body) {
865
895
  const props = [];
866
- let match;
867
- propRegex.lastIndex = 0;
868
- while ((match = propRegex.exec(cssResults[i])) !== null) {
869
- if (!atPropertyDescriptors.has(match[1])) props.push(match[1]);
896
+ let depth = 0;
897
+ let lineStart = 0;
898
+ for (let i = 0; i <= body.length; i++) {
899
+ if (i === body.length || body[i] === '\\n') {
900
+ if (depth === 0) {
901
+ const line = body.slice(lineStart, i);
902
+ const m = /^\\s+([\\w-]+)\\s*:/.exec(line);
903
+ if (m && !atPropertyDescriptors.has(m[1])) props.push(m[1]);
904
+ }
905
+ lineStart = i + 1;
906
+ } else if (body[i] === '{') {
907
+ depth++;
908
+ } else if (body[i] === '}') {
909
+ depth--;
910
+ }
870
911
  }
912
+ return props;
913
+ }
914
+
915
+ function processText(text) {
916
+ let i = 0;
917
+ while (i < text.length) {
918
+ while (i < text.length && /\\s/.test(text[i])) i++;
919
+ if (i >= text.length) break;
920
+ const braceIdx = text.indexOf('{', i);
921
+ if (braceIdx === -1) break;
922
+ const selector = text.slice(i, braceIdx).trim();
923
+ let depth = 1, j = braceIdx + 1;
924
+ while (j < text.length && depth > 0) {
925
+ if (text[j] === '{') depth++;
926
+ if (text[j] === '}') depth--;
927
+ j++;
928
+ }
929
+ const body = text.slice(braceIdx + 1, j - 1);
930
+ if (selector.startsWith('@media') || selector.startsWith('@supports') || selector.startsWith('@layer')) {
931
+ processText(body);
932
+ } else if (!selector.startsWith('@')) {
933
+ propRe.lastIndex = 0;
934
+ let m;
935
+ while ((m = propRe.exec(body)) !== null) {
936
+ if (!atPropertyDescriptors.has(m[1])) allProps.push(m[1]);
937
+ }
938
+ if (isRoot(selector)) rootProps.push(...extractTopLevelProps(body));
939
+ }
940
+ i = j;
941
+ }
942
+ }
943
+
944
+ processText(cssText);
945
+ // Use root-only properties when found; fall back to all for classes with
946
+ // escaped selectors or single-block output where root matching may miss.
947
+ const result = rootProps.length > 0 ? rootProps : allProps;
948
+ return [...new Set(result)];
949
+ }
950
+
951
+ for (let i = 0; i < classNames.length; i++) {
952
+ if (cssResults[i]) {
953
+ const props = extractRootCssProps(cssResults[i], classNames[i]);
871
954
  if (props.length > 0) cssProps[classNames[i]] = props;
872
955
  }
873
956
  }
@@ -884,6 +967,20 @@ async function main() {
884
967
  // Component classes from @layer components
885
968
  const componentClasses = extractComponentClasses(cssPath, base);
886
969
 
970
+ // Extract class names from attribute selectors [class~="..."] in CSS output.
971
+ // Plugins like @tailwindcss/typography use these for modifier classes (e.g. "not-prose")
972
+ // that don't generate their own CSS but are referenced in other classes' selectors.
973
+ const attrClassRe = /\\[class~="([^"]+)"\\]/g;
974
+ for (let i = 0; i < cssResults.length; i++) {
975
+ if (cssResults[i]) {
976
+ let acm;
977
+ attrClassRe.lastIndex = 0;
978
+ while ((acm = attrClassRe.exec(cssResults[i])) !== null) {
979
+ componentClasses.push(acm[1]);
980
+ }
981
+ }
982
+ }
983
+
887
984
  // Arbitrary equivalents: map arbitrary forms to named equivalents
888
985
  const arbitraryEquivalents = {};
889
986
  const candidates = [];
@@ -922,7 +1019,7 @@ async function main() {
922
1019
  main().catch(e => { process.stderr.write(e.message); process.exit(1); });
923
1020
  `;
924
1021
  const CACHE_DIR = (0, node_path.join)((0, node_os.tmpdir)(), "oxlint-tailwindcss");
925
- const CACHE_VERSION = 8;
1022
+ const CACHE_VERSION = 10;
926
1023
  function getCachePath(cssPath, mtime) {
927
1024
  return (0, node_path.join)(CACHE_DIR, `${(0, node_crypto.createHash)("md5").update(`v${CACHE_VERSION}:${cssPath}:${mtime}`).digest("hex")}.json`);
928
1025
  }
@@ -1514,7 +1611,7 @@ async function main() {
1514
1611
 
1515
1612
  let ds;
1516
1613
  try {
1517
- const { __unstable__loadDesignSystem } = require('@tailwindcss/node');
1614
+ const { __unstable__loadDesignSystem } = require(workerData.tailwindNodePath);
1518
1615
  const { readFileSync } = require('fs');
1519
1616
  const { dirname } = require('path');
1520
1617
  const css = readFileSync(cssPath, 'utf-8');
@@ -1573,6 +1670,7 @@ function ensureService(cssPath) {
1573
1670
  if (initialized) return available;
1574
1671
  initialized = true;
1575
1672
  try {
1673
+ const tailwindNodePath = require.resolve("@tailwindcss/node");
1576
1674
  const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
1577
1675
  controlArray = new Int32Array(sharedBuffer, 0, HEADER_INTS);
1578
1676
  lengthView = new DataView(sharedBuffer, HEADER_INTS * 4, 4);
@@ -1581,7 +1679,8 @@ function ensureService(cssPath) {
1581
1679
  eval: true,
1582
1680
  workerData: {
1583
1681
  sharedBuffer,
1584
- cssPath
1682
+ cssPath,
1683
+ tailwindNodePath
1585
1684
  }
1586
1685
  });
1587
1686
  worker.unref();
@@ -1678,10 +1777,11 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
1678
1777
  const dynamic = sortClassesSync(entryPoint, classes);
1679
1778
  if (dynamic) return dynamic;
1680
1779
  return [...cache.getClassOrder(classes)].sort((a, b) => {
1681
- const orderA = a[1] ?? 0n;
1682
- const orderB = b[1] ?? 0n;
1683
- if (orderA < orderB) return -1;
1684
- if (orderA > orderB) return 1;
1780
+ if (a[1] === null && b[1] === null) return 0;
1781
+ if (a[1] === null) return -1;
1782
+ if (b[1] === null) return 1;
1783
+ if (a[1] < b[1]) return -1;
1784
+ if (a[1] > b[1]) return 1;
1685
1785
  return 0;
1686
1786
  }).map(([name]) => name);
1687
1787
  }
@@ -1699,10 +1799,11 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
1699
1799
  for (const [, groupClasses] of groups) {
1700
1800
  const ordered = cache.getClassOrder(groupClasses);
1701
1801
  ordered.sort((a, b) => {
1702
- const orderA = a[1] ?? 0n;
1703
- const orderB = b[1] ?? 0n;
1704
- if (orderA < orderB) return -1;
1705
- if (orderA > orderB) return 1;
1802
+ if (a[1] === null && b[1] === null) return 0;
1803
+ if (a[1] === null) return -1;
1804
+ if (b[1] === null) return 1;
1805
+ if (a[1] < b[1]) return -1;
1806
+ if (a[1] > b[1]) return 1;
1706
1807
  return 0;
1707
1808
  });
1708
1809
  groupClasses.length = 0;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import * as _oxlint_plugins0 from "@oxlint/plugins";
1
+ import * as _$_oxlint_plugins0 from "@oxlint/plugins";
2
2
 
3
3
  //#region src/index.d.ts
4
- declare const plugin: _oxlint_plugins0.Plugin;
4
+ declare const plugin: _$_oxlint_plugins0.Plugin;
5
5
  export = plugin;
6
6
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAwBM,MAAA,EA0BJ,gBAAA,CA1BU,MAAA;AAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAwBM,MAAA,EA0BJ,kBAAA,CA1BU,MAAA;AAAA"}
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import * as _oxlint_plugins0 from "@oxlint/plugins";
1
+ import * as _$_oxlint_plugins0 from "@oxlint/plugins";
2
2
 
3
3
  //#region src/index.d.ts
4
- declare const plugin: _oxlint_plugins0.Plugin;
4
+ declare const plugin: _$_oxlint_plugins0.Plugin;
5
5
  //#endregion
6
6
  export { plugin as default };
7
7
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAwBM,MAAA,EA0BJ,gBAAA,CA1BU,MAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAwBM,MAAA,EA0BJ,kBAAA,CA1BU,MAAA"}
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { createRequire } from "node:module";
1
2
  import { definePlugin, defineRule } from "@oxlint/plugins";
2
3
  import { execFileSync } from "node:child_process";
3
4
  import { createHash } from "node:crypto";
@@ -5,6 +6,9 @@ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "no
5
6
  import { dirname, join, resolve } from "node:path";
6
7
  import { tmpdir } from "node:os";
7
8
  import { Worker } from "node:worker_threads";
9
+ //#region \0rolldown/runtime.js
10
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
11
+ //#endregion
8
12
  //#region src/utils/extractors.ts
9
13
  /**
10
14
  * Preserves leading/trailing spaces in fixed class strings for template literals.
@@ -536,6 +540,9 @@ var DesignSystemCache = class DesignSystemCache {
536
540
  get validClasses() {
537
541
  return this._validClasses;
538
542
  }
543
+ get maxOrder() {
544
+ return this._maxOrder;
545
+ }
539
546
  canonicalize(className) {
540
547
  const cached = this.canonicalMap.get(className);
541
548
  if (cached !== void 0) return cached;
@@ -656,6 +663,11 @@ var DesignSystemCache = class DesignSystemCache {
656
663
  baseOrder = this.findOrderByPrefix(prefix);
657
664
  }
658
665
  }
666
+ if (baseOrder === void 0) {
667
+ const stripped = stripImportant(utility).bare;
668
+ const numericMatch = /^(.+)-(\d+\.?\d*)$/.exec(stripped);
669
+ if (numericMatch && this.getKnownPrefixes().has(numericMatch[1])) baseOrder = this.findOrderByPrefix(numericMatch[1] + "-");
670
+ }
659
671
  if (baseOrder === void 0) return null;
660
672
  if (!hasVariant) return baseOrder;
661
673
  const variants = extractVariants(className);
@@ -856,18 +868,93 @@ async function main() {
856
868
  if (val !== null) order[name] = val.toString();
857
869
  }
858
870
 
859
- // CSS properties per class — extract only from the class rule block, skip @property descriptors
871
+ // CSS properties per class — extract only from the ROOT selector, not descendant selectors.
872
+ // Plugin classes like "prose" generate CSS for both the root element (.prose { color: ...; })
873
+ // and descendant selectors (:where(.prose pre) { overflow-x: auto; }).
874
+ // Only root-level properties should be used for conflict detection.
860
875
  const cssProps = {};
861
876
  const atPropertyDescriptors = new Set(['syntax', 'inherits', 'initial-value']);
862
- const propRegex = /^\\s+([\\w-]+)\\s*:/gm;
863
- for (let i = 0; i < classNames.length; i++) {
864
- if (cssResults[i]) {
877
+
878
+ function extractRootCssProps(cssText, className) {
879
+ const rootProps = [];
880
+ const allProps = [];
881
+ // CSS-escape special chars in class name for selector matching
882
+ const escapedName = className.replace(/([^\\w-])/g, '\\\\$1');
883
+ const classSelector = '.' + escapedName;
884
+ const rawSelector = '.' + className;
885
+ const propRe = /^\\s+([\\w-]+)\\s*:/gm;
886
+
887
+ function isRoot(sel) {
888
+ for (const s of [classSelector, rawSelector]) {
889
+ if (sel === s) return true;
890
+ if (sel.length > s.length && sel.startsWith(s) && sel[s.length] === ':') return true;
891
+ }
892
+ return false;
893
+ }
894
+
895
+ // Extract only top-level declarations from a block body (skip nested blocks).
896
+ // For CSS nesting like .prose { color: ...; :where(a) { color: ...; } },
897
+ // only extracts "color" from the top level, not from the nested :where(a) block.
898
+ function extractTopLevelProps(body) {
865
899
  const props = [];
866
- let match;
867
- propRegex.lastIndex = 0;
868
- while ((match = propRegex.exec(cssResults[i])) !== null) {
869
- if (!atPropertyDescriptors.has(match[1])) props.push(match[1]);
900
+ let depth = 0;
901
+ let lineStart = 0;
902
+ for (let i = 0; i <= body.length; i++) {
903
+ if (i === body.length || body[i] === '\\n') {
904
+ if (depth === 0) {
905
+ const line = body.slice(lineStart, i);
906
+ const m = /^\\s+([\\w-]+)\\s*:/.exec(line);
907
+ if (m && !atPropertyDescriptors.has(m[1])) props.push(m[1]);
908
+ }
909
+ lineStart = i + 1;
910
+ } else if (body[i] === '{') {
911
+ depth++;
912
+ } else if (body[i] === '}') {
913
+ depth--;
914
+ }
915
+ }
916
+ return props;
917
+ }
918
+
919
+ function processText(text) {
920
+ let i = 0;
921
+ while (i < text.length) {
922
+ while (i < text.length && /\\s/.test(text[i])) i++;
923
+ if (i >= text.length) break;
924
+ const braceIdx = text.indexOf('{', i);
925
+ if (braceIdx === -1) break;
926
+ const selector = text.slice(i, braceIdx).trim();
927
+ let depth = 1, j = braceIdx + 1;
928
+ while (j < text.length && depth > 0) {
929
+ if (text[j] === '{') depth++;
930
+ if (text[j] === '}') depth--;
931
+ j++;
932
+ }
933
+ const body = text.slice(braceIdx + 1, j - 1);
934
+ if (selector.startsWith('@media') || selector.startsWith('@supports') || selector.startsWith('@layer')) {
935
+ processText(body);
936
+ } else if (!selector.startsWith('@')) {
937
+ propRe.lastIndex = 0;
938
+ let m;
939
+ while ((m = propRe.exec(body)) !== null) {
940
+ if (!atPropertyDescriptors.has(m[1])) allProps.push(m[1]);
941
+ }
942
+ if (isRoot(selector)) rootProps.push(...extractTopLevelProps(body));
943
+ }
944
+ i = j;
870
945
  }
946
+ }
947
+
948
+ processText(cssText);
949
+ // Use root-only properties when found; fall back to all for classes with
950
+ // escaped selectors or single-block output where root matching may miss.
951
+ const result = rootProps.length > 0 ? rootProps : allProps;
952
+ return [...new Set(result)];
953
+ }
954
+
955
+ for (let i = 0; i < classNames.length; i++) {
956
+ if (cssResults[i]) {
957
+ const props = extractRootCssProps(cssResults[i], classNames[i]);
871
958
  if (props.length > 0) cssProps[classNames[i]] = props;
872
959
  }
873
960
  }
@@ -884,6 +971,20 @@ async function main() {
884
971
  // Component classes from @layer components
885
972
  const componentClasses = extractComponentClasses(cssPath, base);
886
973
 
974
+ // Extract class names from attribute selectors [class~="..."] in CSS output.
975
+ // Plugins like @tailwindcss/typography use these for modifier classes (e.g. "not-prose")
976
+ // that don't generate their own CSS but are referenced in other classes' selectors.
977
+ const attrClassRe = /\\[class~="([^"]+)"\\]/g;
978
+ for (let i = 0; i < cssResults.length; i++) {
979
+ if (cssResults[i]) {
980
+ let acm;
981
+ attrClassRe.lastIndex = 0;
982
+ while ((acm = attrClassRe.exec(cssResults[i])) !== null) {
983
+ componentClasses.push(acm[1]);
984
+ }
985
+ }
986
+ }
987
+
887
988
  // Arbitrary equivalents: map arbitrary forms to named equivalents
888
989
  const arbitraryEquivalents = {};
889
990
  const candidates = [];
@@ -922,7 +1023,7 @@ async function main() {
922
1023
  main().catch(e => { process.stderr.write(e.message); process.exit(1); });
923
1024
  `;
924
1025
  const CACHE_DIR = join(tmpdir(), "oxlint-tailwindcss");
925
- const CACHE_VERSION = 8;
1026
+ const CACHE_VERSION = 10;
926
1027
  function getCachePath(cssPath, mtime) {
927
1028
  return join(CACHE_DIR, `${createHash("md5").update(`v${CACHE_VERSION}:${cssPath}:${mtime}`).digest("hex")}.json`);
928
1029
  }
@@ -1514,7 +1615,7 @@ async function main() {
1514
1615
 
1515
1616
  let ds;
1516
1617
  try {
1517
- const { __unstable__loadDesignSystem } = require('@tailwindcss/node');
1618
+ const { __unstable__loadDesignSystem } = require(workerData.tailwindNodePath);
1518
1619
  const { readFileSync } = require('fs');
1519
1620
  const { dirname } = require('path');
1520
1621
  const css = readFileSync(cssPath, 'utf-8');
@@ -1573,6 +1674,7 @@ function ensureService(cssPath) {
1573
1674
  if (initialized) return available;
1574
1675
  initialized = true;
1575
1676
  try {
1677
+ const tailwindNodePath = __require.resolve("@tailwindcss/node");
1576
1678
  const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
1577
1679
  controlArray = new Int32Array(sharedBuffer, 0, HEADER_INTS);
1578
1680
  lengthView = new DataView(sharedBuffer, HEADER_INTS * 4, 4);
@@ -1581,7 +1683,8 @@ function ensureService(cssPath) {
1581
1683
  eval: true,
1582
1684
  workerData: {
1583
1685
  sharedBuffer,
1584
- cssPath
1686
+ cssPath,
1687
+ tailwindNodePath
1585
1688
  }
1586
1689
  });
1587
1690
  worker.unref();
@@ -1678,10 +1781,11 @@ const enforceSortOrder = defineRule({
1678
1781
  const dynamic = sortClassesSync(entryPoint, classes);
1679
1782
  if (dynamic) return dynamic;
1680
1783
  return [...cache.getClassOrder(classes)].sort((a, b) => {
1681
- const orderA = a[1] ?? 0n;
1682
- const orderB = b[1] ?? 0n;
1683
- if (orderA < orderB) return -1;
1684
- if (orderA > orderB) return 1;
1784
+ if (a[1] === null && b[1] === null) return 0;
1785
+ if (a[1] === null) return -1;
1786
+ if (b[1] === null) return 1;
1787
+ if (a[1] < b[1]) return -1;
1788
+ if (a[1] > b[1]) return 1;
1685
1789
  return 0;
1686
1790
  }).map(([name]) => name);
1687
1791
  }
@@ -1699,10 +1803,11 @@ const enforceSortOrder = defineRule({
1699
1803
  for (const [, groupClasses] of groups) {
1700
1804
  const ordered = cache.getClassOrder(groupClasses);
1701
1805
  ordered.sort((a, b) => {
1702
- const orderA = a[1] ?? 0n;
1703
- const orderB = b[1] ?? 0n;
1704
- if (orderA < orderB) return -1;
1705
- if (orderA > orderB) return 1;
1806
+ if (a[1] === null && b[1] === null) return 0;
1807
+ if (a[1] === null) return -1;
1808
+ if (b[1] === null) return 1;
1809
+ if (a[1] < b[1]) return -1;
1810
+ if (a[1] > b[1]) return 1;
1706
1811
  return 0;
1707
1812
  });
1708
1813
  groupClasses.length = 0;