oxlint-tailwindcss 0.4.1 → 0.6.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 +75 -4
- package/dist/index.cjs +471 -40
- package/dist/index.mjs +605 -178
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -1269,21 +1269,86 @@ function autoDetectEntryPoint(filePath) {
|
|
|
1269
1269
|
return null;
|
|
1270
1270
|
}
|
|
1271
1271
|
//#endregion
|
|
1272
|
+
//#region src/design-system/debug.ts
|
|
1273
|
+
const PREFIX = "[oxlint-tailwindcss]";
|
|
1274
|
+
let _enabled = null;
|
|
1275
|
+
/**
|
|
1276
|
+
* Check if debug logging is enabled.
|
|
1277
|
+
* Activated by `settings.tailwindcss.debug: true` or `DEBUG=oxlint-tailwindcss` env var.
|
|
1278
|
+
*/
|
|
1279
|
+
function isDebugEnabled(settings) {
|
|
1280
|
+
if (process.env.DEBUG === "oxlint-tailwindcss") return true;
|
|
1281
|
+
if (settings !== void 0) {
|
|
1282
|
+
const tw = settings?.tailwindcss;
|
|
1283
|
+
if (tw && typeof tw === "object" && "debug" in tw) return tw.debug === true;
|
|
1284
|
+
}
|
|
1285
|
+
return false;
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Enable debug mode (called once when settings become available).
|
|
1289
|
+
*/
|
|
1290
|
+
function setDebugEnabled(enabled) {
|
|
1291
|
+
_enabled = enabled;
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Log a debug message if debug mode is active.
|
|
1295
|
+
*/
|
|
1296
|
+
function debugLog(message) {
|
|
1297
|
+
if (_enabled || process.env.DEBUG === "oxlint-tailwindcss") console.error(`${PREFIX} ${message}`);
|
|
1298
|
+
}
|
|
1299
|
+
//#endregion
|
|
1272
1300
|
//#region src/design-system/loader.ts
|
|
1273
1301
|
const dsCache = /* @__PURE__ */ new Map();
|
|
1274
1302
|
const autoDetectCache = /* @__PURE__ */ new Map();
|
|
1275
1303
|
let lastLoadedPath = null;
|
|
1276
1304
|
/**
|
|
1277
1305
|
* Extracts `entryPoint` from `context.settings.tailwindcss`.
|
|
1306
|
+
* Supports both `string` and `string[]` (for monorepos).
|
|
1278
1307
|
*/
|
|
1279
1308
|
function entryPointFromSettings(settings) {
|
|
1280
1309
|
const tw = settings?.tailwindcss;
|
|
1281
1310
|
if (tw && typeof tw === "object" && "entryPoint" in tw) {
|
|
1282
1311
|
const ep = tw.entryPoint;
|
|
1283
1312
|
if (typeof ep === "string") return ep;
|
|
1313
|
+
if (Array.isArray(ep) && ep.length > 0 && ep.every((e) => typeof e === "string")) return ep;
|
|
1284
1314
|
}
|
|
1285
1315
|
}
|
|
1286
1316
|
/**
|
|
1317
|
+
* Given an array of entry points and a file path, pick the one that shares
|
|
1318
|
+
* the longest common directory prefix with the file. Falls back to first entry.
|
|
1319
|
+
*/
|
|
1320
|
+
function resolveClosestEntryPoint(entryPoints, filePath) {
|
|
1321
|
+
if (entryPoints.length === 1 || !filePath) return entryPoints[0];
|
|
1322
|
+
const fileDir = (0, node_path.dirname)((0, node_path.resolve)(filePath));
|
|
1323
|
+
let best = entryPoints[0];
|
|
1324
|
+
let bestLen = 0;
|
|
1325
|
+
for (const ep of entryPoints) {
|
|
1326
|
+
const len = commonPrefixLength(fileDir, (0, node_path.dirname)((0, node_path.resolve)(ep)));
|
|
1327
|
+
if (len > bestLen) {
|
|
1328
|
+
bestLen = len;
|
|
1329
|
+
best = ep;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
return best;
|
|
1333
|
+
}
|
|
1334
|
+
function commonPrefixLength(a, b) {
|
|
1335
|
+
const len = Math.min(a.length, b.length);
|
|
1336
|
+
let i = 0;
|
|
1337
|
+
while (i < len && a[i] === b[i]) i++;
|
|
1338
|
+
return i;
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* Extracts `rootFontSize` from `context.settings.tailwindcss` (default: 16).
|
|
1342
|
+
*/
|
|
1343
|
+
function rootFontSizeFromSettings(settings) {
|
|
1344
|
+
const tw = settings?.tailwindcss;
|
|
1345
|
+
if (tw && typeof tw === "object" && "rootFontSize" in tw) {
|
|
1346
|
+
const v = tw.rootFontSize;
|
|
1347
|
+
if (typeof v === "number" && v > 0) return v;
|
|
1348
|
+
}
|
|
1349
|
+
return 16;
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1287
1352
|
* Extracts `timeout` from `context.settings.tailwindcss`.
|
|
1288
1353
|
*/
|
|
1289
1354
|
function timeoutFromSettings(settings) {
|
|
@@ -1317,7 +1382,8 @@ function cachedAutoDetect(filePath) {
|
|
|
1317
1382
|
* Resolution order: rule option `entryPoint` > `settings.tailwindcss.entryPoint` > auto-detect.
|
|
1318
1383
|
*/
|
|
1319
1384
|
function getLoadedDesignSystem(entryPoint, settings, filePath) {
|
|
1320
|
-
const
|
|
1385
|
+
const settingsEntry = entryPointFromSettings(settings);
|
|
1386
|
+
const explicitEntry = entryPoint ?? (Array.isArray(settingsEntry) ? resolveClosestEntryPoint(settingsEntry, filePath) : settingsEntry);
|
|
1321
1387
|
const cssPath = explicitEntry ?? cachedAutoDetect(filePath) ?? lastLoadedPath;
|
|
1322
1388
|
if (!cssPath) return null;
|
|
1323
1389
|
const resolvedPath = (0, node_path.resolve)(cssPath);
|
|
@@ -1338,7 +1404,7 @@ function getLoadedDesignSystem(entryPoint, settings, filePath) {
|
|
|
1338
1404
|
cache,
|
|
1339
1405
|
mtime
|
|
1340
1406
|
});
|
|
1341
|
-
|
|
1407
|
+
debugLog(`Loaded design system from "${resolvedPath}"`);
|
|
1342
1408
|
if (explicitEntry) lastLoadedPath = resolvedPath;
|
|
1343
1409
|
return {
|
|
1344
1410
|
cache,
|
|
@@ -1363,6 +1429,7 @@ function createLazyLoader(context) {
|
|
|
1363
1429
|
let lastResult = null;
|
|
1364
1430
|
let fixedEntryResolved = false;
|
|
1365
1431
|
let fixedResult = null;
|
|
1432
|
+
let debugInitialized = false;
|
|
1366
1433
|
return () => {
|
|
1367
1434
|
let entryPoint;
|
|
1368
1435
|
try {
|
|
@@ -1376,16 +1443,31 @@ function createLazyLoader(context) {
|
|
|
1376
1443
|
try {
|
|
1377
1444
|
filePath = context.filename;
|
|
1378
1445
|
} catch {}
|
|
1379
|
-
|
|
1446
|
+
if (!debugInitialized && settings) {
|
|
1447
|
+
debugInitialized = true;
|
|
1448
|
+
setDebugEnabled(isDebugEnabled(settings));
|
|
1449
|
+
}
|
|
1450
|
+
const settingsEntry = entryPointFromSettings(settings);
|
|
1451
|
+
const fixedEntry = entryPoint ?? (typeof settingsEntry === "string" ? settingsEntry : void 0);
|
|
1380
1452
|
if (fixedEntry) {
|
|
1381
1453
|
if (fixedEntryResolved) return fixedResult;
|
|
1382
1454
|
fixedEntryResolved = true;
|
|
1383
1455
|
fixedResult = getLoadedDesignSystem(fixedEntry, settings, filePath);
|
|
1456
|
+
if (fixedResult && filePath) debugLog(`${(0, node_path.relative)(process.cwd(), filePath)} → ${(0, node_path.relative)(process.cwd(), fixedResult.entryPoint)}`);
|
|
1384
1457
|
return fixedResult;
|
|
1385
1458
|
}
|
|
1459
|
+
if (Array.isArray(settingsEntry)) {
|
|
1460
|
+
const closest = resolveClosestEntryPoint(settingsEntry, filePath);
|
|
1461
|
+
if (filePath && filePath === lastFilePath) return lastResult;
|
|
1462
|
+
if (filePath) lastFilePath = filePath;
|
|
1463
|
+
lastResult = getLoadedDesignSystem(closest, settings, filePath);
|
|
1464
|
+
if (lastResult && filePath) debugLog(`${(0, node_path.relative)(process.cwd(), filePath)} → ${(0, node_path.relative)(process.cwd(), lastResult.entryPoint)}`);
|
|
1465
|
+
return lastResult;
|
|
1466
|
+
}
|
|
1386
1467
|
if (filePath && filePath === lastFilePath) return lastResult;
|
|
1387
1468
|
if (filePath) lastFilePath = filePath;
|
|
1388
1469
|
lastResult = getLoadedDesignSystem(void 0, settings, filePath);
|
|
1470
|
+
if (lastResult && filePath) debugLog(`${(0, node_path.relative)(process.cwd(), filePath)} → ${(0, node_path.relative)(process.cwd(), lastResult.entryPoint)}`);
|
|
1389
1471
|
return lastResult;
|
|
1390
1472
|
};
|
|
1391
1473
|
}
|
|
@@ -1407,6 +1489,19 @@ function safeOptions(context) {
|
|
|
1407
1489
|
return;
|
|
1408
1490
|
}
|
|
1409
1491
|
}
|
|
1492
|
+
/**
|
|
1493
|
+
* Safely read context.settings.
|
|
1494
|
+
*
|
|
1495
|
+
* Like `safeOptions`, `context.settings` may not be accessible in `createOnce()`.
|
|
1496
|
+
* The try/catch handles that gracefully.
|
|
1497
|
+
*/
|
|
1498
|
+
function safeSettings(context) {
|
|
1499
|
+
try {
|
|
1500
|
+
return context.settings ?? void 0;
|
|
1501
|
+
} catch {
|
|
1502
|
+
return;
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1410
1505
|
//#endregion
|
|
1411
1506
|
//#region src/rules/no-deprecated-classes.ts
|
|
1412
1507
|
const DEPRECATED_MAP = {
|
|
@@ -1436,7 +1531,11 @@ const noDeprecatedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1436
1531
|
properties: { entryPoint: { type: "string" } },
|
|
1437
1532
|
additionalProperties: false
|
|
1438
1533
|
}],
|
|
1439
|
-
|
|
1534
|
+
hasSuggestions: true,
|
|
1535
|
+
messages: {
|
|
1536
|
+
deprecated: "\"{{className}}\" is deprecated in Tailwind v4. Use \"{{replacement}}\" instead.",
|
|
1537
|
+
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
|
|
1538
|
+
}
|
|
1440
1539
|
},
|
|
1441
1540
|
createOnce(context) {
|
|
1442
1541
|
const getDS = createLazyLoader(context);
|
|
@@ -1484,7 +1583,17 @@ const noDeprecatedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1484
1583
|
data: {
|
|
1485
1584
|
className: cls,
|
|
1486
1585
|
replacement
|
|
1487
|
-
}
|
|
1586
|
+
},
|
|
1587
|
+
suggest: [{
|
|
1588
|
+
messageId: "suggestReplace",
|
|
1589
|
+
data: {
|
|
1590
|
+
className: cls,
|
|
1591
|
+
replacement
|
|
1592
|
+
},
|
|
1593
|
+
fix(fixer) {
|
|
1594
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
1595
|
+
}
|
|
1596
|
+
}]
|
|
1488
1597
|
});
|
|
1489
1598
|
}
|
|
1490
1599
|
}
|
|
@@ -1513,9 +1622,15 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1513
1622
|
},
|
|
1514
1623
|
additionalProperties: false
|
|
1515
1624
|
}],
|
|
1625
|
+
hasSuggestions: true,
|
|
1626
|
+
defaultOptions: [{
|
|
1627
|
+
allowlist: [],
|
|
1628
|
+
ignorePrefixes: []
|
|
1629
|
+
}],
|
|
1516
1630
|
messages: {
|
|
1517
1631
|
unknown: "\"{{className}}\" is not a valid Tailwind class.",
|
|
1518
|
-
unknownWithSuggestion: "\"{{className}}\" is not a valid Tailwind class. Did you mean \"{{suggestion}}\"?"
|
|
1632
|
+
unknownWithSuggestion: "\"{{className}}\" is not a valid Tailwind class. Did you mean \"{{suggestion}}\"?",
|
|
1633
|
+
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
|
|
1519
1634
|
}
|
|
1520
1635
|
},
|
|
1521
1636
|
createOnce(context) {
|
|
@@ -1556,15 +1671,27 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1556
1671
|
if (cache.isValid(stripped)) continue;
|
|
1557
1672
|
if (DEPRECATED_MAP[stripped]) continue;
|
|
1558
1673
|
const suggestion = findBestSuggestion(stripped, cache.validClasses);
|
|
1559
|
-
if (suggestion)
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1674
|
+
if (suggestion) {
|
|
1675
|
+
const fixedValue = classes.map((c) => c === cls ? suggestion : c).join(" ");
|
|
1676
|
+
context.report({
|
|
1677
|
+
node: loc.node,
|
|
1678
|
+
messageId: "unknownWithSuggestion",
|
|
1679
|
+
data: {
|
|
1680
|
+
className: cls,
|
|
1681
|
+
suggestion
|
|
1682
|
+
},
|
|
1683
|
+
suggest: [{
|
|
1684
|
+
messageId: "suggestReplace",
|
|
1685
|
+
data: {
|
|
1686
|
+
className: cls,
|
|
1687
|
+
replacement: suggestion
|
|
1688
|
+
},
|
|
1689
|
+
fix(fixer) {
|
|
1690
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
1691
|
+
}
|
|
1692
|
+
}]
|
|
1693
|
+
});
|
|
1694
|
+
} else context.report({
|
|
1568
1695
|
node: loc.node,
|
|
1569
1696
|
messageId: "unknown",
|
|
1570
1697
|
data: { className: cls }
|
|
@@ -1675,7 +1802,187 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1675
1802
|
}
|
|
1676
1803
|
});
|
|
1677
1804
|
//#endregion
|
|
1805
|
+
//#region src/design-system/canonicalize-service.ts
|
|
1806
|
+
/**
|
|
1807
|
+
* Persistent canonicalize service using worker_threads + SharedArrayBuffer.
|
|
1808
|
+
*
|
|
1809
|
+
* Calls `ds.canonicalizeCandidates(classes, { rem })` dynamically via a worker
|
|
1810
|
+
* thread. Same pattern as sort-service.ts — loads the DS once, then accepts
|
|
1811
|
+
* requests synchronously via Atomics.wait().
|
|
1812
|
+
*
|
|
1813
|
+
* This enables canonicalization of arbitrary user classes (e.g. `p-[2px]` → `p-0.5`)
|
|
1814
|
+
* which can't be precomputed because the input space is infinite.
|
|
1815
|
+
*/
|
|
1816
|
+
const BUFFER_SIZE$1 = 4 * 1024 * 1024;
|
|
1817
|
+
const HEADER_INTS$1 = 4;
|
|
1818
|
+
const DATA_OFFSET$1 = HEADER_INTS$1 * 4 + 4;
|
|
1819
|
+
const INIT_TIMEOUT$1 = 3e4;
|
|
1820
|
+
const REQUEST_TIMEOUT$1 = 1e4;
|
|
1821
|
+
const WORKER_SCRIPT$1 = `
|
|
1822
|
+
const { workerData } = require('worker_threads');
|
|
1823
|
+
|
|
1824
|
+
async function main() {
|
|
1825
|
+
const { sharedBuffer, cssPath } = workerData;
|
|
1826
|
+
const control = new Int32Array(sharedBuffer, 0, ${HEADER_INTS$1});
|
|
1827
|
+
const lengthView = new DataView(sharedBuffer, ${HEADER_INTS$1 * 4}, 4);
|
|
1828
|
+
const dataArea = new Uint8Array(sharedBuffer, ${DATA_OFFSET$1});
|
|
1829
|
+
|
|
1830
|
+
let ds;
|
|
1831
|
+
try {
|
|
1832
|
+
const { __unstable__loadDesignSystem } = require(workerData.tailwindNodePath);
|
|
1833
|
+
const { readFileSync } = require('fs');
|
|
1834
|
+
const { dirname } = require('path');
|
|
1835
|
+
const css = readFileSync(cssPath, 'utf-8');
|
|
1836
|
+
ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
|
|
1837
|
+
} catch {
|
|
1838
|
+
Atomics.store(control, 2, -1);
|
|
1839
|
+
Atomics.notify(control, 2);
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
// Signal ready
|
|
1844
|
+
Atomics.store(control, 2, 1);
|
|
1845
|
+
Atomics.notify(control, 2);
|
|
1846
|
+
|
|
1847
|
+
// Request loop
|
|
1848
|
+
while (true) {
|
|
1849
|
+
Atomics.wait(control, 0, 0);
|
|
1850
|
+
|
|
1851
|
+
const len = lengthView.getUint32(0);
|
|
1852
|
+
const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
|
|
1853
|
+
Atomics.store(control, 0, 0);
|
|
1854
|
+
|
|
1855
|
+
let response;
|
|
1856
|
+
try {
|
|
1857
|
+
const { classes, rem } = JSON.parse(requestStr);
|
|
1858
|
+
const options = rem ? { rem } : undefined;
|
|
1859
|
+
const result = ds.canonicalizeCandidates(classes, options);
|
|
1860
|
+
response = Buffer.from(JSON.stringify(result), 'utf-8');
|
|
1861
|
+
} catch {
|
|
1862
|
+
response = Buffer.from('null', 'utf-8');
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
dataArea.set(response, 0);
|
|
1866
|
+
lengthView.setUint32(0, response.length);
|
|
1867
|
+
|
|
1868
|
+
Atomics.store(control, 1, 1);
|
|
1869
|
+
Atomics.notify(control, 1);
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
main();
|
|
1873
|
+
`;
|
|
1874
|
+
let worker$1 = null;
|
|
1875
|
+
let controlArray$1 = null;
|
|
1876
|
+
let lengthView$1 = null;
|
|
1877
|
+
let dataArea$1 = null;
|
|
1878
|
+
let initialized$1 = false;
|
|
1879
|
+
let available$1 = true;
|
|
1880
|
+
let currentCssPath$1 = null;
|
|
1881
|
+
function ensureService$1(cssPath) {
|
|
1882
|
+
if (initialized$1 && currentCssPath$1 === cssPath) return available$1;
|
|
1883
|
+
if (initialized$1) {
|
|
1884
|
+
cleanup$1();
|
|
1885
|
+
initialized$1 = false;
|
|
1886
|
+
available$1 = true;
|
|
1887
|
+
controlArray$1 = null;
|
|
1888
|
+
lengthView$1 = null;
|
|
1889
|
+
dataArea$1 = null;
|
|
1890
|
+
}
|
|
1891
|
+
initialized$1 = true;
|
|
1892
|
+
currentCssPath$1 = cssPath;
|
|
1893
|
+
try {
|
|
1894
|
+
const tailwindNodePath = require.resolve("@tailwindcss/node");
|
|
1895
|
+
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE$1);
|
|
1896
|
+
controlArray$1 = new Int32Array(sharedBuffer, 0, HEADER_INTS$1);
|
|
1897
|
+
lengthView$1 = new DataView(sharedBuffer, HEADER_INTS$1 * 4, 4);
|
|
1898
|
+
dataArea$1 = new Uint8Array(sharedBuffer, DATA_OFFSET$1);
|
|
1899
|
+
worker$1 = new node_worker_threads.Worker(WORKER_SCRIPT$1, {
|
|
1900
|
+
eval: true,
|
|
1901
|
+
workerData: {
|
|
1902
|
+
sharedBuffer,
|
|
1903
|
+
cssPath,
|
|
1904
|
+
tailwindNodePath
|
|
1905
|
+
}
|
|
1906
|
+
});
|
|
1907
|
+
worker$1.unref();
|
|
1908
|
+
worker$1.on("error", () => {
|
|
1909
|
+
available$1 = false;
|
|
1910
|
+
worker$1 = null;
|
|
1911
|
+
});
|
|
1912
|
+
worker$1.on("exit", () => {
|
|
1913
|
+
worker$1 = null;
|
|
1914
|
+
});
|
|
1915
|
+
if (Atomics.wait(controlArray$1, 2, 0, INIT_TIMEOUT$1) === "timed-out" || controlArray$1[2] === -1) {
|
|
1916
|
+
available$1 = false;
|
|
1917
|
+
cleanup$1();
|
|
1918
|
+
return false;
|
|
1919
|
+
}
|
|
1920
|
+
process.on("exit", cleanup$1);
|
|
1921
|
+
return true;
|
|
1922
|
+
} catch {
|
|
1923
|
+
available$1 = false;
|
|
1924
|
+
cleanup$1();
|
|
1925
|
+
return false;
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
function cleanup$1() {
|
|
1929
|
+
if (worker$1) {
|
|
1930
|
+
try {
|
|
1931
|
+
worker$1.terminate();
|
|
1932
|
+
} catch {}
|
|
1933
|
+
worker$1 = null;
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1937
|
+
* Canonicalize classes using the Tailwind CSS design system via worker thread.
|
|
1938
|
+
* Returns the canonicalized class array, or null if the service is unavailable.
|
|
1939
|
+
*/
|
|
1940
|
+
function canonicalizeClassesSync(cssPath, classes, rem) {
|
|
1941
|
+
if (!ensureService$1(cssPath)) return null;
|
|
1942
|
+
if (!controlArray$1 || !dataArea$1 || !lengthView$1) return null;
|
|
1943
|
+
try {
|
|
1944
|
+
const request = Buffer.from(JSON.stringify({
|
|
1945
|
+
classes,
|
|
1946
|
+
rem
|
|
1947
|
+
}), "utf-8");
|
|
1948
|
+
if (request.length > BUFFER_SIZE$1 - DATA_OFFSET$1) return null;
|
|
1949
|
+
dataArea$1.set(request, 0);
|
|
1950
|
+
lengthView$1.setUint32(0, request.length);
|
|
1951
|
+
Atomics.store(controlArray$1, 0, 1);
|
|
1952
|
+
Atomics.notify(controlArray$1, 0);
|
|
1953
|
+
if (Atomics.wait(controlArray$1, 1, 0, REQUEST_TIMEOUT$1) === "timed-out") {
|
|
1954
|
+
available$1 = false;
|
|
1955
|
+
cleanup$1();
|
|
1956
|
+
return null;
|
|
1957
|
+
}
|
|
1958
|
+
const responseLen = lengthView$1.getUint32(0);
|
|
1959
|
+
const responseStr = Buffer.from(dataArea$1.slice(0, responseLen)).toString("utf-8");
|
|
1960
|
+
Atomics.store(controlArray$1, 1, 0);
|
|
1961
|
+
return JSON.parse(responseStr);
|
|
1962
|
+
} catch {
|
|
1963
|
+
available$1 = false;
|
|
1964
|
+
cleanup$1();
|
|
1965
|
+
return null;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
//#endregion
|
|
1678
1969
|
//#region src/rules/enforce-canonical.ts
|
|
1970
|
+
/**
|
|
1971
|
+
* Preserve the user's ! position after canonicalization.
|
|
1972
|
+
* canonicalizeCandidates always normalizes ! to suffix, but
|
|
1973
|
+
* enforce-consistent-important-position handles that separately.
|
|
1974
|
+
*/
|
|
1975
|
+
function preserveImportantPosition(original, canonicalized) {
|
|
1976
|
+
const origHasPrefix = original.startsWith("!") || /^[a-z0-9[\]*@-]*:!/.test(original);
|
|
1977
|
+
const origHasSuffix = original.endsWith("!") && !origHasPrefix;
|
|
1978
|
+
if (!origHasPrefix && !origHasSuffix) return canonicalized.replace(/!/g, "");
|
|
1979
|
+
const bare = canonicalized.replace(/!/g, "");
|
|
1980
|
+
if (origHasPrefix) {
|
|
1981
|
+
const variantPrefix = bare.slice(0, bare.length - bare.replace(/^[a-z0-9[\]*@-]*:/g, "").length);
|
|
1982
|
+
return variantPrefix + "!" + bare.slice(variantPrefix.length);
|
|
1983
|
+
}
|
|
1984
|
+
return bare + "!";
|
|
1985
|
+
}
|
|
1679
1986
|
const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
1680
1987
|
meta: {
|
|
1681
1988
|
type: "suggestion",
|
|
@@ -1686,17 +1993,29 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
1686
1993
|
properties: { entryPoint: { type: "string" } },
|
|
1687
1994
|
additionalProperties: false
|
|
1688
1995
|
}],
|
|
1689
|
-
|
|
1996
|
+
hasSuggestions: true,
|
|
1997
|
+
messages: {
|
|
1998
|
+
nonCanonical: "\"{{className}}\" can be written as \"{{canonical}}\". Use the canonical form.",
|
|
1999
|
+
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
|
|
2000
|
+
}
|
|
1690
2001
|
},
|
|
1691
2002
|
createOnce(context) {
|
|
1692
2003
|
const getDS = createLazyLoader(context);
|
|
2004
|
+
let _rem = null;
|
|
2005
|
+
function getRem() {
|
|
2006
|
+
if (_rem === null) _rem = rootFontSizeFromSettings(safeSettings(context));
|
|
2007
|
+
return _rem;
|
|
2008
|
+
}
|
|
1693
2009
|
function check(locations) {
|
|
1694
2010
|
const ds = getDS();
|
|
1695
2011
|
if (!ds) return;
|
|
1696
|
-
const { cache } = ds;
|
|
2012
|
+
const { cache, entryPoint } = ds;
|
|
1697
2013
|
for (const loc of locations) {
|
|
1698
2014
|
const classes = splitClasses(loc.value);
|
|
1699
|
-
const
|
|
2015
|
+
const dynamic = canonicalizeClassesSync(entryPoint, classes, getRem());
|
|
2016
|
+
let canonicals;
|
|
2017
|
+
if (dynamic) canonicals = classes.map((cls, i) => preserveImportantPosition(cls, dynamic[i]));
|
|
2018
|
+
else canonicals = classes.map((cls) => cache.canonicalize(cls));
|
|
1700
2019
|
let firstNonCanonical = true;
|
|
1701
2020
|
for (let i = 0; i < classes.length; i++) {
|
|
1702
2021
|
const cls = classes[i];
|
|
@@ -1716,14 +2035,27 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
1716
2035
|
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
1717
2036
|
}
|
|
1718
2037
|
});
|
|
1719
|
-
} else
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
2038
|
+
} else {
|
|
2039
|
+
const fixedValue = canonicals.join(" ");
|
|
2040
|
+
context.report({
|
|
2041
|
+
node: loc.node,
|
|
2042
|
+
messageId: "nonCanonical",
|
|
2043
|
+
data: {
|
|
2044
|
+
className: cls,
|
|
2045
|
+
canonical
|
|
2046
|
+
},
|
|
2047
|
+
suggest: [{
|
|
2048
|
+
messageId: "suggestReplace",
|
|
2049
|
+
data: {
|
|
2050
|
+
className: cls,
|
|
2051
|
+
replacement: canonical
|
|
2052
|
+
},
|
|
2053
|
+
fix(fixer) {
|
|
2054
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
2055
|
+
}
|
|
2056
|
+
}]
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
1727
2059
|
}
|
|
1728
2060
|
}
|
|
1729
2061
|
}
|
|
@@ -2145,7 +2477,11 @@ const enforceLogical = (0, _oxlint_plugins.defineRule)({
|
|
|
2145
2477
|
docs: { description: "Enforce logical (RTL-friendly) Tailwind CSS properties instead of physical ones" },
|
|
2146
2478
|
fixable: "code",
|
|
2147
2479
|
schema: [],
|
|
2148
|
-
|
|
2480
|
+
hasSuggestions: true,
|
|
2481
|
+
messages: {
|
|
2482
|
+
useLogical: "\"{{className}}\" uses a physical property. Use \"{{replacement}}\" for LTR/RTL support.",
|
|
2483
|
+
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
|
|
2484
|
+
}
|
|
2149
2485
|
},
|
|
2150
2486
|
createOnce(context) {
|
|
2151
2487
|
function convertClass(cls) {
|
|
@@ -2192,7 +2528,17 @@ const enforceLogical = (0, _oxlint_plugins.defineRule)({
|
|
|
2192
2528
|
data: {
|
|
2193
2529
|
className: cls,
|
|
2194
2530
|
replacement
|
|
2195
|
-
}
|
|
2531
|
+
},
|
|
2532
|
+
suggest: [{
|
|
2533
|
+
messageId: "suggestReplace",
|
|
2534
|
+
data: {
|
|
2535
|
+
className: cls,
|
|
2536
|
+
replacement
|
|
2537
|
+
},
|
|
2538
|
+
fix(fixer) {
|
|
2539
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
2540
|
+
}
|
|
2541
|
+
}]
|
|
2196
2542
|
});
|
|
2197
2543
|
}
|
|
2198
2544
|
}
|
|
@@ -2210,7 +2556,11 @@ const enforcePhysical = (0, _oxlint_plugins.defineRule)({
|
|
|
2210
2556
|
docs: { description: "Enforce physical Tailwind CSS properties instead of logical ones for consistency in LTR-only projects" },
|
|
2211
2557
|
fixable: "code",
|
|
2212
2558
|
schema: [],
|
|
2213
|
-
|
|
2559
|
+
hasSuggestions: true,
|
|
2560
|
+
messages: {
|
|
2561
|
+
usePhysical: "\"{{className}}\" uses a logical property. Use \"{{replacement}}\" for consistency.",
|
|
2562
|
+
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
|
|
2563
|
+
}
|
|
2214
2564
|
},
|
|
2215
2565
|
createOnce(context) {
|
|
2216
2566
|
function convertClass(cls) {
|
|
@@ -2257,7 +2607,17 @@ const enforcePhysical = (0, _oxlint_plugins.defineRule)({
|
|
|
2257
2607
|
data: {
|
|
2258
2608
|
className: cls,
|
|
2259
2609
|
replacement
|
|
2260
|
-
}
|
|
2610
|
+
},
|
|
2611
|
+
suggest: [{
|
|
2612
|
+
messageId: "suggestReplace",
|
|
2613
|
+
data: {
|
|
2614
|
+
className: cls,
|
|
2615
|
+
replacement
|
|
2616
|
+
},
|
|
2617
|
+
fix(fixer) {
|
|
2618
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
2619
|
+
}
|
|
2620
|
+
}]
|
|
2261
2621
|
});
|
|
2262
2622
|
}
|
|
2263
2623
|
}
|
|
@@ -2277,6 +2637,7 @@ const maxClassCount = (0, _oxlint_plugins.defineRule)({
|
|
|
2277
2637
|
properties: { max: { type: "number" } },
|
|
2278
2638
|
additionalProperties: false
|
|
2279
2639
|
}],
|
|
2640
|
+
defaultOptions: [{ max: DEFAULT_MAX }],
|
|
2280
2641
|
messages: { tooMany: "Too many Tailwind classes ({{count}}). Maximum allowed is {{max}}. Consider extracting into a component or utility." }
|
|
2281
2642
|
},
|
|
2282
2643
|
createOnce(context) {
|
|
@@ -2446,9 +2807,12 @@ const enforceConsistentImportantPosition = (0, _oxlint_plugins.defineRule)({
|
|
|
2446
2807
|
} },
|
|
2447
2808
|
additionalProperties: false
|
|
2448
2809
|
}],
|
|
2810
|
+
hasSuggestions: true,
|
|
2811
|
+
defaultOptions: [{ position: "suffix" }],
|
|
2449
2812
|
messages: {
|
|
2450
2813
|
usePrefix: "\"{{className}}\" uses suffix important. Use \"{{replacement}}\" (prefix) instead.",
|
|
2451
|
-
useSuffix: "\"{{className}}\" uses prefix important. Use \"{{replacement}}\" (suffix) instead."
|
|
2814
|
+
useSuffix: "\"{{className}}\" uses prefix important. Use \"{{replacement}}\" (suffix) instead.",
|
|
2815
|
+
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
|
|
2452
2816
|
}
|
|
2453
2817
|
},
|
|
2454
2818
|
createOnce(context) {
|
|
@@ -2498,7 +2862,17 @@ const enforceConsistentImportantPosition = (0, _oxlint_plugins.defineRule)({
|
|
|
2498
2862
|
data: {
|
|
2499
2863
|
className: cls,
|
|
2500
2864
|
replacement
|
|
2501
|
-
}
|
|
2865
|
+
},
|
|
2866
|
+
suggest: [{
|
|
2867
|
+
messageId: "suggestReplace",
|
|
2868
|
+
data: {
|
|
2869
|
+
className: cls,
|
|
2870
|
+
replacement
|
|
2871
|
+
},
|
|
2872
|
+
fix(fixer) {
|
|
2873
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
2874
|
+
}
|
|
2875
|
+
}]
|
|
2502
2876
|
});
|
|
2503
2877
|
}
|
|
2504
2878
|
}
|
|
@@ -2533,7 +2907,11 @@ const enforceNegativeArbitraryValues = (0, _oxlint_plugins.defineRule)({
|
|
|
2533
2907
|
docs: { description: "Enforce moving the negative sign inside arbitrary value brackets: -top-[5px] → top-[-5px]" },
|
|
2534
2908
|
fixable: "code",
|
|
2535
2909
|
schema: [],
|
|
2536
|
-
|
|
2910
|
+
hasSuggestions: true,
|
|
2911
|
+
messages: {
|
|
2912
|
+
moveNegative: "\"{{className}}\" has the negative outside brackets. Use \"{{replacement}}\" instead.",
|
|
2913
|
+
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
|
|
2914
|
+
}
|
|
2537
2915
|
},
|
|
2538
2916
|
createOnce(context) {
|
|
2539
2917
|
function check(locations) {
|
|
@@ -2569,7 +2947,17 @@ const enforceNegativeArbitraryValues = (0, _oxlint_plugins.defineRule)({
|
|
|
2569
2947
|
data: {
|
|
2570
2948
|
className: cls,
|
|
2571
2949
|
replacement
|
|
2572
|
-
}
|
|
2950
|
+
},
|
|
2951
|
+
suggest: [{
|
|
2952
|
+
messageId: "suggestReplace",
|
|
2953
|
+
data: {
|
|
2954
|
+
className: cls,
|
|
2955
|
+
replacement
|
|
2956
|
+
},
|
|
2957
|
+
fix(fixer) {
|
|
2958
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
2959
|
+
}
|
|
2960
|
+
}]
|
|
2573
2961
|
});
|
|
2574
2962
|
}
|
|
2575
2963
|
}
|
|
@@ -2616,9 +3004,12 @@ const enforceConsistentVariableSyntax = (0, _oxlint_plugins.defineRule)({
|
|
|
2616
3004
|
} },
|
|
2617
3005
|
additionalProperties: false
|
|
2618
3006
|
}],
|
|
3007
|
+
hasSuggestions: true,
|
|
3008
|
+
defaultOptions: [{ syntax: "shorthand" }],
|
|
2619
3009
|
messages: {
|
|
2620
3010
|
useShorthand: "\"{{className}}\" uses explicit var() syntax. Use \"{{replacement}}\" (shorthand) instead.",
|
|
2621
|
-
useExplicit: "\"{{className}}\" uses shorthand syntax. Use \"{{replacement}}\" (explicit) instead."
|
|
3011
|
+
useExplicit: "\"{{className}}\" uses shorthand syntax. Use \"{{replacement}}\" (explicit) instead.",
|
|
3012
|
+
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
|
|
2622
3013
|
}
|
|
2623
3014
|
},
|
|
2624
3015
|
createOnce(context) {
|
|
@@ -2662,7 +3053,17 @@ const enforceConsistentVariableSyntax = (0, _oxlint_plugins.defineRule)({
|
|
|
2662
3053
|
data: {
|
|
2663
3054
|
className: cls,
|
|
2664
3055
|
replacement
|
|
2665
|
-
}
|
|
3056
|
+
},
|
|
3057
|
+
suggest: [{
|
|
3058
|
+
messageId: "suggestReplace",
|
|
3059
|
+
data: {
|
|
3060
|
+
className: cls,
|
|
3061
|
+
replacement
|
|
3062
|
+
},
|
|
3063
|
+
fix(fixer) {
|
|
3064
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
3065
|
+
}
|
|
3066
|
+
}]
|
|
2666
3067
|
});
|
|
2667
3068
|
}
|
|
2668
3069
|
}
|
|
@@ -2730,6 +3131,7 @@ const noDarkWithoutLight = (0, _oxlint_plugins.defineRule)({
|
|
|
2730
3131
|
} },
|
|
2731
3132
|
additionalProperties: false
|
|
2732
3133
|
}],
|
|
3134
|
+
defaultOptions: [{ variants: DEFAULT_VARIANTS }],
|
|
2733
3135
|
messages: { missingBase: "\"{{className}}\" uses the {{variant}} variant, but there is no base \"{{prefix}}-*\" class on this element." }
|
|
2734
3136
|
},
|
|
2735
3137
|
createOnce(context) {
|
|
@@ -3012,7 +3414,11 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3012
3414
|
},
|
|
3013
3415
|
additionalProperties: false
|
|
3014
3416
|
}],
|
|
3015
|
-
|
|
3417
|
+
hasSuggestions: true,
|
|
3418
|
+
messages: {
|
|
3419
|
+
wrongOrder: "\"{{className}}\" has variants in wrong order. Use \"{{replacement}}\" instead.",
|
|
3420
|
+
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
|
|
3421
|
+
}
|
|
3016
3422
|
},
|
|
3017
3423
|
createOnce(context) {
|
|
3018
3424
|
const getDS = createLazyLoader(context);
|
|
@@ -3101,7 +3507,17 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3101
3507
|
data: {
|
|
3102
3508
|
className: cls,
|
|
3103
3509
|
replacement
|
|
3104
|
-
}
|
|
3510
|
+
},
|
|
3511
|
+
suggest: [{
|
|
3512
|
+
messageId: "suggestReplace",
|
|
3513
|
+
data: {
|
|
3514
|
+
className: cls,
|
|
3515
|
+
replacement
|
|
3516
|
+
},
|
|
3517
|
+
fix(fixer) {
|
|
3518
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
3519
|
+
}
|
|
3520
|
+
}]
|
|
3105
3521
|
});
|
|
3106
3522
|
}
|
|
3107
3523
|
}
|
|
@@ -3125,6 +3541,7 @@ const enforceConsistentLineWrapping = (0, _oxlint_plugins.defineRule)({
|
|
|
3125
3541
|
},
|
|
3126
3542
|
additionalProperties: false
|
|
3127
3543
|
}],
|
|
3544
|
+
defaultOptions: [{ printWidth: DEFAULT_PRINT_WIDTH }],
|
|
3128
3545
|
messages: {
|
|
3129
3546
|
tooLong: "Class string is {{length}} characters long, exceeding the print width of {{printWidth}}. Consider splitting into multiple lines or extracting into a component.",
|
|
3130
3547
|
tooManyPerLine: "Too many classes on a single line ({{count}}). Maximum allowed per line is {{max}}."
|
|
@@ -3198,7 +3615,11 @@ const noUnnecessaryArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
3198
3615
|
properties: { entryPoint: { type: "string" } },
|
|
3199
3616
|
additionalProperties: false
|
|
3200
3617
|
}],
|
|
3201
|
-
|
|
3618
|
+
hasSuggestions: true,
|
|
3619
|
+
messages: {
|
|
3620
|
+
unnecessaryArbitrary: "\"{{className}}\" can be written as \"{{replacement}}\". Use the named class instead.",
|
|
3621
|
+
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
|
|
3622
|
+
}
|
|
3202
3623
|
},
|
|
3203
3624
|
createOnce(context) {
|
|
3204
3625
|
const getDS = createLazyLoader(context);
|
|
@@ -3244,7 +3665,17 @@ const noUnnecessaryArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
3244
3665
|
data: {
|
|
3245
3666
|
className: cls,
|
|
3246
3667
|
replacement
|
|
3247
|
-
}
|
|
3668
|
+
},
|
|
3669
|
+
suggest: [{
|
|
3670
|
+
messageId: "suggestReplace",
|
|
3671
|
+
data: {
|
|
3672
|
+
className: cls,
|
|
3673
|
+
replacement
|
|
3674
|
+
},
|
|
3675
|
+
fix(fixer) {
|
|
3676
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
3677
|
+
}
|
|
3678
|
+
}]
|
|
3248
3679
|
});
|
|
3249
3680
|
}
|
|
3250
3681
|
}
|