oxlint-tailwindcss 0.1.5 → 0.1.7
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 +24 -6
- package/dist/index.cjs +586 -113
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +586 -113
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { createHash } from "node:crypto";
|
|
|
4
4
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
|
+
import { Worker } from "node:worker_threads";
|
|
7
8
|
//#region src/utils/extractors.ts
|
|
8
9
|
/**
|
|
9
10
|
* Preserves leading/trailing spaces in fixed class strings for template literals.
|
|
@@ -514,12 +515,18 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
514
515
|
variantOrderMap = /* @__PURE__ */ new Map();
|
|
515
516
|
arbitraryEquivMap = /* @__PURE__ */ new Map();
|
|
516
517
|
_validClasses = [];
|
|
518
|
+
_knownPrefixes = null;
|
|
519
|
+
_maxOrder = 0n;
|
|
517
520
|
static fromPrecomputed(data) {
|
|
518
521
|
const cache = new DesignSystemCache();
|
|
519
522
|
cache._validClasses = data.validClasses;
|
|
520
523
|
for (const cls of data.validClasses) cache.validitySet.add(cls);
|
|
521
524
|
for (const [from, to] of Object.entries(data.canonical)) cache.canonicalMap.set(from, roundRemValue(to));
|
|
522
|
-
for (const [cls, val] of Object.entries(data.order))
|
|
525
|
+
for (const [cls, val] of Object.entries(data.order)) {
|
|
526
|
+
const order = BigInt(val);
|
|
527
|
+
cache.orderMap.set(cls, order);
|
|
528
|
+
if (order > cache._maxOrder) cache._maxOrder = order;
|
|
529
|
+
}
|
|
523
530
|
for (const [cls, props] of Object.entries(data.cssProps)) cache.cssPropsMap.set(cls, props);
|
|
524
531
|
if (data.variantOrder) for (const [name, index] of Object.entries(data.variantOrder)) cache.variantOrderMap.set(name, index);
|
|
525
532
|
if (data.componentClasses) for (const cls of data.componentClasses) cache.validitySet.add(cls);
|
|
@@ -544,27 +551,116 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
544
551
|
}
|
|
545
552
|
return className;
|
|
546
553
|
}
|
|
554
|
+
/**
|
|
555
|
+
* Resolve a variant name to its priority in the CSS output order.
|
|
556
|
+
* Named variants use the precomputed map. Arbitrary variants use pattern-based heuristics
|
|
557
|
+
* to approximate their position relative to named variants.
|
|
558
|
+
*/
|
|
559
|
+
resolveVariantPriority(variant) {
|
|
560
|
+
const direct = this.variantOrderMap.get(variant);
|
|
561
|
+
if (direct !== void 0) return direct;
|
|
562
|
+
if (variant.includes("/")) {
|
|
563
|
+
const stripped = variant.slice(0, variant.indexOf("/"));
|
|
564
|
+
const p = this.variantOrderMap.get(stripped);
|
|
565
|
+
if (p !== void 0) return p;
|
|
566
|
+
}
|
|
567
|
+
if (variant.startsWith("group-") || variant.startsWith("peer-")) {
|
|
568
|
+
const prefix = variant.startsWith("group-") ? "group-" : "peer-";
|
|
569
|
+
const inner = variant.slice(prefix.length);
|
|
570
|
+
const innerClean = inner.includes("/") ? inner.slice(0, inner.indexOf("/")) : inner;
|
|
571
|
+
return this.resolveVariantPriority(innerClean);
|
|
572
|
+
}
|
|
573
|
+
if (variant.startsWith("data-")) return this.variantOrderMap.get("data-open") ?? 121;
|
|
574
|
+
if (variant.startsWith("[")) return (this.variantOrderMap.get("data-ending-style") ?? 124) + 10;
|
|
575
|
+
if (variant.startsWith("has-") || variant.startsWith("not-") || variant.startsWith("in-")) return (this.variantOrderMap.get("inert") ?? 48) + 1;
|
|
576
|
+
if (variant.startsWith("aria-")) return (this.variantOrderMap.get("inert") ?? 48) + 2;
|
|
577
|
+
return 0;
|
|
578
|
+
}
|
|
579
|
+
/** Find the order of the first class matching a prefix (e.g. "max-w-" → order of "max-w-0") */
|
|
580
|
+
findOrderByPrefix(prefix) {
|
|
581
|
+
const withoutDash = prefix.endsWith("-") ? prefix.slice(0, -1) : null;
|
|
582
|
+
if (withoutDash) {
|
|
583
|
+
const order = this.orderMap.get(withoutDash);
|
|
584
|
+
if (order != null) return order;
|
|
585
|
+
}
|
|
586
|
+
for (const [cls, order] of this.orderMap) if (cls.startsWith(prefix) && order != null) return order;
|
|
587
|
+
}
|
|
588
|
+
getKnownPrefixes() {
|
|
589
|
+
if (!this._knownPrefixes) {
|
|
590
|
+
this._knownPrefixes = /* @__PURE__ */ new Set();
|
|
591
|
+
for (const cls of this._validClasses) {
|
|
592
|
+
const dash = cls.lastIndexOf("-");
|
|
593
|
+
if (dash > 0) this._knownPrefixes.add(cls.slice(0, dash));
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
return this._knownPrefixes;
|
|
597
|
+
}
|
|
547
598
|
isValid(className) {
|
|
548
599
|
if (this.validitySet.has(className)) return true;
|
|
549
600
|
const utility = extractUtility(className);
|
|
550
601
|
if (utility !== className && this.validitySet.has(utility)) return true;
|
|
602
|
+
const { bare } = stripImportant(utility);
|
|
603
|
+
if (bare !== utility && this.validitySet.has(bare)) return true;
|
|
604
|
+
const slashIdx = bare.lastIndexOf("/");
|
|
605
|
+
if (slashIdx > 0) {
|
|
606
|
+
const base = bare.slice(0, slashIdx);
|
|
607
|
+
if (this.validitySet.has(base)) return true;
|
|
608
|
+
if (/^(.+)-(\d+\.?\d*)$/.test(base)) {
|
|
609
|
+
const dashIdx = base.lastIndexOf("-");
|
|
610
|
+
if (dashIdx > 0 && this.getKnownPrefixes().has(base.slice(0, dashIdx))) return true;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
const numericMatch = /^(.+)-(\d+\.?\d*)$/.exec(bare);
|
|
614
|
+
if (numericMatch && this.getKnownPrefixes().has(numericMatch[1])) return true;
|
|
551
615
|
if (hasArbitraryValue(className)) return true;
|
|
616
|
+
if (bare.includes("(") && bare.includes(")")) return true;
|
|
552
617
|
return false;
|
|
553
618
|
}
|
|
554
619
|
getOrder(className) {
|
|
555
620
|
const cached = this.orderMap.get(className);
|
|
556
621
|
if (cached !== void 0) return cached;
|
|
557
622
|
const utility = extractUtility(className);
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
623
|
+
const hasVariant = utility !== className;
|
|
624
|
+
let baseOrder = this.orderMap.get(utility) ?? void 0;
|
|
625
|
+
if (baseOrder === void 0) {
|
|
626
|
+
const { bare, important } = stripImportant(utility);
|
|
627
|
+
if (important) baseOrder = this.orderMap.get(bare) ?? void 0;
|
|
561
628
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
629
|
+
if (baseOrder === void 0) {
|
|
630
|
+
const slashIdx = utility.lastIndexOf("/");
|
|
631
|
+
if (slashIdx > 0) {
|
|
632
|
+
const base = utility.slice(0, slashIdx);
|
|
633
|
+
baseOrder = this.orderMap.get(base) ?? void 0;
|
|
634
|
+
if (baseOrder === void 0) {
|
|
635
|
+
const { bare, important } = stripImportant(base);
|
|
636
|
+
if (important) baseOrder = this.orderMap.get(bare) ?? void 0;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
566
639
|
}
|
|
567
|
-
|
|
640
|
+
if (baseOrder === void 0) {
|
|
641
|
+
const stripped = stripImportant(utility).bare;
|
|
642
|
+
const bracketIdx = stripped.indexOf("[");
|
|
643
|
+
if (bracketIdx > 0) {
|
|
644
|
+
const prefix = stripped.slice(0, bracketIdx);
|
|
645
|
+
baseOrder = this.findOrderByPrefix(prefix);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (baseOrder === void 0) {
|
|
649
|
+
const stripped = stripImportant(utility).bare;
|
|
650
|
+
const parenIdx = stripped.indexOf("(");
|
|
651
|
+
if (parenIdx > 0) {
|
|
652
|
+
const prefix = stripped.slice(0, parenIdx);
|
|
653
|
+
baseOrder = this.findOrderByPrefix(prefix);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (baseOrder === void 0) return null;
|
|
657
|
+
if (!hasVariant) return baseOrder;
|
|
658
|
+
const variants = extractVariants(className);
|
|
659
|
+
const firstPriority = this.resolveVariantPriority(variants[0]) + 1;
|
|
660
|
+
let subPriority = 0;
|
|
661
|
+
for (let i = 1; i < variants.length; i++) subPriority += this.resolveVariantPriority(variants[i]) + 1;
|
|
662
|
+
const bucketSize = this._maxOrder + 1n;
|
|
663
|
+
return BigInt(firstPriority) * 1000n * bucketSize + BigInt(subPriority) * bucketSize + baseOrder;
|
|
568
664
|
}
|
|
569
665
|
getClassOrder(classes) {
|
|
570
666
|
return classes.map((cls) => [cls, this.getOrder(cls)]);
|
|
@@ -606,18 +702,58 @@ const { __unstable__loadDesignSystem } = require('@tailwindcss/node');
|
|
|
606
702
|
const { readFileSync } = require('fs');
|
|
607
703
|
const { dirname, resolve } = require('path');
|
|
608
704
|
|
|
705
|
+
function resolveImport(specifier, baseDir) {
|
|
706
|
+
// Relative import: ./file.css, ../file.css
|
|
707
|
+
if (specifier.startsWith('.')) return resolve(baseDir, specifier);
|
|
708
|
+
// Package import: tw-animate-css, @scope/pkg
|
|
709
|
+
const { join } = require('path');
|
|
710
|
+
const { existsSync } = require('fs');
|
|
711
|
+
// Walk up to find node_modules (monorepo support)
|
|
712
|
+
let dir = baseDir;
|
|
713
|
+
while (true) {
|
|
714
|
+
const pkgDir = join(dir, 'node_modules', specifier);
|
|
715
|
+
if (existsSync(pkgDir)) {
|
|
716
|
+
// Read package.json to find CSS entry (main, style, exports.style)
|
|
717
|
+
try {
|
|
718
|
+
const pkg = JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf-8'));
|
|
719
|
+
const entry = pkg.style || pkg.main || '';
|
|
720
|
+
if (entry.endsWith('.css')) return resolve(pkgDir, entry);
|
|
721
|
+
// Check exports["."].style
|
|
722
|
+
const exp = pkg.exports && pkg.exports['.'];
|
|
723
|
+
const styleEntry = typeof exp === 'object' && exp !== null ? exp.style : null;
|
|
724
|
+
if (styleEntry) return resolve(pkgDir, styleEntry);
|
|
725
|
+
} catch {}
|
|
726
|
+
// Fallback: try common CSS filenames
|
|
727
|
+
const fallbacks = ['index.css', 'dist/index.css', 'style.css', 'styles.css'];
|
|
728
|
+
for (const f of fallbacks) {
|
|
729
|
+
const p = join(pkgDir, f);
|
|
730
|
+
if (existsSync(p)) return p;
|
|
731
|
+
}
|
|
732
|
+
return null;
|
|
733
|
+
}
|
|
734
|
+
const parent = dirname(dir);
|
|
735
|
+
if (parent === dir) break;
|
|
736
|
+
dir = parent;
|
|
737
|
+
}
|
|
738
|
+
return null;
|
|
739
|
+
}
|
|
740
|
+
|
|
609
741
|
function extractComponentClasses(cssPath, baseDir) {
|
|
610
742
|
let css;
|
|
611
743
|
try { css = readFileSync(cssPath, 'utf-8'); } catch { return []; }
|
|
612
744
|
const files = [css];
|
|
613
|
-
const importRe = /@import\\s+['"](
|
|
745
|
+
const importRe = /@import\\s+['"]([^'"]+)['"]/g;
|
|
614
746
|
let m;
|
|
615
747
|
while ((m = importRe.exec(css)) !== null) {
|
|
616
|
-
|
|
748
|
+
const resolved = resolveImport(m[1], baseDir);
|
|
749
|
+
if (resolved) {
|
|
750
|
+
try { files.push(readFileSync(resolved, 'utf-8')); } catch {}
|
|
751
|
+
}
|
|
617
752
|
}
|
|
618
753
|
const result = [];
|
|
619
754
|
for (const content of files) {
|
|
620
|
-
|
|
755
|
+
// Scan both @layer components AND @layer utilities
|
|
756
|
+
const layerRe = /@layer\\s+(?:components|utilities)\\s*\\{/g;
|
|
621
757
|
let lm;
|
|
622
758
|
while ((lm = layerRe.exec(content)) !== null) {
|
|
623
759
|
let depth = 1, i = lm.index + lm[0].length;
|
|
@@ -631,6 +767,10 @@ function extractComponentClasses(cssPath, baseDir) {
|
|
|
631
767
|
let sm;
|
|
632
768
|
while ((sm = selRe.exec(block)) !== null) result.push(sm[1]);
|
|
633
769
|
}
|
|
770
|
+
// Scan all class selectors anywhere in the file (.class-name)
|
|
771
|
+
const classSelRe = /\\.([a-zA-Z_][\\w-]*)/g;
|
|
772
|
+
let cs;
|
|
773
|
+
while ((cs = classSelRe.exec(content)) !== null) result.push(cs[1]);
|
|
634
774
|
}
|
|
635
775
|
return [...new Set(result)];
|
|
636
776
|
}
|
|
@@ -648,6 +788,50 @@ async function main() {
|
|
|
648
788
|
const cssResults = ds.candidatesToCss(classNames);
|
|
649
789
|
const validClasses = classNames.filter((_, i) => cssResults[i] != null);
|
|
650
790
|
|
|
791
|
+
// Expand: validate extra candidates not in getClassList() but valid in v4
|
|
792
|
+
const validSet = new Set(validClasses);
|
|
793
|
+
const knownPrefixes = new Set();
|
|
794
|
+
for (const cls of validClasses) {
|
|
795
|
+
const dash = cls.lastIndexOf('-');
|
|
796
|
+
if (dash > 0) knownPrefixes.add(cls.slice(0, dash));
|
|
797
|
+
}
|
|
798
|
+
const extraCandidates = [];
|
|
799
|
+
const breakpoints = ['sm', 'md', 'lg', 'xl', '2xl'];
|
|
800
|
+
for (const prefix of knownPrefixes) {
|
|
801
|
+
// Bare utilities: rounded, shadow, blur, etc.
|
|
802
|
+
if (!validSet.has(prefix)) extraCandidates.push(prefix);
|
|
803
|
+
// Screen breakpoint variants: max-w-screen-lg, etc.
|
|
804
|
+
for (const bp of breakpoints) {
|
|
805
|
+
const candidate = prefix + '-screen-' + bp;
|
|
806
|
+
if (!validSet.has(candidate)) extraCandidates.push(candidate);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
if (extraCandidates.length > 0) {
|
|
810
|
+
const extraResults = ds.candidatesToCss(extraCandidates);
|
|
811
|
+
for (let i = 0; i < extraCandidates.length; i++) {
|
|
812
|
+
if (extraResults[i] != null) {
|
|
813
|
+
validClasses.push(extraCandidates[i]);
|
|
814
|
+
validSet.add(extraCandidates[i]);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// Marker classes: group/peer don't produce CSS but enable group-hover:/peer-checked: variants
|
|
820
|
+
const allVariants = ds.getVariants();
|
|
821
|
+
for (const v of allVariants) {
|
|
822
|
+
if (v.name === 'group' || v.name.startsWith('group-')) {
|
|
823
|
+
validClasses.push('group'); validSet.add('group'); break;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
for (const v of allVariants) {
|
|
827
|
+
if (v.name === 'peer' || v.name.startsWith('peer-')) {
|
|
828
|
+
validClasses.push('peer'); validSet.add('peer'); break;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// Named groups/peers: group/name, peer/name — the /name part is user-defined
|
|
833
|
+
// These are validated by the variant system, not by candidatesToCss
|
|
834
|
+
|
|
651
835
|
// Canonical forms (only store diffs)
|
|
652
836
|
// NOTE: canonicalizeCandidates deduplicates, so we must call it one class at a time
|
|
653
837
|
const canonical = {};
|
|
@@ -658,15 +842,20 @@ async function main() {
|
|
|
658
842
|
}
|
|
659
843
|
}
|
|
660
844
|
|
|
661
|
-
// Sort order
|
|
845
|
+
// Sort order — include extra candidates so bare utilities (rounded, blur, etc.) get order
|
|
846
|
+
const allForOrder = [...classNames];
|
|
847
|
+
for (const cls of validClasses) {
|
|
848
|
+
if (!classNames.includes(cls)) allForOrder.push(cls);
|
|
849
|
+
}
|
|
662
850
|
const order = {};
|
|
663
|
-
const orderResults = ds.getClassOrder(
|
|
851
|
+
const orderResults = ds.getClassOrder(allForOrder);
|
|
664
852
|
for (const [name, val] of orderResults) {
|
|
665
853
|
if (val !== null) order[name] = val.toString();
|
|
666
854
|
}
|
|
667
855
|
|
|
668
|
-
// CSS properties per class
|
|
856
|
+
// CSS properties per class — extract only from the class rule block, skip @property descriptors
|
|
669
857
|
const cssProps = {};
|
|
858
|
+
const atPropertyDescriptors = new Set(['syntax', 'inherits', 'initial-value']);
|
|
670
859
|
const propRegex = /^\\s+([\\w-]+)\\s*:/gm;
|
|
671
860
|
for (let i = 0; i < classNames.length; i++) {
|
|
672
861
|
if (cssResults[i]) {
|
|
@@ -674,7 +863,7 @@ async function main() {
|
|
|
674
863
|
let match;
|
|
675
864
|
propRegex.lastIndex = 0;
|
|
676
865
|
while ((match = propRegex.exec(cssResults[i])) !== null) {
|
|
677
|
-
props.push(match[1]);
|
|
866
|
+
if (!atPropertyDescriptors.has(match[1])) props.push(match[1]);
|
|
678
867
|
}
|
|
679
868
|
if (props.length > 0) cssProps[classNames[i]] = props;
|
|
680
869
|
}
|
|
@@ -730,8 +919,9 @@ async function main() {
|
|
|
730
919
|
main().catch(e => { process.stderr.write(e.message); process.exit(1); });
|
|
731
920
|
`;
|
|
732
921
|
const CACHE_DIR = join(tmpdir(), "oxlint-tailwindcss");
|
|
922
|
+
const CACHE_VERSION = 8;
|
|
733
923
|
function getCachePath(cssPath, mtime) {
|
|
734
|
-
return join(CACHE_DIR, `${createHash("md5").update(
|
|
924
|
+
return join(CACHE_DIR, `${createHash("md5").update(`v${CACHE_VERSION}:${cssPath}:${mtime}`).digest("hex")}.json`);
|
|
735
925
|
}
|
|
736
926
|
function loadDesignSystemSync(cssPath) {
|
|
737
927
|
const resolvedPath = resolve(cssPath);
|
|
@@ -883,10 +1073,9 @@ function getLoadedDesignSystem(entryPoint, settings, filePath) {
|
|
|
883
1073
|
*/
|
|
884
1074
|
function createLazyLoader(context) {
|
|
885
1075
|
let result = null;
|
|
886
|
-
let
|
|
1076
|
+
let lastFilePath;
|
|
887
1077
|
return () => {
|
|
888
1078
|
if (result) return result;
|
|
889
|
-
if (triedWithFilePath) return null;
|
|
890
1079
|
let entryPoint;
|
|
891
1080
|
try {
|
|
892
1081
|
entryPoint = (context.options?.[0])?.entryPoint;
|
|
@@ -899,8 +1088,9 @@ function createLazyLoader(context) {
|
|
|
899
1088
|
try {
|
|
900
1089
|
filePath = context.filename;
|
|
901
1090
|
} catch {}
|
|
1091
|
+
if (filePath && filePath === lastFilePath) return null;
|
|
1092
|
+
if (filePath) lastFilePath = filePath;
|
|
902
1093
|
result = getLoadedDesignSystem(entryPoint, settings, filePath);
|
|
903
|
-
if (filePath) triedWithFilePath = true;
|
|
904
1094
|
return result;
|
|
905
1095
|
};
|
|
906
1096
|
}
|
|
@@ -923,6 +1113,104 @@ function safeOptions(context) {
|
|
|
923
1113
|
}
|
|
924
1114
|
}
|
|
925
1115
|
//#endregion
|
|
1116
|
+
//#region src/rules/no-deprecated-classes.ts
|
|
1117
|
+
const DEPRECATED_MAP = {
|
|
1118
|
+
"flex-grow": "grow",
|
|
1119
|
+
"flex-grow-0": "grow-0",
|
|
1120
|
+
"flex-shrink": "shrink",
|
|
1121
|
+
"flex-shrink-0": "shrink-0",
|
|
1122
|
+
"overflow-ellipsis": "text-ellipsis",
|
|
1123
|
+
"decoration-slice": "box-decoration-slice",
|
|
1124
|
+
"decoration-clone": "box-decoration-clone",
|
|
1125
|
+
"bg-gradient-to-t": "bg-linear-to-t",
|
|
1126
|
+
"bg-gradient-to-tr": "bg-linear-to-tr",
|
|
1127
|
+
"bg-gradient-to-r": "bg-linear-to-r",
|
|
1128
|
+
"bg-gradient-to-br": "bg-linear-to-br",
|
|
1129
|
+
"bg-gradient-to-b": "bg-linear-to-b",
|
|
1130
|
+
"bg-gradient-to-bl": "bg-linear-to-bl",
|
|
1131
|
+
"bg-gradient-to-l": "bg-linear-to-l",
|
|
1132
|
+
"bg-gradient-to-tl": "bg-linear-to-tl"
|
|
1133
|
+
};
|
|
1134
|
+
const noDeprecatedClasses = defineRule({
|
|
1135
|
+
meta: {
|
|
1136
|
+
type: "problem",
|
|
1137
|
+
docs: { description: "Disallow deprecated Tailwind CSS v4 classes" },
|
|
1138
|
+
fixable: "code",
|
|
1139
|
+
schema: [{
|
|
1140
|
+
type: "object",
|
|
1141
|
+
properties: { entryPoint: { type: "string" } },
|
|
1142
|
+
additionalProperties: false
|
|
1143
|
+
}],
|
|
1144
|
+
messages: { deprecated: "\"{{className}}\" is deprecated in Tailwind v4. Use \"{{replacement}}\" instead." }
|
|
1145
|
+
},
|
|
1146
|
+
createOnce(context) {
|
|
1147
|
+
const getDS = createLazyLoader(context);
|
|
1148
|
+
function check(locations) {
|
|
1149
|
+
const dsResult = getDS();
|
|
1150
|
+
for (const loc of locations) {
|
|
1151
|
+
const classes = splitClasses(loc.value);
|
|
1152
|
+
const offending = [];
|
|
1153
|
+
for (const cls of classes) {
|
|
1154
|
+
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
1155
|
+
const hasImportantPrefix = utility.startsWith("!");
|
|
1156
|
+
const hasImportantSuffix = !hasImportantPrefix && utility.endsWith("!");
|
|
1157
|
+
const bareUtility = hasImportantPrefix ? utility.slice(1) : hasImportantSuffix ? utility.slice(0, -1) : utility;
|
|
1158
|
+
const replacement = DEPRECATED_MAP[bareUtility];
|
|
1159
|
+
if (!replacement) continue;
|
|
1160
|
+
if (dsResult) {
|
|
1161
|
+
const canonical = dsResult.cache.canonicalize(bareUtility);
|
|
1162
|
+
if (canonical !== bareUtility && canonical === replacement) {}
|
|
1163
|
+
}
|
|
1164
|
+
const fullReplacement = variant + (hasImportantPrefix ? "!" : "") + replacement + (hasImportantSuffix ? "!" : "");
|
|
1165
|
+
offending.push({
|
|
1166
|
+
cls,
|
|
1167
|
+
replacement: fullReplacement
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
if (offending.length === 0) continue;
|
|
1171
|
+
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
1172
|
+
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls).join(" ");
|
|
1173
|
+
for (let i = 0; i < offending.length; i++) {
|
|
1174
|
+
const { cls, replacement } = offending[i];
|
|
1175
|
+
if (i === 0) context.report({
|
|
1176
|
+
node: loc.node,
|
|
1177
|
+
messageId: "deprecated",
|
|
1178
|
+
data: {
|
|
1179
|
+
className: cls,
|
|
1180
|
+
replacement
|
|
1181
|
+
},
|
|
1182
|
+
fix(fixer) {
|
|
1183
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
else context.report({
|
|
1187
|
+
node: loc.node,
|
|
1188
|
+
messageId: "deprecated",
|
|
1189
|
+
data: {
|
|
1190
|
+
className: cls,
|
|
1191
|
+
replacement
|
|
1192
|
+
}
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
return {
|
|
1198
|
+
JSXAttribute(node) {
|
|
1199
|
+
check(extractFromJSXAttribute(node, DEFAULT_EXTRACTOR_CONFIG));
|
|
1200
|
+
},
|
|
1201
|
+
CallExpression(node) {
|
|
1202
|
+
check(extractFromCallExpression(node, DEFAULT_EXTRACTOR_CONFIG));
|
|
1203
|
+
},
|
|
1204
|
+
TaggedTemplateExpression(node) {
|
|
1205
|
+
check(extractFromTaggedTemplate(node, DEFAULT_EXTRACTOR_CONFIG));
|
|
1206
|
+
},
|
|
1207
|
+
VariableDeclarator(node) {
|
|
1208
|
+
check(extractFromVariableDeclarator(node, DEFAULT_EXTRACTOR_CONFIG));
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
});
|
|
1213
|
+
//#endregion
|
|
926
1214
|
//#region src/rules/no-unknown-classes.ts
|
|
927
1215
|
const noUnknownClasses = defineRule({
|
|
928
1216
|
meta: {
|
|
@@ -984,6 +1272,7 @@ const noUnknownClasses = defineRule({
|
|
|
984
1272
|
if (shouldIgnore(cls)) continue;
|
|
985
1273
|
const stripped = stripModifiers(cls);
|
|
986
1274
|
if (cache.isValid(stripped)) continue;
|
|
1275
|
+
if (DEPRECATED_MAP[stripped]) continue;
|
|
987
1276
|
const suggestion = findBestSuggestion(stripped, cache.validClasses);
|
|
988
1277
|
if (suggestion) context.report({
|
|
989
1278
|
node: loc.node,
|
|
@@ -1056,12 +1345,37 @@ const noConflictingClasses = defineRule({
|
|
|
1056
1345
|
const props = cache.getCssProperties(utility);
|
|
1057
1346
|
propsMap.set(cls, props);
|
|
1058
1347
|
}
|
|
1348
|
+
const COMPLEMENTARY_GROUPS = [
|
|
1349
|
+
/^(?:from|via|to)-/,
|
|
1350
|
+
/^(?:shadow|ring|ring-offset)-/,
|
|
1351
|
+
/^(?:transition|duration|ease|delay)(?:-|$)/,
|
|
1352
|
+
/^-?(?:translate|scale|rotate|skew)-/,
|
|
1353
|
+
/^prose(?:-|$)/
|
|
1354
|
+
];
|
|
1355
|
+
const COMPOSITION_PAIRS = [
|
|
1356
|
+
[/^text-/, /^leading-/],
|
|
1357
|
+
[/^border(?:-[0-9]|$)/, /^border-(?:solid|dashed|dotted|double|hidden|none)$/],
|
|
1358
|
+
[/^divide-/, /^border(?:-[trblxyse])?-/],
|
|
1359
|
+
[/^prose(?:-|$)/, /^max-w-/]
|
|
1360
|
+
];
|
|
1361
|
+
function shouldSkipPair(a, b) {
|
|
1362
|
+
let ua = extractUtility(a);
|
|
1363
|
+
let ub = extractUtility(b);
|
|
1364
|
+
if (ua.startsWith("!")) ua = ua.slice(1);
|
|
1365
|
+
else if (ua.endsWith("!")) ua = ua.slice(0, -1);
|
|
1366
|
+
if (ub.startsWith("!")) ub = ub.slice(1);
|
|
1367
|
+
else if (ub.endsWith("!")) ub = ub.slice(0, -1);
|
|
1368
|
+
for (const re of COMPLEMENTARY_GROUPS) if (re.test(ua) && re.test(ub)) return true;
|
|
1369
|
+
for (const [reA, reB] of COMPOSITION_PAIRS) if (reA.test(ua) && reB.test(ub) || reA.test(ub) && reB.test(ua)) return true;
|
|
1370
|
+
return false;
|
|
1371
|
+
}
|
|
1059
1372
|
for (let i = 0; i < variantClasses.length; i++) {
|
|
1060
1373
|
const classA = variantClasses[i];
|
|
1061
1374
|
const propsA = propsMap.get(classA) ?? [];
|
|
1062
1375
|
for (let j = i + 1; j < variantClasses.length; j++) {
|
|
1063
1376
|
const classB = variantClasses[j];
|
|
1064
1377
|
const propsB = propsMap.get(classB) ?? [];
|
|
1378
|
+
if (shouldSkipPair(classA, classB)) continue;
|
|
1065
1379
|
const overlap = propsA.filter((p) => propsB.includes(p));
|
|
1066
1380
|
if (overlap.length > 0) {
|
|
1067
1381
|
const propList = overlap.length <= 3 ? `"${overlap.join("\", \"")}"` : `${overlap.length} CSS properties`;
|
|
@@ -1098,96 +1412,6 @@ const noConflictingClasses = defineRule({
|
|
|
1098
1412
|
}
|
|
1099
1413
|
});
|
|
1100
1414
|
//#endregion
|
|
1101
|
-
//#region src/rules/no-deprecated-classes.ts
|
|
1102
|
-
const DEPRECATED_MAP = {
|
|
1103
|
-
"flex-grow": "grow",
|
|
1104
|
-
"flex-grow-0": "grow-0",
|
|
1105
|
-
"flex-shrink": "shrink",
|
|
1106
|
-
"flex-shrink-0": "shrink-0",
|
|
1107
|
-
"overflow-ellipsis": "text-ellipsis",
|
|
1108
|
-
"decoration-slice": "box-decoration-slice",
|
|
1109
|
-
"decoration-clone": "box-decoration-clone"
|
|
1110
|
-
};
|
|
1111
|
-
const noDeprecatedClasses = defineRule({
|
|
1112
|
-
meta: {
|
|
1113
|
-
type: "problem",
|
|
1114
|
-
docs: { description: "Disallow deprecated Tailwind CSS v4 classes" },
|
|
1115
|
-
fixable: "code",
|
|
1116
|
-
schema: [{
|
|
1117
|
-
type: "object",
|
|
1118
|
-
properties: { entryPoint: { type: "string" } },
|
|
1119
|
-
additionalProperties: false
|
|
1120
|
-
}],
|
|
1121
|
-
messages: { deprecated: "\"{{className}}\" is deprecated in Tailwind v4. Use \"{{replacement}}\" instead." }
|
|
1122
|
-
},
|
|
1123
|
-
createOnce(context) {
|
|
1124
|
-
const getDS = createLazyLoader(context);
|
|
1125
|
-
function check(locations) {
|
|
1126
|
-
const dsResult = getDS();
|
|
1127
|
-
for (const loc of locations) {
|
|
1128
|
-
const classes = splitClasses(loc.value);
|
|
1129
|
-
const offending = [];
|
|
1130
|
-
for (const cls of classes) {
|
|
1131
|
-
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
1132
|
-
const hasImportantPrefix = utility.startsWith("!");
|
|
1133
|
-
const hasImportantSuffix = !hasImportantPrefix && utility.endsWith("!");
|
|
1134
|
-
const bareUtility = hasImportantPrefix ? utility.slice(1) : hasImportantSuffix ? utility.slice(0, -1) : utility;
|
|
1135
|
-
const replacement = DEPRECATED_MAP[bareUtility];
|
|
1136
|
-
if (!replacement) continue;
|
|
1137
|
-
if (dsResult) {
|
|
1138
|
-
const canonical = dsResult.cache.canonicalize(bareUtility);
|
|
1139
|
-
if (canonical !== bareUtility && canonical === replacement) {}
|
|
1140
|
-
}
|
|
1141
|
-
const fullReplacement = variant + (hasImportantPrefix ? "!" : "") + replacement + (hasImportantSuffix ? "!" : "");
|
|
1142
|
-
offending.push({
|
|
1143
|
-
cls,
|
|
1144
|
-
replacement: fullReplacement
|
|
1145
|
-
});
|
|
1146
|
-
}
|
|
1147
|
-
if (offending.length === 0) continue;
|
|
1148
|
-
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
1149
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls).join(" ");
|
|
1150
|
-
for (let i = 0; i < offending.length; i++) {
|
|
1151
|
-
const { cls, replacement } = offending[i];
|
|
1152
|
-
if (i === 0) context.report({
|
|
1153
|
-
node: loc.node,
|
|
1154
|
-
messageId: "deprecated",
|
|
1155
|
-
data: {
|
|
1156
|
-
className: cls,
|
|
1157
|
-
replacement
|
|
1158
|
-
},
|
|
1159
|
-
fix(fixer) {
|
|
1160
|
-
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
1161
|
-
}
|
|
1162
|
-
});
|
|
1163
|
-
else context.report({
|
|
1164
|
-
node: loc.node,
|
|
1165
|
-
messageId: "deprecated",
|
|
1166
|
-
data: {
|
|
1167
|
-
className: cls,
|
|
1168
|
-
replacement
|
|
1169
|
-
}
|
|
1170
|
-
});
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
return {
|
|
1175
|
-
JSXAttribute(node) {
|
|
1176
|
-
check(extractFromJSXAttribute(node, DEFAULT_EXTRACTOR_CONFIG));
|
|
1177
|
-
},
|
|
1178
|
-
CallExpression(node) {
|
|
1179
|
-
check(extractFromCallExpression(node, DEFAULT_EXTRACTOR_CONFIG));
|
|
1180
|
-
},
|
|
1181
|
-
TaggedTemplateExpression(node) {
|
|
1182
|
-
check(extractFromTaggedTemplate(node, DEFAULT_EXTRACTOR_CONFIG));
|
|
1183
|
-
},
|
|
1184
|
-
VariableDeclarator(node) {
|
|
1185
|
-
check(extractFromVariableDeclarator(node, DEFAULT_EXTRACTOR_CONFIG));
|
|
1186
|
-
}
|
|
1187
|
-
};
|
|
1188
|
-
}
|
|
1189
|
-
});
|
|
1190
|
-
//#endregion
|
|
1191
1415
|
//#region src/rules/enforce-canonical.ts
|
|
1192
1416
|
const enforceCanonical = defineRule({
|
|
1193
1417
|
meta: {
|
|
@@ -1257,6 +1481,165 @@ const enforceCanonical = defineRule({
|
|
|
1257
1481
|
}
|
|
1258
1482
|
});
|
|
1259
1483
|
//#endregion
|
|
1484
|
+
//#region src/design-system/sort-service.ts
|
|
1485
|
+
/**
|
|
1486
|
+
* Persistent sort service using worker_threads + SharedArrayBuffer.
|
|
1487
|
+
*
|
|
1488
|
+
* The problem: `ds.getClassOrder()` is the only way to get the exact official
|
|
1489
|
+
* Tailwind CSS sort order (matching oxfmt/prettier-plugin-tailwindcss), but the
|
|
1490
|
+
* design system is async to load and the oxlint plugin API is sync.
|
|
1491
|
+
*
|
|
1492
|
+
* The solution: spawn a Worker thread that loads the DS once, then accepts sort
|
|
1493
|
+
* requests via SharedArrayBuffer + Atomics. The parent uses `Atomics.wait()`
|
|
1494
|
+
* (with timeout) for synchronous blocking without risk of infinite hangs.
|
|
1495
|
+
*
|
|
1496
|
+
* Falls back gracefully if the worker fails to initialize within the timeout.
|
|
1497
|
+
*/
|
|
1498
|
+
const BUFFER_SIZE = 4 * 1024 * 1024;
|
|
1499
|
+
const HEADER_INTS = 4;
|
|
1500
|
+
const DATA_OFFSET = HEADER_INTS * 4 + 4;
|
|
1501
|
+
const INIT_TIMEOUT = 3e4;
|
|
1502
|
+
const REQUEST_TIMEOUT = 1e4;
|
|
1503
|
+
const WORKER_SCRIPT = `
|
|
1504
|
+
const { workerData } = require('worker_threads');
|
|
1505
|
+
|
|
1506
|
+
async function main() {
|
|
1507
|
+
const { sharedBuffer, cssPath } = workerData;
|
|
1508
|
+
const control = new Int32Array(sharedBuffer, 0, ${HEADER_INTS});
|
|
1509
|
+
const lengthView = new DataView(sharedBuffer, ${HEADER_INTS * 4}, 4);
|
|
1510
|
+
const dataArea = new Uint8Array(sharedBuffer, ${DATA_OFFSET});
|
|
1511
|
+
|
|
1512
|
+
let ds;
|
|
1513
|
+
try {
|
|
1514
|
+
const { __unstable__loadDesignSystem } = require('@tailwindcss/node');
|
|
1515
|
+
const { readFileSync } = require('fs');
|
|
1516
|
+
const { dirname } = require('path');
|
|
1517
|
+
const css = readFileSync(cssPath, 'utf-8');
|
|
1518
|
+
ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
|
|
1519
|
+
} catch {
|
|
1520
|
+
Atomics.store(control, 2, -1);
|
|
1521
|
+
Atomics.notify(control, 2);
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
// Signal ready
|
|
1526
|
+
Atomics.store(control, 2, 1);
|
|
1527
|
+
Atomics.notify(control, 2);
|
|
1528
|
+
|
|
1529
|
+
// Request loop
|
|
1530
|
+
while (true) {
|
|
1531
|
+
Atomics.wait(control, 0, 0); // wait for requestSignal !== 0
|
|
1532
|
+
|
|
1533
|
+
const len = lengthView.getUint32(0);
|
|
1534
|
+
const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
|
|
1535
|
+
Atomics.store(control, 0, 0); // consume request
|
|
1536
|
+
|
|
1537
|
+
let response;
|
|
1538
|
+
try {
|
|
1539
|
+
const classes = JSON.parse(requestStr);
|
|
1540
|
+
const ordered = ds.getClassOrder(classes);
|
|
1541
|
+
const sorted = [...ordered]
|
|
1542
|
+
.sort((a, b) => {
|
|
1543
|
+
if (a[1] === null && b[1] === null) return 0;
|
|
1544
|
+
if (a[1] === null) return -1;
|
|
1545
|
+
if (b[1] === null) return 1;
|
|
1546
|
+
return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0;
|
|
1547
|
+
})
|
|
1548
|
+
.map(([name]) => name);
|
|
1549
|
+
response = Buffer.from(JSON.stringify(sorted), 'utf-8');
|
|
1550
|
+
} catch {
|
|
1551
|
+
response = Buffer.from('null', 'utf-8');
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
dataArea.set(response, 0);
|
|
1555
|
+
lengthView.setUint32(0, response.length);
|
|
1556
|
+
|
|
1557
|
+
Atomics.store(control, 1, 1); // signal response
|
|
1558
|
+
Atomics.notify(control, 1);
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
main();
|
|
1562
|
+
`;
|
|
1563
|
+
let worker = null;
|
|
1564
|
+
let controlArray = null;
|
|
1565
|
+
let lengthView = null;
|
|
1566
|
+
let dataArea = null;
|
|
1567
|
+
let initialized = false;
|
|
1568
|
+
let available = true;
|
|
1569
|
+
function ensureService(cssPath) {
|
|
1570
|
+
if (initialized) return available;
|
|
1571
|
+
initialized = true;
|
|
1572
|
+
try {
|
|
1573
|
+
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
|
|
1574
|
+
controlArray = new Int32Array(sharedBuffer, 0, HEADER_INTS);
|
|
1575
|
+
lengthView = new DataView(sharedBuffer, HEADER_INTS * 4, 4);
|
|
1576
|
+
dataArea = new Uint8Array(sharedBuffer, DATA_OFFSET);
|
|
1577
|
+
worker = new Worker(WORKER_SCRIPT, {
|
|
1578
|
+
eval: true,
|
|
1579
|
+
workerData: {
|
|
1580
|
+
sharedBuffer,
|
|
1581
|
+
cssPath
|
|
1582
|
+
}
|
|
1583
|
+
});
|
|
1584
|
+
worker.unref();
|
|
1585
|
+
worker.on("error", () => {
|
|
1586
|
+
available = false;
|
|
1587
|
+
worker = null;
|
|
1588
|
+
});
|
|
1589
|
+
worker.on("exit", () => {
|
|
1590
|
+
worker = null;
|
|
1591
|
+
});
|
|
1592
|
+
if (Atomics.wait(controlArray, 2, 0, INIT_TIMEOUT) === "timed-out" || controlArray[2] === -1) {
|
|
1593
|
+
available = false;
|
|
1594
|
+
cleanup();
|
|
1595
|
+
return false;
|
|
1596
|
+
}
|
|
1597
|
+
process.on("exit", cleanup);
|
|
1598
|
+
return true;
|
|
1599
|
+
} catch {
|
|
1600
|
+
available = false;
|
|
1601
|
+
cleanup();
|
|
1602
|
+
return false;
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
function cleanup() {
|
|
1606
|
+
if (worker) {
|
|
1607
|
+
try {
|
|
1608
|
+
worker.terminate();
|
|
1609
|
+
} catch {}
|
|
1610
|
+
worker = null;
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
/**
|
|
1614
|
+
* Sort classes using the official Tailwind CSS sort order via worker thread.
|
|
1615
|
+
* Returns the sorted class array, or null if the service is unavailable.
|
|
1616
|
+
*/
|
|
1617
|
+
function sortClassesSync(cssPath, classes) {
|
|
1618
|
+
if (!ensureService(cssPath)) return null;
|
|
1619
|
+
if (!controlArray || !dataArea || !lengthView) return null;
|
|
1620
|
+
try {
|
|
1621
|
+
const request = Buffer.from(JSON.stringify(classes), "utf-8");
|
|
1622
|
+
if (request.length > BUFFER_SIZE - DATA_OFFSET) return null;
|
|
1623
|
+
dataArea.set(request, 0);
|
|
1624
|
+
lengthView.setUint32(0, request.length);
|
|
1625
|
+
Atomics.store(controlArray, 0, 1);
|
|
1626
|
+
Atomics.notify(controlArray, 0);
|
|
1627
|
+
if (Atomics.wait(controlArray, 1, 0, REQUEST_TIMEOUT) === "timed-out") {
|
|
1628
|
+
available = false;
|
|
1629
|
+
cleanup();
|
|
1630
|
+
return null;
|
|
1631
|
+
}
|
|
1632
|
+
const responseLen = lengthView.getUint32(0);
|
|
1633
|
+
const responseStr = Buffer.from(dataArea.slice(0, responseLen)).toString("utf-8");
|
|
1634
|
+
Atomics.store(controlArray, 1, 0);
|
|
1635
|
+
return JSON.parse(responseStr);
|
|
1636
|
+
} catch {
|
|
1637
|
+
available = false;
|
|
1638
|
+
cleanup();
|
|
1639
|
+
return null;
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
//#endregion
|
|
1260
1643
|
//#region src/rules/enforce-sort-order.ts
|
|
1261
1644
|
const enforceSortOrder = defineRule({
|
|
1262
1645
|
meta: {
|
|
@@ -1286,9 +1669,11 @@ const enforceSortOrder = defineRule({
|
|
|
1286
1669
|
function check(locations) {
|
|
1287
1670
|
const ds = getDS();
|
|
1288
1671
|
if (!ds) return;
|
|
1289
|
-
const { cache } = ds;
|
|
1672
|
+
const { cache, entryPoint } = ds;
|
|
1290
1673
|
const mode = getMode();
|
|
1291
1674
|
function sortDefault(classes) {
|
|
1675
|
+
const dynamic = sortClassesSync(entryPoint, classes);
|
|
1676
|
+
if (dynamic) return dynamic;
|
|
1292
1677
|
return [...cache.getClassOrder(classes)].sort((a, b) => {
|
|
1293
1678
|
const orderA = a[1] ?? 0n;
|
|
1294
1679
|
const orderB = b[1] ?? 0n;
|
|
@@ -1367,6 +1752,15 @@ const enforceSortOrder = defineRule({
|
|
|
1367
1752
|
//#endregion
|
|
1368
1753
|
//#region src/rules/enforce-shorthand.ts
|
|
1369
1754
|
const VALUE_RE = /^(?:m[trbl]|p[trbl]|[wh]|rounded-t[lr]|rounded-b[lr]|min-[wh]|max-[wh])-(.+)$/;
|
|
1755
|
+
const INVALID_SIZE_VALUES = new Set([
|
|
1756
|
+
"screen",
|
|
1757
|
+
"dvw",
|
|
1758
|
+
"dvh",
|
|
1759
|
+
"svw",
|
|
1760
|
+
"svh",
|
|
1761
|
+
"lvw",
|
|
1762
|
+
"lvh"
|
|
1763
|
+
]);
|
|
1370
1764
|
/**
|
|
1371
1765
|
* Generates shorthand rules parameterized by value.
|
|
1372
1766
|
* E.g.: mt-2 + mr-2 + mb-2 + ml-2 -> m-2
|
|
@@ -1407,10 +1801,10 @@ function createShorthandRules(value) {
|
|
|
1407
1801
|
parts: [`pl-${value}`, `pr-${value}`],
|
|
1408
1802
|
replacement: `px-${value}`
|
|
1409
1803
|
},
|
|
1410
|
-
{
|
|
1804
|
+
...!INVALID_SIZE_VALUES.has(value) ? [{
|
|
1411
1805
|
parts: [`w-${value}`, `h-${value}`],
|
|
1412
1806
|
replacement: `size-${value}`
|
|
1413
|
-
},
|
|
1807
|
+
}] : [],
|
|
1414
1808
|
{
|
|
1415
1809
|
parts: [
|
|
1416
1810
|
`rounded-tl-${value}`,
|
|
@@ -1582,6 +1976,84 @@ const enforceLogical = defineRule({
|
|
|
1582
1976
|
}
|
|
1583
1977
|
});
|
|
1584
1978
|
//#endregion
|
|
1979
|
+
//#region src/rules/enforce-physical.ts
|
|
1980
|
+
const LOGICAL_TO_PHYSICAL = {};
|
|
1981
|
+
for (const [physical, logical] of Object.entries(PHYSICAL_TO_LOGICAL)) LOGICAL_TO_PHYSICAL[logical] = physical;
|
|
1982
|
+
const enforcePhysical = defineRule({
|
|
1983
|
+
meta: {
|
|
1984
|
+
type: "suggestion",
|
|
1985
|
+
docs: { description: "Enforce physical Tailwind CSS properties instead of logical ones for consistency in LTR-only projects" },
|
|
1986
|
+
fixable: "code",
|
|
1987
|
+
schema: [],
|
|
1988
|
+
messages: { usePhysical: "\"{{className}}\" uses a logical property. Use \"{{replacement}}\" for consistency." }
|
|
1989
|
+
},
|
|
1990
|
+
createOnce(context) {
|
|
1991
|
+
function convertClass(cls) {
|
|
1992
|
+
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
1993
|
+
const hasImportantPrefix = utility.startsWith("!");
|
|
1994
|
+
const hasImportantSuffix = !hasImportantPrefix && utility.endsWith("!");
|
|
1995
|
+
const bareUtility = hasImportantPrefix ? utility.slice(1) : hasImportantSuffix ? utility.slice(0, -1) : utility;
|
|
1996
|
+
for (const [logical, physical] of Object.entries(LOGICAL_TO_PHYSICAL)) if (bareUtility === logical || bareUtility.startsWith(`${logical}-`)) {
|
|
1997
|
+
const suffix = bareUtility.slice(logical.length);
|
|
1998
|
+
return `${variant}${hasImportantPrefix ? "!" : ""}${physical}${suffix}${hasImportantSuffix ? "!" : ""}`;
|
|
1999
|
+
}
|
|
2000
|
+
return null;
|
|
2001
|
+
}
|
|
2002
|
+
function check(locations) {
|
|
2003
|
+
for (const loc of locations) {
|
|
2004
|
+
const classes = splitClasses(loc.value);
|
|
2005
|
+
const offending = [];
|
|
2006
|
+
for (const cls of classes) {
|
|
2007
|
+
const converted = convertClass(cls);
|
|
2008
|
+
if (converted) offending.push({
|
|
2009
|
+
cls,
|
|
2010
|
+
replacement: converted
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2013
|
+
if (offending.length === 0) continue;
|
|
2014
|
+
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
2015
|
+
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls).join(" ");
|
|
2016
|
+
for (let i = 0; i < offending.length; i++) {
|
|
2017
|
+
const { cls, replacement } = offending[i];
|
|
2018
|
+
if (i === 0) context.report({
|
|
2019
|
+
node: loc.node,
|
|
2020
|
+
messageId: "usePhysical",
|
|
2021
|
+
data: {
|
|
2022
|
+
className: cls,
|
|
2023
|
+
replacement
|
|
2024
|
+
},
|
|
2025
|
+
fix(fixer) {
|
|
2026
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
2027
|
+
}
|
|
2028
|
+
});
|
|
2029
|
+
else context.report({
|
|
2030
|
+
node: loc.node,
|
|
2031
|
+
messageId: "usePhysical",
|
|
2032
|
+
data: {
|
|
2033
|
+
className: cls,
|
|
2034
|
+
replacement
|
|
2035
|
+
}
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
return {
|
|
2041
|
+
JSXAttribute(node) {
|
|
2042
|
+
check(extractFromJSXAttribute(node, DEFAULT_EXTRACTOR_CONFIG));
|
|
2043
|
+
},
|
|
2044
|
+
CallExpression(node) {
|
|
2045
|
+
check(extractFromCallExpression(node, DEFAULT_EXTRACTOR_CONFIG));
|
|
2046
|
+
},
|
|
2047
|
+
TaggedTemplateExpression(node) {
|
|
2048
|
+
check(extractFromTaggedTemplate(node, DEFAULT_EXTRACTOR_CONFIG));
|
|
2049
|
+
},
|
|
2050
|
+
VariableDeclarator(node) {
|
|
2051
|
+
check(extractFromVariableDeclarator(node, DEFAULT_EXTRACTOR_CONFIG));
|
|
2052
|
+
}
|
|
2053
|
+
};
|
|
2054
|
+
}
|
|
2055
|
+
});
|
|
2056
|
+
//#endregion
|
|
1585
2057
|
//#region src/rules/max-class-count.ts
|
|
1586
2058
|
const DEFAULT_MAX = 20;
|
|
1587
2059
|
const maxClassCount = defineRule({
|
|
@@ -2737,6 +3209,7 @@ const plugin = definePlugin({
|
|
|
2737
3209
|
"enforce-sort-order": enforceSortOrder,
|
|
2738
3210
|
"enforce-shorthand": enforceShorthand,
|
|
2739
3211
|
"enforce-logical": enforceLogical,
|
|
3212
|
+
"enforce-physical": enforcePhysical,
|
|
2740
3213
|
"max-class-count": maxClassCount,
|
|
2741
3214
|
"no-restricted-classes": noRestrictedClasses,
|
|
2742
3215
|
"no-arbitrary-value": noArbitraryValue,
|