oxlint-tailwindcss 0.1.6 → 0.1.8

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
@@ -98,10 +98,7 @@ You can also override per rule if needed:
98
98
  ```jsonc
99
99
  {
100
100
  "rules": {
101
- "tailwindcss/no-unknown-classes": [
102
- "error",
103
- { "entryPoint": "src/app.css" },
104
- ],
101
+ "tailwindcss/no-unknown-classes": ["error", { "entryPoint": "src/app.css" }],
105
102
  },
106
103
  }
107
104
  ```
@@ -431,13 +428,13 @@ The inverse of `enforce-logical`. Converts logical properties back to physical o
431
428
  Enforces a consistent position for the `!` (important) modifier — either prefix or suffix.
432
429
 
433
430
  ```tsx
434
- // ❌ Bad (default: prefix)
435
- <div className="font-bold!" />
436
- <div className="hover:text-red!" />
437
-
438
- // ✅ Fixed
431
+ // ❌ Bad (default: suffix — Tailwind v4 canonical form)
439
432
  <div className="!font-bold" />
440
433
  <div className="hover:!text-red" />
434
+
435
+ // ✅ Fixed
436
+ <div className="font-bold!" />
437
+ <div className="hover:text-red!" />
441
438
  ```
442
439
 
443
440
  Handles variants correctly — the `!` is placed on the utility, not the variant prefix.
@@ -446,7 +443,9 @@ Handles variants correctly — the `!` is placed on the utility, not the variant
446
443
 
447
444
  | Option | Type | Default | Description |
448
445
  | ---------- | ------------------------ | ---------- | ------------------------------- |
449
- | `position` | `"prefix"` \| `"suffix"` | `"prefix"` | Where to place the `!` modifier |
446
+ | `position` | `"prefix"` \| `"suffix"` | `"suffix"` | Where to place the `!` modifier |
447
+
448
+ > **Note:** The default is `"suffix"` to match Tailwind CSS v4's canonical form. The prefix form (`!flex`) is deprecated in v4. Using `"prefix"` may conflict with `enforce-canonical`, which also normalizes `!` to the suffix position.
450
449
 
451
450
  **Autofix:** Moves `!` to the correct position.
452
451
 
package/dist/index.cjs CHANGED
@@ -4,6 +4,7 @@ let node_crypto = require("node:crypto");
4
4
  let node_fs = require("node:fs");
5
5
  let node_path = require("node:path");
6
6
  let node_os = require("node:os");
7
+ let node_worker_threads = require("node:worker_threads");
7
8
  //#region src/utils/extractors.ts
8
9
  /**
9
10
  * Preserves leading/trailing spaces in fixed class strings for template literals.
@@ -546,7 +547,10 @@ var DesignSystemCache = class DesignSystemCache {
546
547
  const { bare, important } = stripImportant(utility);
547
548
  if (important) {
548
549
  const canonicalBare = this.canonicalMap.get(bare);
549
- if (canonicalBare !== void 0) return className.slice(0, className.length - utility.length) + "!" + canonicalBare;
550
+ if (canonicalBare !== void 0) {
551
+ const variantPrefix = className.slice(0, className.length - utility.length);
552
+ return utility.startsWith("!") ? variantPrefix + "!" + canonicalBare : variantPrefix + canonicalBare + "!";
553
+ }
550
554
  }
551
555
  return className;
552
556
  }
@@ -1482,51 +1486,60 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
1482
1486
  //#endregion
1483
1487
  //#region src/design-system/sort-service.ts
1484
1488
  /**
1485
- * Persistent sort service using named pipes (FIFOs) for synchronous IPC.
1489
+ * Persistent sort service using worker_threads + SharedArrayBuffer.
1486
1490
  *
1487
1491
  * The problem: `ds.getClassOrder()` is the only way to get the exact official
1488
1492
  * Tailwind CSS sort order (matching oxfmt/prettier-plugin-tailwindcss), but the
1489
1493
  * design system is async to load and the oxlint plugin API is sync.
1490
1494
  *
1491
- * The solution: spawn a persistent child process that loads the DS once, then
1492
- * accepts sort requests via FIFOs. File descriptors are opened ONCE and kept
1493
- * open for the entire lint session, using newline-delimited JSON framing.
1495
+ * The solution: spawn a Worker thread that loads the DS once, then accepts sort
1496
+ * requests via SharedArrayBuffer + Atomics. The parent uses `Atomics.wait()`
1497
+ * (with timeout) for synchronous blocking without risk of infinite hangs.
1494
1498
  *
1495
- * Falls back gracefully on platforms without FIFO support (Windows).
1499
+ * Falls back gracefully if the worker fails to initialize within the timeout.
1496
1500
  */
1497
- const SORT_WORKER_SCRIPT = `
1498
- const { openSync, readSync, writeSync, closeSync } = require('fs');
1499
- const { dirname } = require('path');
1501
+ const BUFFER_SIZE = 4 * 1024 * 1024;
1502
+ const HEADER_INTS = 4;
1503
+ const DATA_OFFSET = HEADER_INTS * 4 + 4;
1504
+ const INIT_TIMEOUT = 3e4;
1505
+ const REQUEST_TIMEOUT = 1e4;
1506
+ const WORKER_SCRIPT = `
1507
+ const { workerData } = require('worker_threads');
1500
1508
 
1501
- function readLine(fd) {
1502
- let line = '';
1503
- const buf = Buffer.alloc(1);
1504
- while (true) {
1505
- const n = readSync(fd, buf, 0, 1);
1506
- if (n === 0) return null;
1507
- if (buf[0] === 10) return line;
1508
- line += String.fromCharCode(buf[0]);
1509
+ async function main() {
1510
+ const { sharedBuffer, cssPath } = workerData;
1511
+ const control = new Int32Array(sharedBuffer, 0, ${HEADER_INTS});
1512
+ const lengthView = new DataView(sharedBuffer, ${HEADER_INTS * 4}, 4);
1513
+ const dataArea = new Uint8Array(sharedBuffer, ${DATA_OFFSET});
1514
+
1515
+ let ds;
1516
+ try {
1517
+ const { __unstable__loadDesignSystem } = require('@tailwindcss/node');
1518
+ const { readFileSync } = require('fs');
1519
+ const { dirname } = require('path');
1520
+ const css = readFileSync(cssPath, 'utf-8');
1521
+ ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
1522
+ } catch {
1523
+ Atomics.store(control, 2, -1);
1524
+ Atomics.notify(control, 2);
1525
+ return;
1509
1526
  }
1510
- }
1511
1527
 
1512
- async function main() {
1513
- const cssPath = process.env.TAILWIND_CSS_PATH;
1514
- const reqPipe = process.env.REQ_PIPE;
1515
- const resPipe = process.env.RES_PIPE;
1528
+ // Signal ready
1529
+ Atomics.store(control, 2, 1);
1530
+ Atomics.notify(control, 2);
1516
1531
 
1517
- const { __unstable__loadDesignSystem } = require('@tailwindcss/node');
1518
- const { readFileSync } = require('fs');
1519
- const css = readFileSync(cssPath, 'utf-8');
1520
- const ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
1532
+ // Request loop
1533
+ while (true) {
1534
+ Atomics.wait(control, 0, 0); // wait for requestSignal !== 0
1521
1535
 
1522
- const reqFd = openSync(reqPipe, 'r');
1523
- const resFd = openSync(resPipe, 'w');
1536
+ const len = lengthView.getUint32(0);
1537
+ const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
1538
+ Atomics.store(control, 0, 0); // consume request
1524
1539
 
1525
- let req;
1526
- while ((req = readLine(reqFd)) !== null) {
1527
- if (!req) continue;
1540
+ let response;
1528
1541
  try {
1529
- const classes = JSON.parse(req);
1542
+ const classes = JSON.parse(requestStr);
1530
1543
  const ordered = ds.getClassOrder(classes);
1531
1544
  const sorted = [...ordered]
1532
1545
  .sort((a, b) => {
@@ -1536,72 +1549,54 @@ async function main() {
1536
1549
  return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0;
1537
1550
  })
1538
1551
  .map(([name]) => name);
1539
- const out = Buffer.from(JSON.stringify(sorted) + '\\n', 'utf-8');
1540
- writeSync(resFd, out, 0, out.length);
1552
+ response = Buffer.from(JSON.stringify(sorted), 'utf-8');
1541
1553
  } catch {
1542
- const out = Buffer.from('null\\n', 'utf-8');
1543
- writeSync(resFd, out, 0, out.length);
1554
+ response = Buffer.from('null', 'utf-8');
1544
1555
  }
1545
- }
1546
1556
 
1547
- closeSync(reqFd);
1548
- closeSync(resFd);
1557
+ dataArea.set(response, 0);
1558
+ lengthView.setUint32(0, response.length);
1559
+
1560
+ Atomics.store(control, 1, 1); // signal response
1561
+ Atomics.notify(control, 1);
1562
+ }
1549
1563
  }
1550
- main().catch(() => process.exit(1));
1564
+ main();
1551
1565
  `;
1552
- let child = null;
1553
- let reqPipe = null;
1554
- let resPipe = null;
1555
- let reqFd = null;
1556
- let resFd = null;
1566
+ let worker = null;
1567
+ let controlArray = null;
1568
+ let lengthView = null;
1569
+ let dataArea = null;
1557
1570
  let initialized = false;
1558
1571
  let available = true;
1559
- let readBuffer = "";
1560
- /** Read a newline-delimited line from an open file descriptor (blocking). */
1561
- function readLineSync(fd) {
1562
- while (true) {
1563
- const nlIdx = readBuffer.indexOf("\n");
1564
- if (nlIdx >= 0) {
1565
- const line = readBuffer.slice(0, nlIdx);
1566
- readBuffer = readBuffer.slice(nlIdx + 1);
1567
- return line;
1568
- }
1569
- const buf = Buffer.alloc(65536);
1570
- const n = (0, node_fs.readSync)(fd, buf, 0, buf.length, null);
1571
- if (n === 0) throw new Error("EOF");
1572
- readBuffer += buf.toString("utf-8", 0, n);
1573
- }
1574
- }
1575
1572
  function ensureService(cssPath) {
1576
1573
  if (initialized) return available;
1577
1574
  initialized = true;
1578
1575
  try {
1579
- const id = `${process.pid}-${Date.now()}`;
1580
- reqPipe = (0, node_path.join)((0, node_os.tmpdir)(), `oxlint-tw-req-${id}`);
1581
- resPipe = (0, node_path.join)((0, node_os.tmpdir)(), `oxlint-tw-res-${id}`);
1582
- (0, node_child_process.execFileSync)("mkfifo", [reqPipe]);
1583
- (0, node_child_process.execFileSync)("mkfifo", [resPipe]);
1584
- child = (0, node_child_process.spawn)(process.execPath, ["-e", SORT_WORKER_SCRIPT], {
1585
- env: {
1586
- ...process.env,
1587
- TAILWIND_CSS_PATH: cssPath,
1588
- REQ_PIPE: reqPipe,
1589
- RES_PIPE: resPipe
1590
- },
1591
- cwd: (0, node_path.dirname)(cssPath),
1592
- stdio: "ignore",
1593
- detached: false
1576
+ const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
1577
+ controlArray = new Int32Array(sharedBuffer, 0, HEADER_INTS);
1578
+ lengthView = new DataView(sharedBuffer, HEADER_INTS * 4, 4);
1579
+ dataArea = new Uint8Array(sharedBuffer, DATA_OFFSET);
1580
+ worker = new node_worker_threads.Worker(WORKER_SCRIPT, {
1581
+ eval: true,
1582
+ workerData: {
1583
+ sharedBuffer,
1584
+ cssPath
1585
+ }
1594
1586
  });
1595
- child.unref();
1596
- child.on("error", () => {
1597
- child = null;
1587
+ worker.unref();
1588
+ worker.on("error", () => {
1598
1589
  available = false;
1590
+ worker = null;
1599
1591
  });
1600
- child.on("exit", () => {
1601
- child = null;
1592
+ worker.on("exit", () => {
1593
+ worker = null;
1602
1594
  });
1603
- reqFd = (0, node_fs.openSync)(reqPipe, "w");
1604
- resFd = (0, node_fs.openSync)(resPipe, "r");
1595
+ if (Atomics.wait(controlArray, 2, 0, INIT_TIMEOUT) === "timed-out" || controlArray[2] === -1) {
1596
+ available = false;
1597
+ cleanup();
1598
+ return false;
1599
+ }
1605
1600
  process.on("exit", cleanup);
1606
1601
  return true;
1607
1602
  } catch {
@@ -1611,49 +1606,36 @@ function ensureService(cssPath) {
1611
1606
  }
1612
1607
  }
1613
1608
  function cleanup() {
1614
- if (reqFd !== null) {
1615
- try {
1616
- (0, node_fs.closeSync)(reqFd);
1617
- } catch {}
1618
- reqFd = null;
1619
- }
1620
- if (resFd !== null) {
1609
+ if (worker) {
1621
1610
  try {
1622
- (0, node_fs.closeSync)(resFd);
1611
+ worker.terminate();
1623
1612
  } catch {}
1624
- resFd = null;
1625
- }
1626
- if (child) {
1627
- try {
1628
- child.kill();
1629
- } catch {}
1630
- child = null;
1631
- }
1632
- if (reqPipe) {
1633
- try {
1634
- (0, node_fs.unlinkSync)(reqPipe);
1635
- } catch {}
1636
- reqPipe = null;
1637
- }
1638
- if (resPipe) {
1639
- try {
1640
- (0, node_fs.unlinkSync)(resPipe);
1641
- } catch {}
1642
- resPipe = null;
1613
+ worker = null;
1643
1614
  }
1644
1615
  }
1645
1616
  /**
1646
- * Sort classes using the official Tailwind CSS sort order via persistent child process.
1617
+ * Sort classes using the official Tailwind CSS sort order via worker thread.
1647
1618
  * Returns the sorted class array, or null if the service is unavailable.
1648
1619
  */
1649
1620
  function sortClassesSync(cssPath, classes) {
1650
1621
  if (!ensureService(cssPath)) return null;
1651
- if (reqFd === null || resFd === null) return null;
1622
+ if (!controlArray || !dataArea || !lengthView) return null;
1652
1623
  try {
1653
- const payload = Buffer.from(JSON.stringify(classes) + "\n", "utf-8");
1654
- (0, node_fs.writeSync)(reqFd, payload, 0, payload.length);
1655
- const line = readLineSync(resFd);
1656
- return JSON.parse(line);
1624
+ const request = Buffer.from(JSON.stringify(classes), "utf-8");
1625
+ if (request.length > BUFFER_SIZE - DATA_OFFSET) return null;
1626
+ dataArea.set(request, 0);
1627
+ lengthView.setUint32(0, request.length);
1628
+ Atomics.store(controlArray, 0, 1);
1629
+ Atomics.notify(controlArray, 0);
1630
+ if (Atomics.wait(controlArray, 1, 0, REQUEST_TIMEOUT) === "timed-out") {
1631
+ available = false;
1632
+ cleanup();
1633
+ return null;
1634
+ }
1635
+ const responseLen = lengthView.getUint32(0);
1636
+ const responseStr = Buffer.from(dataArea.slice(0, responseLen)).toString("utf-8");
1637
+ Atomics.store(controlArray, 1, 0);
1638
+ return JSON.parse(responseStr);
1657
1639
  } catch {
1658
1640
  available = false;
1659
1641
  cleanup();
@@ -2284,7 +2266,7 @@ const noArbitraryValue = (0, _oxlint_plugins.defineRule)({
2284
2266
  const enforceConsistentImportantPosition = (0, _oxlint_plugins.defineRule)({
2285
2267
  meta: {
2286
2268
  type: "suggestion",
2287
- docs: { description: "Enforce consistent position of the important (!) modifier in Tailwind CSS classes" },
2269
+ docs: { description: "Enforce consistent position of the important (!) modifier. Default: suffix (Tailwind v4 canonical form). Note: using \"prefix\" may conflict with enforce-canonical which normalizes to suffix." },
2288
2270
  fixable: "code",
2289
2271
  schema: [{
2290
2272
  type: "object",
@@ -2302,7 +2284,7 @@ const enforceConsistentImportantPosition = (0, _oxlint_plugins.defineRule)({
2302
2284
  createOnce(context) {
2303
2285
  let _position = null;
2304
2286
  function getPosition() {
2305
- if (_position === null) _position = safeOptions(context)?.position ?? "prefix";
2287
+ if (_position === null) _position = safeOptions(context)?.position ?? "suffix";
2306
2288
  return _position;
2307
2289
  }
2308
2290
  function fixUtility(utility, variantPfx) {
@@ -2850,6 +2832,8 @@ const noContradictingVariants = (0, _oxlint_plugins.defineRule)({
2850
2832
  //#endregion
2851
2833
  //#region src/rules/consistent-variant-order.ts
2852
2834
  const DEFAULT_VARIANT_ORDER = [
2835
+ "*",
2836
+ "**",
2853
2837
  "sm",
2854
2838
  "md",
2855
2839
  "lg",
@@ -2982,7 +2966,6 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
2982
2966
  const dsPriority = dsCache.getVariantPriority(variant);
2983
2967
  if (dsPriority !== null) return dsPriority;
2984
2968
  }
2985
- if (variant.startsWith("[")) return -1;
2986
2969
  return fallbackPriority;
2987
2970
  }
2988
2971
  function reorderClass(cls) {