oxlint-tailwindcss 0.4.0 → 0.5.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/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { definePlugin, defineRule } from "@oxlint/plugins";
3
3
  import { execFileSync } from "node:child_process";
4
4
  import { createHash } from "node:crypto";
5
5
  import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
6
- import { dirname, join, resolve } from "node:path";
6
+ import { dirname, join, relative, resolve } from "node:path";
7
7
  import { tmpdir } from "node:os";
8
8
  import { Worker } from "node:worker_threads";
9
9
  //#region \0rolldown/runtime.js
@@ -177,6 +177,10 @@ function extractFromClassedCall(node) {
177
177
  skippedFirst = true;
178
178
  continue;
179
179
  }
180
+ if (!skippedFirst && arg.type === "TemplateLiteral") {
181
+ skippedFirst = true;
182
+ continue;
183
+ }
180
184
  skippedFirst = true;
181
185
  if (arg.type === "ObjectExpression") results.push(...extractFromCvaConfig(arg));
182
186
  else results.push(...extractFromExpression(arg));
@@ -1261,42 +1265,83 @@ function autoDetectEntryPoint(filePath) {
1261
1265
  continue;
1262
1266
  }
1263
1267
  }
1268
+ if (existsSync(join(currentDir, "package.json"))) break;
1264
1269
  const parentDir = dirname(currentDir);
1265
1270
  if (parentDir === currentDir) break;
1266
- if (depth > 0 && existsSync(join(parentDir, "package.json"))) {
1267
- for (const candidate of CANDIDATE_PATHS) {
1268
- const fullPath = join(parentDir, candidate);
1269
- if (!existsSync(fullPath)) continue;
1270
- try {
1271
- const content = readFileSync(fullPath, "utf-8");
1272
- if (TAILWIND_SIGNALS.some((signal) => content.includes(signal))) return fullPath;
1273
- if (hasTailwindSignalInImports(content, dirname(fullPath), TAILWIND_SIGNALS)) return fullPath;
1274
- } catch {
1275
- continue;
1276
- }
1277
- }
1278
- break;
1279
- }
1280
1271
  currentDir = parentDir;
1281
1272
  }
1282
1273
  return null;
1283
1274
  }
1284
1275
  //#endregion
1276
+ //#region src/design-system/debug.ts
1277
+ const PREFIX = "[oxlint-tailwindcss]";
1278
+ let _enabled = null;
1279
+ /**
1280
+ * Check if debug logging is enabled.
1281
+ * Activated by `settings.tailwindcss.debug: true` or `DEBUG=oxlint-tailwindcss` env var.
1282
+ */
1283
+ function isDebugEnabled(settings) {
1284
+ if (process.env.DEBUG === "oxlint-tailwindcss") return true;
1285
+ if (settings !== void 0) {
1286
+ const tw = settings?.tailwindcss;
1287
+ if (tw && typeof tw === "object" && "debug" in tw) return tw.debug === true;
1288
+ }
1289
+ return false;
1290
+ }
1291
+ /**
1292
+ * Enable debug mode (called once when settings become available).
1293
+ */
1294
+ function setDebugEnabled(enabled) {
1295
+ _enabled = enabled;
1296
+ }
1297
+ /**
1298
+ * Log a debug message if debug mode is active.
1299
+ */
1300
+ function debugLog(message) {
1301
+ if (_enabled || process.env.DEBUG === "oxlint-tailwindcss") console.error(`${PREFIX} ${message}`);
1302
+ }
1303
+ //#endregion
1285
1304
  //#region src/design-system/loader.ts
1286
1305
  const dsCache = /* @__PURE__ */ new Map();
1287
1306
  const autoDetectCache = /* @__PURE__ */ new Map();
1288
1307
  let lastLoadedPath = null;
1289
1308
  /**
1290
1309
  * Extracts `entryPoint` from `context.settings.tailwindcss`.
1310
+ * Supports both `string` and `string[]` (for monorepos).
1291
1311
  */
1292
1312
  function entryPointFromSettings(settings) {
1293
1313
  const tw = settings?.tailwindcss;
1294
1314
  if (tw && typeof tw === "object" && "entryPoint" in tw) {
1295
1315
  const ep = tw.entryPoint;
1296
1316
  if (typeof ep === "string") return ep;
1317
+ if (Array.isArray(ep) && ep.length > 0 && ep.every((e) => typeof e === "string")) return ep;
1297
1318
  }
1298
1319
  }
1299
1320
  /**
1321
+ * Given an array of entry points and a file path, pick the one that shares
1322
+ * the longest common directory prefix with the file. Falls back to first entry.
1323
+ */
1324
+ function resolveClosestEntryPoint(entryPoints, filePath) {
1325
+ if (entryPoints.length === 1 || !filePath) return entryPoints[0];
1326
+ const fileDir = dirname(resolve(filePath));
1327
+ let best = entryPoints[0];
1328
+ let bestLen = 0;
1329
+ for (const ep of entryPoints) {
1330
+ const len = commonPrefixLength(fileDir, dirname(resolve(ep)));
1331
+ if (len > bestLen) {
1332
+ bestLen = len;
1333
+ best = ep;
1334
+ }
1335
+ }
1336
+ return best;
1337
+ }
1338
+ function commonPrefixLength(a, b) {
1339
+ const len = Math.min(a.length, b.length);
1340
+ let i = 0;
1341
+ while (i < len && a[i] === b[i]) i++;
1342
+ return i;
1343
+ }
1344
+ /**
1300
1345
  * Extracts `timeout` from `context.settings.tailwindcss`.
1301
1346
  */
1302
1347
  function timeoutFromSettings(settings) {
@@ -1330,16 +1375,21 @@ function cachedAutoDetect(filePath) {
1330
1375
  * Resolution order: rule option `entryPoint` > `settings.tailwindcss.entryPoint` > auto-detect.
1331
1376
  */
1332
1377
  function getLoadedDesignSystem(entryPoint, settings, filePath) {
1333
- const cssPath = entryPoint ?? entryPointFromSettings(settings) ?? cachedAutoDetect(filePath) ?? lastLoadedPath;
1378
+ const settingsEntry = entryPointFromSettings(settings);
1379
+ const explicitEntry = entryPoint ?? (Array.isArray(settingsEntry) ? resolveClosestEntryPoint(settingsEntry, filePath) : settingsEntry);
1380
+ const cssPath = explicitEntry ?? cachedAutoDetect(filePath) ?? lastLoadedPath;
1334
1381
  if (!cssPath) return null;
1335
1382
  const resolvedPath = resolve(cssPath);
1336
1383
  try {
1337
1384
  const mtime = statSync(resolvedPath).mtimeMs;
1338
1385
  const cached = dsCache.get(resolvedPath);
1339
- if (cached && cached.mtime === mtime) return {
1340
- cache: cached.cache,
1341
- entryPoint: resolvedPath
1342
- };
1386
+ if (cached && cached.mtime === mtime) {
1387
+ if (explicitEntry) lastLoadedPath = resolvedPath;
1388
+ return {
1389
+ cache: cached.cache,
1390
+ entryPoint: resolvedPath
1391
+ };
1392
+ }
1343
1393
  const data = loadDesignSystemSync(resolvedPath, timeoutFromSettings(settings));
1344
1394
  if (!data) return null;
1345
1395
  const cache = DesignSystemCache.fromPrecomputed(data);
@@ -1347,7 +1397,8 @@ function getLoadedDesignSystem(entryPoint, settings, filePath) {
1347
1397
  cache,
1348
1398
  mtime
1349
1399
  });
1350
- lastLoadedPath = resolvedPath;
1400
+ debugLog(`Loaded design system from "${resolvedPath}"`);
1401
+ if (explicitEntry) lastLoadedPath = resolvedPath;
1351
1402
  return {
1352
1403
  cache,
1353
1404
  entryPoint: resolvedPath
@@ -1371,6 +1422,7 @@ function createLazyLoader(context) {
1371
1422
  let lastResult = null;
1372
1423
  let fixedEntryResolved = false;
1373
1424
  let fixedResult = null;
1425
+ let debugInitialized = false;
1374
1426
  return () => {
1375
1427
  let entryPoint;
1376
1428
  try {
@@ -1384,16 +1436,31 @@ function createLazyLoader(context) {
1384
1436
  try {
1385
1437
  filePath = context.filename;
1386
1438
  } catch {}
1387
- const fixedEntry = entryPoint ?? entryPointFromSettings(settings);
1439
+ if (!debugInitialized && settings) {
1440
+ debugInitialized = true;
1441
+ setDebugEnabled(isDebugEnabled(settings));
1442
+ }
1443
+ const settingsEntry = entryPointFromSettings(settings);
1444
+ const fixedEntry = entryPoint ?? (typeof settingsEntry === "string" ? settingsEntry : void 0);
1388
1445
  if (fixedEntry) {
1389
1446
  if (fixedEntryResolved) return fixedResult;
1390
1447
  fixedEntryResolved = true;
1391
1448
  fixedResult = getLoadedDesignSystem(fixedEntry, settings, filePath);
1449
+ if (fixedResult && filePath) debugLog(`${relative(process.cwd(), filePath)} → ${relative(process.cwd(), fixedResult.entryPoint)}`);
1392
1450
  return fixedResult;
1393
1451
  }
1452
+ if (Array.isArray(settingsEntry)) {
1453
+ const closest = resolveClosestEntryPoint(settingsEntry, filePath);
1454
+ if (filePath && filePath === lastFilePath) return lastResult;
1455
+ if (filePath) lastFilePath = filePath;
1456
+ lastResult = getLoadedDesignSystem(closest, settings, filePath);
1457
+ if (lastResult && filePath) debugLog(`${relative(process.cwd(), filePath)} → ${relative(process.cwd(), lastResult.entryPoint)}`);
1458
+ return lastResult;
1459
+ }
1394
1460
  if (filePath && filePath === lastFilePath) return lastResult;
1395
1461
  if (filePath) lastFilePath = filePath;
1396
1462
  lastResult = getLoadedDesignSystem(void 0, settings, filePath);
1463
+ if (lastResult && filePath) debugLog(`${relative(process.cwd(), filePath)} → ${relative(process.cwd(), lastResult.entryPoint)}`);
1397
1464
  return lastResult;
1398
1465
  };
1399
1466
  }
@@ -1444,7 +1511,11 @@ const noDeprecatedClasses = defineRule({
1444
1511
  properties: { entryPoint: { type: "string" } },
1445
1512
  additionalProperties: false
1446
1513
  }],
1447
- messages: { deprecated: "\"{{className}}\" is deprecated in Tailwind v4. Use \"{{replacement}}\" instead." }
1514
+ hasSuggestions: true,
1515
+ messages: {
1516
+ deprecated: "\"{{className}}\" is deprecated in Tailwind v4. Use \"{{replacement}}\" instead.",
1517
+ suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
1518
+ }
1448
1519
  },
1449
1520
  createOnce(context) {
1450
1521
  const getDS = createLazyLoader(context);
@@ -1492,7 +1563,17 @@ const noDeprecatedClasses = defineRule({
1492
1563
  data: {
1493
1564
  className: cls,
1494
1565
  replacement
1495
- }
1566
+ },
1567
+ suggest: [{
1568
+ messageId: "suggestReplace",
1569
+ data: {
1570
+ className: cls,
1571
+ replacement
1572
+ },
1573
+ fix(fixer) {
1574
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
1575
+ }
1576
+ }]
1496
1577
  });
1497
1578
  }
1498
1579
  }
@@ -1521,9 +1602,15 @@ const noUnknownClasses = defineRule({
1521
1602
  },
1522
1603
  additionalProperties: false
1523
1604
  }],
1605
+ hasSuggestions: true,
1606
+ defaultOptions: [{
1607
+ allowlist: [],
1608
+ ignorePrefixes: []
1609
+ }],
1524
1610
  messages: {
1525
1611
  unknown: "\"{{className}}\" is not a valid Tailwind class.",
1526
- unknownWithSuggestion: "\"{{className}}\" is not a valid Tailwind class. Did you mean \"{{suggestion}}\"?"
1612
+ unknownWithSuggestion: "\"{{className}}\" is not a valid Tailwind class. Did you mean \"{{suggestion}}\"?",
1613
+ suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
1527
1614
  }
1528
1615
  },
1529
1616
  createOnce(context) {
@@ -1564,15 +1651,27 @@ const noUnknownClasses = defineRule({
1564
1651
  if (cache.isValid(stripped)) continue;
1565
1652
  if (DEPRECATED_MAP[stripped]) continue;
1566
1653
  const suggestion = findBestSuggestion(stripped, cache.validClasses);
1567
- if (suggestion) context.report({
1568
- node: loc.node,
1569
- messageId: "unknownWithSuggestion",
1570
- data: {
1571
- className: cls,
1572
- suggestion
1573
- }
1574
- });
1575
- else context.report({
1654
+ if (suggestion) {
1655
+ const fixedValue = classes.map((c) => c === cls ? suggestion : c).join(" ");
1656
+ context.report({
1657
+ node: loc.node,
1658
+ messageId: "unknownWithSuggestion",
1659
+ data: {
1660
+ className: cls,
1661
+ suggestion
1662
+ },
1663
+ suggest: [{
1664
+ messageId: "suggestReplace",
1665
+ data: {
1666
+ className: cls,
1667
+ replacement: suggestion
1668
+ },
1669
+ fix(fixer) {
1670
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
1671
+ }
1672
+ }]
1673
+ });
1674
+ } else context.report({
1576
1675
  node: loc.node,
1577
1676
  messageId: "unknown",
1578
1677
  data: { className: cls }
@@ -1630,6 +1729,7 @@ const noConflictingClasses = defineRule({
1630
1729
  ];
1631
1730
  const COMPOSITION_PAIRS = [
1632
1731
  [/^text-/, /^leading-/],
1732
+ [/^text-/, /^tracking-/],
1633
1733
  [/^border(?:-[0-9]|$)/, /^border-(?:solid|dashed|dotted|double|hidden|none)$/],
1634
1734
  [/^divide-/, /^border(?:-[trblxyse])?-/],
1635
1735
  [/^prose(?:-|$)/, /^max-w-/]
@@ -1693,7 +1793,11 @@ const enforceCanonical = defineRule({
1693
1793
  properties: { entryPoint: { type: "string" } },
1694
1794
  additionalProperties: false
1695
1795
  }],
1696
- messages: { nonCanonical: "\"{{className}}\" can be written as \"{{canonical}}\". Use the canonical form." }
1796
+ hasSuggestions: true,
1797
+ messages: {
1798
+ nonCanonical: "\"{{className}}\" can be written as \"{{canonical}}\". Use the canonical form.",
1799
+ suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
1800
+ }
1697
1801
  },
1698
1802
  createOnce(context) {
1699
1803
  const getDS = createLazyLoader(context);
@@ -1723,14 +1827,27 @@ const enforceCanonical = defineRule({
1723
1827
  return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
1724
1828
  }
1725
1829
  });
1726
- } else context.report({
1727
- node: loc.node,
1728
- messageId: "nonCanonical",
1729
- data: {
1730
- className: cls,
1731
- canonical
1732
- }
1733
- });
1830
+ } else {
1831
+ const fixedValue = canonicals.join(" ");
1832
+ context.report({
1833
+ node: loc.node,
1834
+ messageId: "nonCanonical",
1835
+ data: {
1836
+ className: cls,
1837
+ canonical
1838
+ },
1839
+ suggest: [{
1840
+ messageId: "suggestReplace",
1841
+ data: {
1842
+ className: cls,
1843
+ replacement: canonical
1844
+ },
1845
+ fix(fixer) {
1846
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
1847
+ }
1848
+ }]
1849
+ });
1850
+ }
1734
1851
  }
1735
1852
  }
1736
1853
  }
@@ -2152,7 +2269,11 @@ const enforceLogical = defineRule({
2152
2269
  docs: { description: "Enforce logical (RTL-friendly) Tailwind CSS properties instead of physical ones" },
2153
2270
  fixable: "code",
2154
2271
  schema: [],
2155
- messages: { useLogical: "\"{{className}}\" uses a physical property. Use \"{{replacement}}\" for LTR/RTL support." }
2272
+ hasSuggestions: true,
2273
+ messages: {
2274
+ useLogical: "\"{{className}}\" uses a physical property. Use \"{{replacement}}\" for LTR/RTL support.",
2275
+ suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
2276
+ }
2156
2277
  },
2157
2278
  createOnce(context) {
2158
2279
  function convertClass(cls) {
@@ -2199,7 +2320,17 @@ const enforceLogical = defineRule({
2199
2320
  data: {
2200
2321
  className: cls,
2201
2322
  replacement
2202
- }
2323
+ },
2324
+ suggest: [{
2325
+ messageId: "suggestReplace",
2326
+ data: {
2327
+ className: cls,
2328
+ replacement
2329
+ },
2330
+ fix(fixer) {
2331
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
2332
+ }
2333
+ }]
2203
2334
  });
2204
2335
  }
2205
2336
  }
@@ -2217,7 +2348,11 @@ const enforcePhysical = defineRule({
2217
2348
  docs: { description: "Enforce physical Tailwind CSS properties instead of logical ones for consistency in LTR-only projects" },
2218
2349
  fixable: "code",
2219
2350
  schema: [],
2220
- messages: { usePhysical: "\"{{className}}\" uses a logical property. Use \"{{replacement}}\" for consistency." }
2351
+ hasSuggestions: true,
2352
+ messages: {
2353
+ usePhysical: "\"{{className}}\" uses a logical property. Use \"{{replacement}}\" for consistency.",
2354
+ suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
2355
+ }
2221
2356
  },
2222
2357
  createOnce(context) {
2223
2358
  function convertClass(cls) {
@@ -2264,7 +2399,17 @@ const enforcePhysical = defineRule({
2264
2399
  data: {
2265
2400
  className: cls,
2266
2401
  replacement
2267
- }
2402
+ },
2403
+ suggest: [{
2404
+ messageId: "suggestReplace",
2405
+ data: {
2406
+ className: cls,
2407
+ replacement
2408
+ },
2409
+ fix(fixer) {
2410
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
2411
+ }
2412
+ }]
2268
2413
  });
2269
2414
  }
2270
2415
  }
@@ -2284,6 +2429,7 @@ const maxClassCount = defineRule({
2284
2429
  properties: { max: { type: "number" } },
2285
2430
  additionalProperties: false
2286
2431
  }],
2432
+ defaultOptions: [{ max: DEFAULT_MAX }],
2287
2433
  messages: { tooMany: "Too many Tailwind classes ({{count}}). Maximum allowed is {{max}}. Consider extracting into a component or utility." }
2288
2434
  },
2289
2435
  createOnce(context) {
@@ -2453,9 +2599,12 @@ const enforceConsistentImportantPosition = defineRule({
2453
2599
  } },
2454
2600
  additionalProperties: false
2455
2601
  }],
2602
+ hasSuggestions: true,
2603
+ defaultOptions: [{ position: "suffix" }],
2456
2604
  messages: {
2457
2605
  usePrefix: "\"{{className}}\" uses suffix important. Use \"{{replacement}}\" (prefix) instead.",
2458
- useSuffix: "\"{{className}}\" uses prefix important. Use \"{{replacement}}\" (suffix) instead."
2606
+ useSuffix: "\"{{className}}\" uses prefix important. Use \"{{replacement}}\" (suffix) instead.",
2607
+ suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
2459
2608
  }
2460
2609
  },
2461
2610
  createOnce(context) {
@@ -2505,7 +2654,17 @@ const enforceConsistentImportantPosition = defineRule({
2505
2654
  data: {
2506
2655
  className: cls,
2507
2656
  replacement
2508
- }
2657
+ },
2658
+ suggest: [{
2659
+ messageId: "suggestReplace",
2660
+ data: {
2661
+ className: cls,
2662
+ replacement
2663
+ },
2664
+ fix(fixer) {
2665
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
2666
+ }
2667
+ }]
2509
2668
  });
2510
2669
  }
2511
2670
  }
@@ -2540,7 +2699,11 @@ const enforceNegativeArbitraryValues = defineRule({
2540
2699
  docs: { description: "Enforce moving the negative sign inside arbitrary value brackets: -top-[5px] → top-[-5px]" },
2541
2700
  fixable: "code",
2542
2701
  schema: [],
2543
- messages: { moveNegative: "\"{{className}}\" has the negative outside brackets. Use \"{{replacement}}\" instead." }
2702
+ hasSuggestions: true,
2703
+ messages: {
2704
+ moveNegative: "\"{{className}}\" has the negative outside brackets. Use \"{{replacement}}\" instead.",
2705
+ suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
2706
+ }
2544
2707
  },
2545
2708
  createOnce(context) {
2546
2709
  function check(locations) {
@@ -2576,7 +2739,17 @@ const enforceNegativeArbitraryValues = defineRule({
2576
2739
  data: {
2577
2740
  className: cls,
2578
2741
  replacement
2579
- }
2742
+ },
2743
+ suggest: [{
2744
+ messageId: "suggestReplace",
2745
+ data: {
2746
+ className: cls,
2747
+ replacement
2748
+ },
2749
+ fix(fixer) {
2750
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
2751
+ }
2752
+ }]
2580
2753
  });
2581
2754
  }
2582
2755
  }
@@ -2623,9 +2796,12 @@ const enforceConsistentVariableSyntax = defineRule({
2623
2796
  } },
2624
2797
  additionalProperties: false
2625
2798
  }],
2799
+ hasSuggestions: true,
2800
+ defaultOptions: [{ syntax: "shorthand" }],
2626
2801
  messages: {
2627
2802
  useShorthand: "\"{{className}}\" uses explicit var() syntax. Use \"{{replacement}}\" (shorthand) instead.",
2628
- useExplicit: "\"{{className}}\" uses shorthand syntax. Use \"{{replacement}}\" (explicit) instead."
2803
+ useExplicit: "\"{{className}}\" uses shorthand syntax. Use \"{{replacement}}\" (explicit) instead.",
2804
+ suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
2629
2805
  }
2630
2806
  },
2631
2807
  createOnce(context) {
@@ -2669,7 +2845,17 @@ const enforceConsistentVariableSyntax = defineRule({
2669
2845
  data: {
2670
2846
  className: cls,
2671
2847
  replacement
2672
- }
2848
+ },
2849
+ suggest: [{
2850
+ messageId: "suggestReplace",
2851
+ data: {
2852
+ className: cls,
2853
+ replacement
2854
+ },
2855
+ fix(fixer) {
2856
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
2857
+ }
2858
+ }]
2673
2859
  });
2674
2860
  }
2675
2861
  }
@@ -2737,6 +2923,7 @@ const noDarkWithoutLight = defineRule({
2737
2923
  } },
2738
2924
  additionalProperties: false
2739
2925
  }],
2926
+ defaultOptions: [{ variants: DEFAULT_VARIANTS }],
2740
2927
  messages: { missingBase: "\"{{className}}\" uses the {{variant}} variant, but there is no base \"{{prefix}}-*\" class on this element." }
2741
2928
  },
2742
2929
  createOnce(context) {
@@ -3019,7 +3206,11 @@ const consistentVariantOrder = defineRule({
3019
3206
  },
3020
3207
  additionalProperties: false
3021
3208
  }],
3022
- messages: { wrongOrder: "\"{{className}}\" has variants in wrong order. Use \"{{replacement}}\" instead." }
3209
+ hasSuggestions: true,
3210
+ messages: {
3211
+ wrongOrder: "\"{{className}}\" has variants in wrong order. Use \"{{replacement}}\" instead.",
3212
+ suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
3213
+ }
3023
3214
  },
3024
3215
  createOnce(context) {
3025
3216
  const getDS = createLazyLoader(context);
@@ -3108,84 +3299,17 @@ const consistentVariantOrder = defineRule({
3108
3299
  data: {
3109
3300
  className: cls,
3110
3301
  replacement
3111
- }
3112
- });
3113
- }
3114
- }
3115
- }
3116
- return createExtractorVisitors(context, check);
3117
- }
3118
- });
3119
- //#endregion
3120
- //#region src/rules/enforce-consistent-line-wrapping.ts
3121
- const DEFAULT_PRINT_WIDTH = 80;
3122
- const enforceConsistentLineWrapping = defineRule({
3123
- meta: {
3124
- type: "suggestion",
3125
- docs: { description: "Warn when a class string exceeds the configured print width" },
3126
- fixable: "whitespace",
3127
- schema: [{
3128
- type: "object",
3129
- properties: {
3130
- printWidth: { type: "number" },
3131
- classesPerLine: { type: "number" }
3132
- },
3133
- additionalProperties: false
3134
- }],
3135
- messages: {
3136
- tooLong: "Class string is {{length}} characters long, exceeding the print width of {{printWidth}}. Consider splitting into multiple lines or extracting into a component.",
3137
- tooManyPerLine: "Too many classes on a single line ({{count}}). Maximum allowed per line is {{max}}."
3138
- }
3139
- },
3140
- createOnce(context) {
3141
- let _printWidth = null;
3142
- function getPrintWidth() {
3143
- if (_printWidth === null) _printWidth = safeOptions(context)?.printWidth ?? DEFAULT_PRINT_WIDTH;
3144
- return _printWidth;
3145
- }
3146
- let _classesPerLine = null;
3147
- function getClassesPerLine() {
3148
- if (_classesPerLine === null) _classesPerLine = safeOptions(context)?.classesPerLine ?? void 0;
3149
- return _classesPerLine;
3150
- }
3151
- function check(locations) {
3152
- const printWidth = getPrintWidth();
3153
- const classesPerLine = getClassesPerLine();
3154
- for (const loc of locations) {
3155
- if (loc.value.length > printWidth) context.report({
3156
- node: loc.node,
3157
- messageId: "tooLong",
3158
- data: {
3159
- length: String(loc.value.length),
3160
- printWidth: String(printWidth)
3161
- }
3162
- });
3163
- if (classesPerLine !== void 0) {
3164
- const classes = splitClasses(loc.value);
3165
- if (classes.length > classesPerLine) if (loc.node.type === "TemplateElement") {
3166
- const chunks = [];
3167
- for (let i = 0; i < classes.length; i += classesPerLine) chunks.push(classes.slice(i, i + classesPerLine).join(" "));
3168
- const startCol = loc.node.loc?.start.column ?? 0;
3169
- const indent = " ".repeat(startCol);
3170
- const fixedValue = chunks.join("\n" + indent);
3171
- context.report({
3172
- node: loc.node,
3173
- messageId: "tooManyPerLine",
3302
+ },
3303
+ suggest: [{
3304
+ messageId: "suggestReplace",
3174
3305
  data: {
3175
- count: String(classes.length),
3176
- max: String(classesPerLine)
3306
+ className: cls,
3307
+ replacement
3177
3308
  },
3178
3309
  fix(fixer) {
3179
3310
  return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
3180
3311
  }
3181
- });
3182
- } else context.report({
3183
- node: loc.node,
3184
- messageId: "tooManyPerLine",
3185
- data: {
3186
- count: String(classes.length),
3187
- max: String(classesPerLine)
3188
- }
3312
+ }]
3189
3313
  });
3190
3314
  }
3191
3315
  }
@@ -3194,71 +3318,8 @@ const enforceConsistentLineWrapping = defineRule({
3194
3318
  }
3195
3319
  });
3196
3320
  //#endregion
3197
- //#region src/rules/no-unnecessary-arbitrary-value.ts
3198
- const noUnnecessaryArbitraryValue = defineRule({
3199
- meta: {
3200
- type: "suggestion",
3201
- docs: { description: "Disallow arbitrary values when a named Tailwind class produces the same CSS" },
3202
- fixable: "code",
3203
- schema: [{
3204
- type: "object",
3205
- properties: { entryPoint: { type: "string" } },
3206
- additionalProperties: false
3207
- }],
3208
- messages: { unnecessaryArbitrary: "\"{{className}}\" can be written as \"{{replacement}}\". Use the named class instead." }
3209
- },
3210
- createOnce(context) {
3211
- const getDS = createLazyLoader(context);
3212
- function check(locations) {
3213
- const ds = getDS();
3214
- if (!ds) return;
3215
- const { cache } = ds;
3216
- for (const loc of locations) {
3217
- const classes = splitClasses(loc.value);
3218
- const offending = [];
3219
- for (const cls of classes) {
3220
- if (!hasArbitraryValue(cls)) continue;
3221
- const { utility, variant } = splitUtilityAndVariant(cls);
3222
- const hasImportantPrefix = utility.startsWith("!");
3223
- const hasImportantSuffix = !hasImportantPrefix && utility.endsWith("!");
3224
- const bareUtility = hasImportantPrefix ? utility.slice(1) : hasImportantSuffix ? utility.slice(0, -1) : utility;
3225
- const named = cache.getNamedEquivalent(bareUtility);
3226
- if (!named) continue;
3227
- offending.push({
3228
- cls,
3229
- replacement: variant + (hasImportantPrefix ? "!" : "") + named + (hasImportantSuffix ? "!" : "")
3230
- });
3231
- }
3232
- if (offending.length === 0) continue;
3233
- const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
3234
- const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls).join(" ");
3235
- for (let i = 0; i < offending.length; i++) {
3236
- const { cls, replacement } = offending[i];
3237
- if (i === 0) context.report({
3238
- node: loc.node,
3239
- messageId: "unnecessaryArbitrary",
3240
- data: {
3241
- className: cls,
3242
- replacement
3243
- },
3244
- fix(fixer) {
3245
- return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
3246
- }
3247
- });
3248
- else context.report({
3249
- node: loc.node,
3250
- messageId: "unnecessaryArbitrary",
3251
- data: {
3252
- className: cls,
3253
- replacement
3254
- }
3255
- });
3256
- }
3257
- }
3258
- }
3259
- return createExtractorVisitors(context, check);
3260
- }
3261
- });
3321
+ //#region src/rules/enforce-consistent-line-wrapping.ts
3322
+ const DEFAULT_PRINT_WIDTH = 80;
3262
3323
  //#endregion
3263
3324
  //#region src/index.ts
3264
3325
  const plugin = definePlugin({
@@ -3284,8 +3345,159 @@ const plugin = definePlugin({
3284
3345
  "no-hardcoded-colors": noHardcodedColors,
3285
3346
  "no-contradicting-variants": noContradictingVariants,
3286
3347
  "consistent-variant-order": consistentVariantOrder,
3287
- "enforce-consistent-line-wrapping": enforceConsistentLineWrapping,
3288
- "no-unnecessary-arbitrary-value": noUnnecessaryArbitraryValue
3348
+ "enforce-consistent-line-wrapping": defineRule({
3349
+ meta: {
3350
+ type: "suggestion",
3351
+ docs: { description: "Warn when a class string exceeds the configured print width" },
3352
+ fixable: "whitespace",
3353
+ schema: [{
3354
+ type: "object",
3355
+ properties: {
3356
+ printWidth: { type: "number" },
3357
+ classesPerLine: { type: "number" }
3358
+ },
3359
+ additionalProperties: false
3360
+ }],
3361
+ defaultOptions: [{ printWidth: DEFAULT_PRINT_WIDTH }],
3362
+ messages: {
3363
+ tooLong: "Class string is {{length}} characters long, exceeding the print width of {{printWidth}}. Consider splitting into multiple lines or extracting into a component.",
3364
+ tooManyPerLine: "Too many classes on a single line ({{count}}). Maximum allowed per line is {{max}}."
3365
+ }
3366
+ },
3367
+ createOnce(context) {
3368
+ let _printWidth = null;
3369
+ function getPrintWidth() {
3370
+ if (_printWidth === null) _printWidth = safeOptions(context)?.printWidth ?? DEFAULT_PRINT_WIDTH;
3371
+ return _printWidth;
3372
+ }
3373
+ let _classesPerLine = null;
3374
+ function getClassesPerLine() {
3375
+ if (_classesPerLine === null) _classesPerLine = safeOptions(context)?.classesPerLine ?? void 0;
3376
+ return _classesPerLine;
3377
+ }
3378
+ function check(locations) {
3379
+ const printWidth = getPrintWidth();
3380
+ const classesPerLine = getClassesPerLine();
3381
+ for (const loc of locations) {
3382
+ if (loc.value.length > printWidth) context.report({
3383
+ node: loc.node,
3384
+ messageId: "tooLong",
3385
+ data: {
3386
+ length: String(loc.value.length),
3387
+ printWidth: String(printWidth)
3388
+ }
3389
+ });
3390
+ if (classesPerLine !== void 0) {
3391
+ const classes = splitClasses(loc.value);
3392
+ if (classes.length > classesPerLine) if (loc.node.type === "TemplateElement") {
3393
+ const chunks = [];
3394
+ for (let i = 0; i < classes.length; i += classesPerLine) chunks.push(classes.slice(i, i + classesPerLine).join(" "));
3395
+ const startCol = loc.node.loc?.start.column ?? 0;
3396
+ const indent = " ".repeat(startCol);
3397
+ const fixedValue = chunks.join("\n" + indent);
3398
+ context.report({
3399
+ node: loc.node,
3400
+ messageId: "tooManyPerLine",
3401
+ data: {
3402
+ count: String(classes.length),
3403
+ max: String(classesPerLine)
3404
+ },
3405
+ fix(fixer) {
3406
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
3407
+ }
3408
+ });
3409
+ } else context.report({
3410
+ node: loc.node,
3411
+ messageId: "tooManyPerLine",
3412
+ data: {
3413
+ count: String(classes.length),
3414
+ max: String(classesPerLine)
3415
+ }
3416
+ });
3417
+ }
3418
+ }
3419
+ }
3420
+ return createExtractorVisitors(context, check);
3421
+ }
3422
+ }),
3423
+ "no-unnecessary-arbitrary-value": defineRule({
3424
+ meta: {
3425
+ type: "suggestion",
3426
+ docs: { description: "Disallow arbitrary values when a named Tailwind class produces the same CSS" },
3427
+ fixable: "code",
3428
+ schema: [{
3429
+ type: "object",
3430
+ properties: { entryPoint: { type: "string" } },
3431
+ additionalProperties: false
3432
+ }],
3433
+ hasSuggestions: true,
3434
+ messages: {
3435
+ unnecessaryArbitrary: "\"{{className}}\" can be written as \"{{replacement}}\". Use the named class instead.",
3436
+ suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
3437
+ }
3438
+ },
3439
+ createOnce(context) {
3440
+ const getDS = createLazyLoader(context);
3441
+ function check(locations) {
3442
+ const ds = getDS();
3443
+ if (!ds) return;
3444
+ const { cache } = ds;
3445
+ for (const loc of locations) {
3446
+ const classes = splitClasses(loc.value);
3447
+ const offending = [];
3448
+ for (const cls of classes) {
3449
+ if (!hasArbitraryValue(cls)) continue;
3450
+ const { utility, variant } = splitUtilityAndVariant(cls);
3451
+ const hasImportantPrefix = utility.startsWith("!");
3452
+ const hasImportantSuffix = !hasImportantPrefix && utility.endsWith("!");
3453
+ const bareUtility = hasImportantPrefix ? utility.slice(1) : hasImportantSuffix ? utility.slice(0, -1) : utility;
3454
+ const named = cache.getNamedEquivalent(bareUtility);
3455
+ if (!named) continue;
3456
+ offending.push({
3457
+ cls,
3458
+ replacement: variant + (hasImportantPrefix ? "!" : "") + named + (hasImportantSuffix ? "!" : "")
3459
+ });
3460
+ }
3461
+ if (offending.length === 0) continue;
3462
+ const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
3463
+ const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls).join(" ");
3464
+ for (let i = 0; i < offending.length; i++) {
3465
+ const { cls, replacement } = offending[i];
3466
+ if (i === 0) context.report({
3467
+ node: loc.node,
3468
+ messageId: "unnecessaryArbitrary",
3469
+ data: {
3470
+ className: cls,
3471
+ replacement
3472
+ },
3473
+ fix(fixer) {
3474
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
3475
+ }
3476
+ });
3477
+ else context.report({
3478
+ node: loc.node,
3479
+ messageId: "unnecessaryArbitrary",
3480
+ data: {
3481
+ className: cls,
3482
+ replacement
3483
+ },
3484
+ suggest: [{
3485
+ messageId: "suggestReplace",
3486
+ data: {
3487
+ className: cls,
3488
+ replacement
3489
+ },
3490
+ fix(fixer) {
3491
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
3492
+ }
3493
+ }]
3494
+ });
3495
+ }
3496
+ }
3497
+ }
3498
+ return createExtractorVisitors(context, check);
3499
+ }
3500
+ })
3289
3501
  }
3290
3502
  });
3291
3503
  //#endregion