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