oxlint-tailwindcss 0.4.1 → 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
@@ -1273,19 +1273,73 @@ function autoDetectEntryPoint(filePath) {
1273
1273
  return null;
1274
1274
  }
1275
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
1276
1304
  //#region src/design-system/loader.ts
1277
1305
  const dsCache = /* @__PURE__ */ new Map();
1278
1306
  const autoDetectCache = /* @__PURE__ */ new Map();
1279
1307
  let lastLoadedPath = null;
1280
1308
  /**
1281
1309
  * Extracts `entryPoint` from `context.settings.tailwindcss`.
1310
+ * Supports both `string` and `string[]` (for monorepos).
1282
1311
  */
1283
1312
  function entryPointFromSettings(settings) {
1284
1313
  const tw = settings?.tailwindcss;
1285
1314
  if (tw && typeof tw === "object" && "entryPoint" in tw) {
1286
1315
  const ep = tw.entryPoint;
1287
1316
  if (typeof ep === "string") return ep;
1317
+ if (Array.isArray(ep) && ep.length > 0 && ep.every((e) => typeof e === "string")) return ep;
1318
+ }
1319
+ }
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
+ }
1288
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;
1289
1343
  }
1290
1344
  /**
1291
1345
  * Extracts `timeout` from `context.settings.tailwindcss`.
@@ -1321,7 +1375,8 @@ function cachedAutoDetect(filePath) {
1321
1375
  * Resolution order: rule option `entryPoint` > `settings.tailwindcss.entryPoint` > auto-detect.
1322
1376
  */
1323
1377
  function getLoadedDesignSystem(entryPoint, settings, filePath) {
1324
- const explicitEntry = entryPoint ?? entryPointFromSettings(settings);
1378
+ const settingsEntry = entryPointFromSettings(settings);
1379
+ const explicitEntry = entryPoint ?? (Array.isArray(settingsEntry) ? resolveClosestEntryPoint(settingsEntry, filePath) : settingsEntry);
1325
1380
  const cssPath = explicitEntry ?? cachedAutoDetect(filePath) ?? lastLoadedPath;
1326
1381
  if (!cssPath) return null;
1327
1382
  const resolvedPath = resolve(cssPath);
@@ -1342,7 +1397,7 @@ function getLoadedDesignSystem(entryPoint, settings, filePath) {
1342
1397
  cache,
1343
1398
  mtime
1344
1399
  });
1345
- console.error(`[oxlint-tailwindcss] Loaded design system from "${resolvedPath}"`);
1400
+ debugLog(`Loaded design system from "${resolvedPath}"`);
1346
1401
  if (explicitEntry) lastLoadedPath = resolvedPath;
1347
1402
  return {
1348
1403
  cache,
@@ -1367,6 +1422,7 @@ function createLazyLoader(context) {
1367
1422
  let lastResult = null;
1368
1423
  let fixedEntryResolved = false;
1369
1424
  let fixedResult = null;
1425
+ let debugInitialized = false;
1370
1426
  return () => {
1371
1427
  let entryPoint;
1372
1428
  try {
@@ -1380,16 +1436,31 @@ function createLazyLoader(context) {
1380
1436
  try {
1381
1437
  filePath = context.filename;
1382
1438
  } catch {}
1383
- 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);
1384
1445
  if (fixedEntry) {
1385
1446
  if (fixedEntryResolved) return fixedResult;
1386
1447
  fixedEntryResolved = true;
1387
1448
  fixedResult = getLoadedDesignSystem(fixedEntry, settings, filePath);
1449
+ if (fixedResult && filePath) debugLog(`${relative(process.cwd(), filePath)} → ${relative(process.cwd(), fixedResult.entryPoint)}`);
1388
1450
  return fixedResult;
1389
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
+ }
1390
1460
  if (filePath && filePath === lastFilePath) return lastResult;
1391
1461
  if (filePath) lastFilePath = filePath;
1392
1462
  lastResult = getLoadedDesignSystem(void 0, settings, filePath);
1463
+ if (lastResult && filePath) debugLog(`${relative(process.cwd(), filePath)} → ${relative(process.cwd(), lastResult.entryPoint)}`);
1393
1464
  return lastResult;
1394
1465
  };
1395
1466
  }
@@ -1440,7 +1511,11 @@ const noDeprecatedClasses = defineRule({
1440
1511
  properties: { entryPoint: { type: "string" } },
1441
1512
  additionalProperties: false
1442
1513
  }],
1443
- 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
+ }
1444
1519
  },
1445
1520
  createOnce(context) {
1446
1521
  const getDS = createLazyLoader(context);
@@ -1488,7 +1563,17 @@ const noDeprecatedClasses = defineRule({
1488
1563
  data: {
1489
1564
  className: cls,
1490
1565
  replacement
1491
- }
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
+ }]
1492
1577
  });
1493
1578
  }
1494
1579
  }
@@ -1517,9 +1602,15 @@ const noUnknownClasses = defineRule({
1517
1602
  },
1518
1603
  additionalProperties: false
1519
1604
  }],
1605
+ hasSuggestions: true,
1606
+ defaultOptions: [{
1607
+ allowlist: [],
1608
+ ignorePrefixes: []
1609
+ }],
1520
1610
  messages: {
1521
1611
  unknown: "\"{{className}}\" is not a valid Tailwind class.",
1522
- 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}}\"."
1523
1614
  }
1524
1615
  },
1525
1616
  createOnce(context) {
@@ -1560,15 +1651,27 @@ const noUnknownClasses = defineRule({
1560
1651
  if (cache.isValid(stripped)) continue;
1561
1652
  if (DEPRECATED_MAP[stripped]) continue;
1562
1653
  const suggestion = findBestSuggestion(stripped, cache.validClasses);
1563
- if (suggestion) context.report({
1564
- node: loc.node,
1565
- messageId: "unknownWithSuggestion",
1566
- data: {
1567
- className: cls,
1568
- suggestion
1569
- }
1570
- });
1571
- 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({
1572
1675
  node: loc.node,
1573
1676
  messageId: "unknown",
1574
1677
  data: { className: cls }
@@ -1690,7 +1793,11 @@ const enforceCanonical = defineRule({
1690
1793
  properties: { entryPoint: { type: "string" } },
1691
1794
  additionalProperties: false
1692
1795
  }],
1693
- 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
+ }
1694
1801
  },
1695
1802
  createOnce(context) {
1696
1803
  const getDS = createLazyLoader(context);
@@ -1720,14 +1827,27 @@ const enforceCanonical = defineRule({
1720
1827
  return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
1721
1828
  }
1722
1829
  });
1723
- } else context.report({
1724
- node: loc.node,
1725
- messageId: "nonCanonical",
1726
- data: {
1727
- className: cls,
1728
- canonical
1729
- }
1730
- });
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
+ }
1731
1851
  }
1732
1852
  }
1733
1853
  }
@@ -2149,7 +2269,11 @@ const enforceLogical = defineRule({
2149
2269
  docs: { description: "Enforce logical (RTL-friendly) Tailwind CSS properties instead of physical ones" },
2150
2270
  fixable: "code",
2151
2271
  schema: [],
2152
- 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
+ }
2153
2277
  },
2154
2278
  createOnce(context) {
2155
2279
  function convertClass(cls) {
@@ -2196,7 +2320,17 @@ const enforceLogical = defineRule({
2196
2320
  data: {
2197
2321
  className: cls,
2198
2322
  replacement
2199
- }
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
+ }]
2200
2334
  });
2201
2335
  }
2202
2336
  }
@@ -2214,7 +2348,11 @@ const enforcePhysical = defineRule({
2214
2348
  docs: { description: "Enforce physical Tailwind CSS properties instead of logical ones for consistency in LTR-only projects" },
2215
2349
  fixable: "code",
2216
2350
  schema: [],
2217
- 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
+ }
2218
2356
  },
2219
2357
  createOnce(context) {
2220
2358
  function convertClass(cls) {
@@ -2261,7 +2399,17 @@ const enforcePhysical = defineRule({
2261
2399
  data: {
2262
2400
  className: cls,
2263
2401
  replacement
2264
- }
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
+ }]
2265
2413
  });
2266
2414
  }
2267
2415
  }
@@ -2281,6 +2429,7 @@ const maxClassCount = defineRule({
2281
2429
  properties: { max: { type: "number" } },
2282
2430
  additionalProperties: false
2283
2431
  }],
2432
+ defaultOptions: [{ max: DEFAULT_MAX }],
2284
2433
  messages: { tooMany: "Too many Tailwind classes ({{count}}). Maximum allowed is {{max}}. Consider extracting into a component or utility." }
2285
2434
  },
2286
2435
  createOnce(context) {
@@ -2450,9 +2599,12 @@ const enforceConsistentImportantPosition = defineRule({
2450
2599
  } },
2451
2600
  additionalProperties: false
2452
2601
  }],
2602
+ hasSuggestions: true,
2603
+ defaultOptions: [{ position: "suffix" }],
2453
2604
  messages: {
2454
2605
  usePrefix: "\"{{className}}\" uses suffix important. Use \"{{replacement}}\" (prefix) instead.",
2455
- 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}}\"."
2456
2608
  }
2457
2609
  },
2458
2610
  createOnce(context) {
@@ -2502,7 +2654,17 @@ const enforceConsistentImportantPosition = defineRule({
2502
2654
  data: {
2503
2655
  className: cls,
2504
2656
  replacement
2505
- }
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
+ }]
2506
2668
  });
2507
2669
  }
2508
2670
  }
@@ -2537,7 +2699,11 @@ const enforceNegativeArbitraryValues = defineRule({
2537
2699
  docs: { description: "Enforce moving the negative sign inside arbitrary value brackets: -top-[5px] → top-[-5px]" },
2538
2700
  fixable: "code",
2539
2701
  schema: [],
2540
- 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
+ }
2541
2707
  },
2542
2708
  createOnce(context) {
2543
2709
  function check(locations) {
@@ -2573,7 +2739,17 @@ const enforceNegativeArbitraryValues = defineRule({
2573
2739
  data: {
2574
2740
  className: cls,
2575
2741
  replacement
2576
- }
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
+ }]
2577
2753
  });
2578
2754
  }
2579
2755
  }
@@ -2620,9 +2796,12 @@ const enforceConsistentVariableSyntax = defineRule({
2620
2796
  } },
2621
2797
  additionalProperties: false
2622
2798
  }],
2799
+ hasSuggestions: true,
2800
+ defaultOptions: [{ syntax: "shorthand" }],
2623
2801
  messages: {
2624
2802
  useShorthand: "\"{{className}}\" uses explicit var() syntax. Use \"{{replacement}}\" (shorthand) instead.",
2625
- 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}}\"."
2626
2805
  }
2627
2806
  },
2628
2807
  createOnce(context) {
@@ -2666,7 +2845,17 @@ const enforceConsistentVariableSyntax = defineRule({
2666
2845
  data: {
2667
2846
  className: cls,
2668
2847
  replacement
2669
- }
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
+ }]
2670
2859
  });
2671
2860
  }
2672
2861
  }
@@ -2734,6 +2923,7 @@ const noDarkWithoutLight = defineRule({
2734
2923
  } },
2735
2924
  additionalProperties: false
2736
2925
  }],
2926
+ defaultOptions: [{ variants: DEFAULT_VARIANTS }],
2737
2927
  messages: { missingBase: "\"{{className}}\" uses the {{variant}} variant, but there is no base \"{{prefix}}-*\" class on this element." }
2738
2928
  },
2739
2929
  createOnce(context) {
@@ -3016,7 +3206,11 @@ const consistentVariantOrder = defineRule({
3016
3206
  },
3017
3207
  additionalProperties: false
3018
3208
  }],
3019
- 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
+ }
3020
3214
  },
3021
3215
  createOnce(context) {
3022
3216
  const getDS = createLazyLoader(context);
@@ -3105,84 +3299,17 @@ const consistentVariantOrder = defineRule({
3105
3299
  data: {
3106
3300
  className: cls,
3107
3301
  replacement
3108
- }
3109
- });
3110
- }
3111
- }
3112
- }
3113
- return createExtractorVisitors(context, check);
3114
- }
3115
- });
3116
- //#endregion
3117
- //#region src/rules/enforce-consistent-line-wrapping.ts
3118
- const DEFAULT_PRINT_WIDTH = 80;
3119
- const enforceConsistentLineWrapping = defineRule({
3120
- meta: {
3121
- type: "suggestion",
3122
- docs: { description: "Warn when a class string exceeds the configured print width" },
3123
- fixable: "whitespace",
3124
- schema: [{
3125
- type: "object",
3126
- properties: {
3127
- printWidth: { type: "number" },
3128
- classesPerLine: { type: "number" }
3129
- },
3130
- additionalProperties: false
3131
- }],
3132
- messages: {
3133
- tooLong: "Class string is {{length}} characters long, exceeding the print width of {{printWidth}}. Consider splitting into multiple lines or extracting into a component.",
3134
- tooManyPerLine: "Too many classes on a single line ({{count}}). Maximum allowed per line is {{max}}."
3135
- }
3136
- },
3137
- createOnce(context) {
3138
- let _printWidth = null;
3139
- function getPrintWidth() {
3140
- if (_printWidth === null) _printWidth = safeOptions(context)?.printWidth ?? DEFAULT_PRINT_WIDTH;
3141
- return _printWidth;
3142
- }
3143
- let _classesPerLine = null;
3144
- function getClassesPerLine() {
3145
- if (_classesPerLine === null) _classesPerLine = safeOptions(context)?.classesPerLine ?? void 0;
3146
- return _classesPerLine;
3147
- }
3148
- function check(locations) {
3149
- const printWidth = getPrintWidth();
3150
- const classesPerLine = getClassesPerLine();
3151
- for (const loc of locations) {
3152
- if (loc.value.length > printWidth) context.report({
3153
- node: loc.node,
3154
- messageId: "tooLong",
3155
- data: {
3156
- length: String(loc.value.length),
3157
- printWidth: String(printWidth)
3158
- }
3159
- });
3160
- if (classesPerLine !== void 0) {
3161
- const classes = splitClasses(loc.value);
3162
- if (classes.length > classesPerLine) if (loc.node.type === "TemplateElement") {
3163
- const chunks = [];
3164
- for (let i = 0; i < classes.length; i += classesPerLine) chunks.push(classes.slice(i, i + classesPerLine).join(" "));
3165
- const startCol = loc.node.loc?.start.column ?? 0;
3166
- const indent = " ".repeat(startCol);
3167
- const fixedValue = chunks.join("\n" + indent);
3168
- context.report({
3169
- node: loc.node,
3170
- messageId: "tooManyPerLine",
3302
+ },
3303
+ suggest: [{
3304
+ messageId: "suggestReplace",
3171
3305
  data: {
3172
- count: String(classes.length),
3173
- max: String(classesPerLine)
3306
+ className: cls,
3307
+ replacement
3174
3308
  },
3175
3309
  fix(fixer) {
3176
3310
  return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
3177
3311
  }
3178
- });
3179
- } else context.report({
3180
- node: loc.node,
3181
- messageId: "tooManyPerLine",
3182
- data: {
3183
- count: String(classes.length),
3184
- max: String(classesPerLine)
3185
- }
3312
+ }]
3186
3313
  });
3187
3314
  }
3188
3315
  }
@@ -3191,71 +3318,8 @@ const enforceConsistentLineWrapping = defineRule({
3191
3318
  }
3192
3319
  });
3193
3320
  //#endregion
3194
- //#region src/rules/no-unnecessary-arbitrary-value.ts
3195
- const noUnnecessaryArbitraryValue = defineRule({
3196
- meta: {
3197
- type: "suggestion",
3198
- docs: { description: "Disallow arbitrary values when a named Tailwind class produces the same CSS" },
3199
- fixable: "code",
3200
- schema: [{
3201
- type: "object",
3202
- properties: { entryPoint: { type: "string" } },
3203
- additionalProperties: false
3204
- }],
3205
- messages: { unnecessaryArbitrary: "\"{{className}}\" can be written as \"{{replacement}}\". Use the named class instead." }
3206
- },
3207
- createOnce(context) {
3208
- const getDS = createLazyLoader(context);
3209
- function check(locations) {
3210
- const ds = getDS();
3211
- if (!ds) return;
3212
- const { cache } = ds;
3213
- for (const loc of locations) {
3214
- const classes = splitClasses(loc.value);
3215
- const offending = [];
3216
- for (const cls of classes) {
3217
- if (!hasArbitraryValue(cls)) continue;
3218
- const { utility, variant } = splitUtilityAndVariant(cls);
3219
- const hasImportantPrefix = utility.startsWith("!");
3220
- const hasImportantSuffix = !hasImportantPrefix && utility.endsWith("!");
3221
- const bareUtility = hasImportantPrefix ? utility.slice(1) : hasImportantSuffix ? utility.slice(0, -1) : utility;
3222
- const named = cache.getNamedEquivalent(bareUtility);
3223
- if (!named) continue;
3224
- offending.push({
3225
- cls,
3226
- replacement: variant + (hasImportantPrefix ? "!" : "") + named + (hasImportantSuffix ? "!" : "")
3227
- });
3228
- }
3229
- if (offending.length === 0) continue;
3230
- const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
3231
- const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls).join(" ");
3232
- for (let i = 0; i < offending.length; i++) {
3233
- const { cls, replacement } = offending[i];
3234
- if (i === 0) context.report({
3235
- node: loc.node,
3236
- messageId: "unnecessaryArbitrary",
3237
- data: {
3238
- className: cls,
3239
- replacement
3240
- },
3241
- fix(fixer) {
3242
- return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
3243
- }
3244
- });
3245
- else context.report({
3246
- node: loc.node,
3247
- messageId: "unnecessaryArbitrary",
3248
- data: {
3249
- className: cls,
3250
- replacement
3251
- }
3252
- });
3253
- }
3254
- }
3255
- }
3256
- return createExtractorVisitors(context, check);
3257
- }
3258
- });
3321
+ //#region src/rules/enforce-consistent-line-wrapping.ts
3322
+ const DEFAULT_PRINT_WIDTH = 80;
3259
3323
  //#endregion
3260
3324
  //#region src/index.ts
3261
3325
  const plugin = definePlugin({
@@ -3281,8 +3345,159 @@ const plugin = definePlugin({
3281
3345
  "no-hardcoded-colors": noHardcodedColors,
3282
3346
  "no-contradicting-variants": noContradictingVariants,
3283
3347
  "consistent-variant-order": consistentVariantOrder,
3284
- "enforce-consistent-line-wrapping": enforceConsistentLineWrapping,
3285
- "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
+ })
3286
3501
  }
3287
3502
  });
3288
3503
  //#endregion