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 +9 -10
- package/dist/index.cjs +102 -119
- package/dist/index.mjs +104 -121
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { definePlugin, defineRule } from "@oxlint/plugins";
|
|
2
|
-
import { execFileSync
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
-
import {
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
|
+
import { Worker } from "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)
|
|
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 = defineRule({
|
|
|
1482
1486
|
//#endregion
|
|
1483
1487
|
//#region src/design-system/sort-service.ts
|
|
1484
1488
|
/**
|
|
1485
|
-
* Persistent sort service using
|
|
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
|
|
1492
|
-
*
|
|
1493
|
-
*
|
|
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
|
|
1499
|
+
* Falls back gracefully if the worker fails to initialize within the timeout.
|
|
1496
1500
|
*/
|
|
1497
|
-
const
|
|
1498
|
-
const
|
|
1499
|
-
const
|
|
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
|
|
1502
|
-
|
|
1503
|
-
const
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
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
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
const resPipe = process.env.RES_PIPE;
|
|
1528
|
+
// Signal ready
|
|
1529
|
+
Atomics.store(control, 2, 1);
|
|
1530
|
+
Atomics.notify(control, 2);
|
|
1516
1531
|
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
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
|
-
|
|
1523
|
-
|
|
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
|
-
|
|
1526
|
-
while ((req = readLine(reqFd)) !== null) {
|
|
1527
|
-
if (!req) continue;
|
|
1540
|
+
let response;
|
|
1528
1541
|
try {
|
|
1529
|
-
const classes = JSON.parse(
|
|
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
|
-
|
|
1540
|
-
writeSync(resFd, out, 0, out.length);
|
|
1552
|
+
response = Buffer.from(JSON.stringify(sorted), 'utf-8');
|
|
1541
1553
|
} catch {
|
|
1542
|
-
|
|
1543
|
-
writeSync(resFd, out, 0, out.length);
|
|
1554
|
+
response = Buffer.from('null', 'utf-8');
|
|
1544
1555
|
}
|
|
1545
|
-
}
|
|
1546
1556
|
|
|
1547
|
-
|
|
1548
|
-
|
|
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()
|
|
1564
|
+
main();
|
|
1551
1565
|
`;
|
|
1552
|
-
let
|
|
1553
|
-
let
|
|
1554
|
-
let
|
|
1555
|
-
let
|
|
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 = 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
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
RES_PIPE: resPipe
|
|
1590
|
-
},
|
|
1591
|
-
cwd: 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 Worker(WORKER_SCRIPT, {
|
|
1581
|
+
eval: true,
|
|
1582
|
+
workerData: {
|
|
1583
|
+
sharedBuffer,
|
|
1584
|
+
cssPath
|
|
1585
|
+
}
|
|
1594
1586
|
});
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
child = null;
|
|
1587
|
+
worker.unref();
|
|
1588
|
+
worker.on("error", () => {
|
|
1598
1589
|
available = false;
|
|
1590
|
+
worker = null;
|
|
1599
1591
|
});
|
|
1600
|
-
|
|
1601
|
-
|
|
1592
|
+
worker.on("exit", () => {
|
|
1593
|
+
worker = null;
|
|
1602
1594
|
});
|
|
1603
|
-
|
|
1604
|
-
|
|
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 (
|
|
1615
|
-
try {
|
|
1616
|
-
closeSync(reqFd);
|
|
1617
|
-
} catch {}
|
|
1618
|
-
reqFd = null;
|
|
1619
|
-
}
|
|
1620
|
-
if (resFd !== null) {
|
|
1609
|
+
if (worker) {
|
|
1621
1610
|
try {
|
|
1622
|
-
|
|
1611
|
+
worker.terminate();
|
|
1623
1612
|
} catch {}
|
|
1624
|
-
|
|
1625
|
-
}
|
|
1626
|
-
if (child) {
|
|
1627
|
-
try {
|
|
1628
|
-
child.kill();
|
|
1629
|
-
} catch {}
|
|
1630
|
-
child = null;
|
|
1631
|
-
}
|
|
1632
|
-
if (reqPipe) {
|
|
1633
|
-
try {
|
|
1634
|
-
unlinkSync(reqPipe);
|
|
1635
|
-
} catch {}
|
|
1636
|
-
reqPipe = null;
|
|
1637
|
-
}
|
|
1638
|
-
if (resPipe) {
|
|
1639
|
-
try {
|
|
1640
|
-
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
|
|
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 (
|
|
1622
|
+
if (!controlArray || !dataArea || !lengthView) return null;
|
|
1652
1623
|
try {
|
|
1653
|
-
const
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
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 = defineRule({
|
|
|
2284
2266
|
const enforceConsistentImportantPosition = defineRule({
|
|
2285
2267
|
meta: {
|
|
2286
2268
|
type: "suggestion",
|
|
2287
|
-
docs: { description: "Enforce consistent position of the important (!) modifier
|
|
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 = defineRule({
|
|
|
2302
2284
|
createOnce(context) {
|
|
2303
2285
|
let _position = null;
|
|
2304
2286
|
function getPosition() {
|
|
2305
|
-
if (_position === null) _position = safeOptions(context)?.position ?? "
|
|
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 = 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 = 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) {
|