@multiplatform.one/config 10.5.1 → 10.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/design-lint.mjs +19 -6
- package/lint.mjs +381 -243
- package/oxlint.mjs +25 -4
- package/package.json +2 -2
package/design-lint.mjs
CHANGED
|
@@ -61,8 +61,22 @@ const middotJoin = /(^|[^\p{L}\p{N}])·([^\p{L}\p{N}]|$)|\s•\s/u;
|
|
|
61
61
|
const focusPaint =
|
|
62
62
|
/^(?:outline(?:Width|Color|Offset)?|boxShadow|shadow(?:Color|Opacity|Radius|Offset)|elevation)$/;
|
|
63
63
|
const focusStates = new Set(["focusStyle", "focusVisibleStyle", "focusWithinStyle"]);
|
|
64
|
-
const
|
|
65
|
-
|
|
64
|
+
const focusClause = /(?<![\w/-])focus(?:-visible|-within)?:(?=\S)/g;
|
|
65
|
+
const inertFocusPayloads = new Set(["0", "0px", "none", "transparent"]);
|
|
66
|
+
const nextFlatClause = /^\s+[@A-Za-z][\w/@-]*:/;
|
|
67
|
+
// A focus clause paints unless its payload is inert and the value ends or a
|
|
68
|
+
// further clause follows it.
|
|
69
|
+
function paintsFocusClause(text) {
|
|
70
|
+
for (const clause of text.matchAll(focusClause)) {
|
|
71
|
+
const rest = text.slice(clause.index + clause[0].length);
|
|
72
|
+
const payload = /^\S*/.exec(rest)[0];
|
|
73
|
+
const after = rest.slice(payload.length);
|
|
74
|
+
const inert =
|
|
75
|
+
inertFocusPayloads.has(payload) && (after.trim() === "" || nextFlatClause.test(after));
|
|
76
|
+
if (!inert) return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
66
80
|
// LC-149 FIELD-TRAILING-ACTION: a field's own action (reveal, clear, copy,
|
|
67
81
|
// eyedropper) is Input.Action inside the field, never an icon button beside it.
|
|
68
82
|
const fieldTag =
|
|
@@ -77,7 +91,6 @@ const copyTag = /^Copy\w*Button$/;
|
|
|
77
91
|
// Tamagui 3 replaced `Component.styleable(fn)` with `createStyledHOC(Component,
|
|
78
92
|
// fn)`, so a wrapped component spells its render function as the second
|
|
79
93
|
// argument. Both shapes are unwrapped while the tree is half converted.
|
|
80
|
-
const styleableWrap = /\.styleable$/;
|
|
81
94
|
const styledHocWrap = /(?:^|\.)createStyledHOC$/;
|
|
82
95
|
// LC-176 ICON-BUTTON: an icon-only button paints its recipe's plate. A prop that
|
|
83
96
|
// paints its own plate, ring or corners around the glyph needs a named plate.
|
|
@@ -884,7 +897,7 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
|
|
|
884
897
|
}
|
|
885
898
|
function checkFocus(key, value, node) {
|
|
886
899
|
const flat = resolve(value);
|
|
887
|
-
if (focusPaint.test(key) && ts.isStringLiteralLike(flat) &&
|
|
900
|
+
if (focusPaint.test(key) && ts.isStringLiteralLike(flat) && paintsFocusClause(flat.text)) {
|
|
888
901
|
report(
|
|
889
902
|
node,
|
|
890
903
|
"field-focus",
|
|
@@ -1944,7 +1957,7 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
|
|
|
1944
1957
|
const callee = current.expression.getText(file);
|
|
1945
1958
|
if (/^(?:(?:React\.)?(?:memo|forwardRef)|observer|withStaticProperties)$/.test(callee))
|
|
1946
1959
|
current = current.arguments[0];
|
|
1947
|
-
else if (
|
|
1960
|
+
else if (callee.endsWith(".styleable")) current = current.arguments[0];
|
|
1948
1961
|
else if (styledHocWrap.test(callee) && current.arguments[1]) current = current.arguments[1];
|
|
1949
1962
|
else return current;
|
|
1950
1963
|
}
|
|
@@ -1957,7 +1970,7 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
|
|
|
1957
1970
|
if (styledPrimitive(value)?.paints) return true;
|
|
1958
1971
|
if (ts.isCallExpression(value)) {
|
|
1959
1972
|
const callee = value.expression.getText(file);
|
|
1960
|
-
if (
|
|
1973
|
+
if (callee.endsWith(".styleable") || styledHocWrap.test(callee)) return false;
|
|
1961
1974
|
}
|
|
1962
1975
|
return false;
|
|
1963
1976
|
}
|
package/lint.mjs
CHANGED
|
@@ -617,7 +617,11 @@ function checkStyleTokens() {
|
|
|
617
617
|
}
|
|
618
618
|
|
|
619
619
|
const flatModifierChain = /^(?:[@A-Za-z][\w/@-]*:)+/;
|
|
620
|
-
const
|
|
620
|
+
const themeKeyShapes = [
|
|
621
|
+
/^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$/,
|
|
622
|
+
/^[a-z]+\d+$/,
|
|
623
|
+
/^[a-z]+[A-Z][A-Za-z0-9]*$/,
|
|
624
|
+
];
|
|
621
625
|
|
|
622
626
|
/**
|
|
623
627
|
* The words of a style value that name a token or theme key nothing defines.
|
|
@@ -642,7 +646,7 @@ function unresolvedStyleWords(value, resolvable, isColor) {
|
|
|
642
646
|
if (word.startsWith("$")) return /^\$[A-Za-z0-9.-]+$/.test(word) && !known(word.slice(1));
|
|
643
647
|
if (!isColor || word === "currentColor") return false;
|
|
644
648
|
const name = word.replace(/^[a-z]+\./, "");
|
|
645
|
-
return
|
|
649
|
+
return themeKeyShapes.some((shape) => shape.test(name)) && !known(word);
|
|
646
650
|
});
|
|
647
651
|
}
|
|
648
652
|
|
|
@@ -718,6 +722,41 @@ function checkIntentTokens() {
|
|
|
718
722
|
return { violations, valid: [...valid].sort(), ok: true };
|
|
719
723
|
}
|
|
720
724
|
|
|
725
|
+
const quotedRun = /["'][^"'\n]*/g;
|
|
726
|
+
const enterExitClause = /(?<![\w/-])(?:enter|exit):(?![\s"'])/;
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* Whether the quote at `at` opens an attribute value: `=`, then space, an
|
|
730
|
+
* optional `{` and more space before it.
|
|
731
|
+
* @param {string} tag
|
|
732
|
+
* @param {number} at
|
|
733
|
+
*/
|
|
734
|
+
function opensAttrValue(tag, at) {
|
|
735
|
+
let i = at - 1;
|
|
736
|
+
while (i >= 0 && /\s/.test(tag[i])) i--;
|
|
737
|
+
if (tag[i] === "{") {
|
|
738
|
+
i--;
|
|
739
|
+
while (i >= 0 && /\s/.test(tag[i])) i--;
|
|
740
|
+
}
|
|
741
|
+
return tag[i] === "=";
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Whether a tag's text carries an `enter:` or `exit:` flat clause inside a
|
|
746
|
+
* quoted attribute value. Each value is read with the opening quote and the
|
|
747
|
+
* character that closes it, so the clause sees the same neighbours it has in
|
|
748
|
+
* the tag.
|
|
749
|
+
* @param {string} tag
|
|
750
|
+
*/
|
|
751
|
+
function hasEnterExitClause(tag) {
|
|
752
|
+
for (const value of tag.matchAll(quotedRun)) {
|
|
753
|
+
if (!opensAttrValue(tag, value.index)) continue;
|
|
754
|
+
const end = value.index + value[0].length + 1;
|
|
755
|
+
if (enterExitClause.test(tag.slice(value.index, end))) return true;
|
|
756
|
+
}
|
|
757
|
+
return false;
|
|
758
|
+
}
|
|
759
|
+
|
|
721
760
|
/**
|
|
722
761
|
* Two more silent-animation-death shapes, both found dead in the live sweep
|
|
723
762
|
* (`p-results/fix-animation-sweep.md`) and neither catchable by the token
|
|
@@ -758,11 +797,7 @@ function checkAnimationProps() {
|
|
|
758
797
|
// truncates the tag and hides everything after it from this check.
|
|
759
798
|
for (const tag of src.matchAll(/<[A-Z][\w.]*(?:\s(?:=>|[^>])*)?>/gs)) {
|
|
760
799
|
const t = tag[0];
|
|
761
|
-
if (
|
|
762
|
-
!/\b(enterStyle|exitStyle)=/.test(t) &&
|
|
763
|
-
!/=\s*\{?\s*["'][^"'\n]*?(?<![\w/-])(?:enter|exit):(?![\s"'])/.test(t)
|
|
764
|
-
)
|
|
765
|
-
continue;
|
|
800
|
+
if (!/\b(enterStyle|exitStyle)=/.test(t) && !hasEnterExitClause(t)) continue;
|
|
766
801
|
if (/\btransition(?:[=:]|Props\()/.test(t)) continue;
|
|
767
802
|
const line = src.slice(0, tag.index).split("\n").length;
|
|
768
803
|
driverless.push(`${rel}:${line} — enter/exitStyle with no \`transition\` driver (LC-24)`);
|
|
@@ -2672,25 +2707,29 @@ function styledVariantAttrSites(ts, src, filePath) {
|
|
|
2672
2707
|
};
|
|
2673
2708
|
collect(sf);
|
|
2674
2709
|
|
|
2710
|
+
const readSpread = (prop, where, seen) => {
|
|
2711
|
+
const spread = unwrap(prop.expression);
|
|
2712
|
+
if (!spread) return;
|
|
2713
|
+
const branches = ts.isConditionalExpression(spread)
|
|
2714
|
+
? [unwrap(spread.whenTrue), unwrap(spread.whenFalse)]
|
|
2715
|
+
: [spread];
|
|
2716
|
+
for (const branch of branches) {
|
|
2717
|
+
if (!branch) continue;
|
|
2718
|
+
if (ts.isObjectLiteralExpression(branch)) readValue(branch, where, seen);
|
|
2719
|
+
else if (ts.isIdentifier(branch) && locals.has(branch.text) && !seen.has(branch.text)) {
|
|
2720
|
+
readValue(
|
|
2721
|
+
locals.get(branch.text),
|
|
2722
|
+
`${where} via ...${branch.text}`,
|
|
2723
|
+
new Set([...seen, branch.text]),
|
|
2724
|
+
);
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
};
|
|
2728
|
+
|
|
2675
2729
|
const readValue = (obj, where, seen) => {
|
|
2676
2730
|
for (const prop of obj.properties) {
|
|
2677
2731
|
if (ts.isSpreadAssignment(prop)) {
|
|
2678
|
-
|
|
2679
|
-
if (!spread) continue;
|
|
2680
|
-
const branches = ts.isConditionalExpression(spread)
|
|
2681
|
-
? [unwrap(spread.whenTrue), unwrap(spread.whenFalse)]
|
|
2682
|
-
: [spread];
|
|
2683
|
-
for (const branch of branches) {
|
|
2684
|
-
if (!branch) continue;
|
|
2685
|
-
if (ts.isObjectLiteralExpression(branch)) readValue(branch, where, seen);
|
|
2686
|
-
else if (ts.isIdentifier(branch) && locals.has(branch.text) && !seen.has(branch.text)) {
|
|
2687
|
-
readValue(
|
|
2688
|
-
locals.get(branch.text),
|
|
2689
|
-
`${where} via ...${branch.text}`,
|
|
2690
|
-
new Set([...seen, branch.text]),
|
|
2691
|
-
);
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2732
|
+
readSpread(prop, where, seen);
|
|
2694
2733
|
continue;
|
|
2695
2734
|
}
|
|
2696
2735
|
const key = keyOf(prop);
|
|
@@ -2699,57 +2738,60 @@ function styledVariantAttrSites(ts, src, filePath) {
|
|
|
2699
2738
|
}
|
|
2700
2739
|
};
|
|
2701
2740
|
|
|
2741
|
+
const isStyledCallee = (callee) =>
|
|
2742
|
+
(ts.isIdentifier(callee) && callee.text === "styled") ||
|
|
2743
|
+
(ts.isPropertyAccessExpression(callee) &&
|
|
2744
|
+
ts.isIdentifier(callee.expression) &&
|
|
2745
|
+
callee.expression.text === "styled" &&
|
|
2746
|
+
callee.name.text !== "dynamic");
|
|
2747
|
+
|
|
2748
|
+
const isContextProp = (prop) => ts.isPropertyAssignment(prop) && keyOf(prop) === "context";
|
|
2749
|
+
|
|
2750
|
+
const readBagHazards = (options) => {
|
|
2751
|
+
if (options.properties.some(isContextProp)) return;
|
|
2752
|
+
for (const prop of options.properties) {
|
|
2753
|
+
if (!ts.isPropertyAssignment(prop) && !ts.isShorthandPropertyAssignment(prop)) continue;
|
|
2754
|
+
const key = keyOf(prop);
|
|
2755
|
+
if (key && BAG_HAZARD_ATTRS.has(key))
|
|
2756
|
+
sites.push({ line: lineOf(prop.getStart(sf)), key, where: "the options object" });
|
|
2757
|
+
}
|
|
2758
|
+
};
|
|
2759
|
+
|
|
2760
|
+
const readVariantCase = (variantName, one) => {
|
|
2761
|
+
if (!ts.isPropertyAssignment(one)) return;
|
|
2762
|
+
const caseName = keyOf(one) ?? "?";
|
|
2763
|
+
const value = unwrap(one.initializer);
|
|
2764
|
+
const where = `variants.${variantName}.${caseName}`;
|
|
2765
|
+
if (!value) return;
|
|
2766
|
+
if (ts.isObjectLiteralExpression(value)) readValue(value, where, new Set());
|
|
2767
|
+
else if (ts.isIdentifier(value) && locals.has(value.text)) {
|
|
2768
|
+
readValue(locals.get(value.text), `${where} = ${value.text}`, new Set([value.text]));
|
|
2769
|
+
}
|
|
2770
|
+
};
|
|
2771
|
+
|
|
2772
|
+
const readVariant = (variant) => {
|
|
2773
|
+
if (!ts.isPropertyAssignment(variant)) return;
|
|
2774
|
+
const variantName = keyOf(variant) ?? "?";
|
|
2775
|
+
const cases = unwrap(variant.initializer);
|
|
2776
|
+
if (!cases || !ts.isObjectLiteralExpression(cases)) return;
|
|
2777
|
+
for (const one of cases.properties) readVariantCase(variantName, one);
|
|
2778
|
+
};
|
|
2779
|
+
|
|
2780
|
+
const readVariants = (options) => {
|
|
2781
|
+
for (const prop of options.properties) {
|
|
2782
|
+
if (!ts.isPropertyAssignment(prop) || keyOf(prop) !== "variants") continue;
|
|
2783
|
+
const variants = unwrap(prop.initializer);
|
|
2784
|
+
if (!variants || !ts.isObjectLiteralExpression(variants)) continue;
|
|
2785
|
+
for (const variant of variants.properties) readVariant(variant);
|
|
2786
|
+
}
|
|
2787
|
+
};
|
|
2788
|
+
|
|
2702
2789
|
const visit = (node) => {
|
|
2703
|
-
if (ts.isCallExpression(node)) {
|
|
2704
|
-
const
|
|
2705
|
-
|
|
2706
|
-
(
|
|
2707
|
-
(
|
|
2708
|
-
ts.isIdentifier(callee.expression) &&
|
|
2709
|
-
callee.expression.text === "styled" &&
|
|
2710
|
-
callee.name.text !== "dynamic");
|
|
2711
|
-
if (isStyled) {
|
|
2712
|
-
const options = unwrap(node.arguments[1]);
|
|
2713
|
-
if (options && ts.isObjectLiteralExpression(options)) {
|
|
2714
|
-
const guarded = options.properties.some(
|
|
2715
|
-
(prop) => ts.isPropertyAssignment(prop) && keyOf(prop) === "context",
|
|
2716
|
-
);
|
|
2717
|
-
if (!guarded) {
|
|
2718
|
-
for (const prop of options.properties) {
|
|
2719
|
-
if (!ts.isPropertyAssignment(prop) && !ts.isShorthandPropertyAssignment(prop))
|
|
2720
|
-
continue;
|
|
2721
|
-
const key = keyOf(prop);
|
|
2722
|
-
if (key && BAG_HAZARD_ATTRS.has(key))
|
|
2723
|
-
sites.push({ line: lineOf(prop.getStart(sf)), key, where: "the options object" });
|
|
2724
|
-
}
|
|
2725
|
-
}
|
|
2726
|
-
for (const prop of options.properties) {
|
|
2727
|
-
if (!ts.isPropertyAssignment(prop) || keyOf(prop) !== "variants") continue;
|
|
2728
|
-
const variants = unwrap(prop.initializer);
|
|
2729
|
-
if (!variants || !ts.isObjectLiteralExpression(variants)) continue;
|
|
2730
|
-
for (const variant of variants.properties) {
|
|
2731
|
-
if (!ts.isPropertyAssignment(variant)) continue;
|
|
2732
|
-
const variantName = keyOf(variant) ?? "?";
|
|
2733
|
-
const cases = unwrap(variant.initializer);
|
|
2734
|
-
if (!cases || !ts.isObjectLiteralExpression(cases)) continue;
|
|
2735
|
-
for (const one of cases.properties) {
|
|
2736
|
-
if (!ts.isPropertyAssignment(one)) continue;
|
|
2737
|
-
const caseName = keyOf(one) ?? "?";
|
|
2738
|
-
const value = unwrap(one.initializer);
|
|
2739
|
-
const where = `variants.${variantName}.${caseName}`;
|
|
2740
|
-
if (!value) continue;
|
|
2741
|
-
if (ts.isObjectLiteralExpression(value)) readValue(value, where, new Set());
|
|
2742
|
-
else if (ts.isIdentifier(value) && locals.has(value.text)) {
|
|
2743
|
-
readValue(
|
|
2744
|
-
locals.get(value.text),
|
|
2745
|
-
`${where} = ${value.text}`,
|
|
2746
|
-
new Set([value.text]),
|
|
2747
|
-
);
|
|
2748
|
-
}
|
|
2749
|
-
}
|
|
2750
|
-
}
|
|
2751
|
-
}
|
|
2752
|
-
}
|
|
2790
|
+
if (ts.isCallExpression(node) && isStyledCallee(node.expression)) {
|
|
2791
|
+
const options = unwrap(node.arguments[1]);
|
|
2792
|
+
if (options && ts.isObjectLiteralExpression(options)) {
|
|
2793
|
+
readBagHazards(options);
|
|
2794
|
+
readVariants(options);
|
|
2753
2795
|
}
|
|
2754
2796
|
}
|
|
2755
2797
|
ts.forEachChild(node, visit);
|
|
@@ -2784,35 +2826,21 @@ function styledVariantAttrSites(ts, src, filePath) {
|
|
|
2784
2826
|
function checkStyledVariantAttrs() {
|
|
2785
2827
|
/** @type {string[]} */
|
|
2786
2828
|
const violations = [];
|
|
2787
|
-
const baselinePath = join(ROOT, VARIANT_ATTR_BASELINES);
|
|
2788
2829
|
/** @type {Record<string, number>} */
|
|
2789
|
-
|
|
2790
|
-
if (existsSync(baselinePath)) {
|
|
2791
|
-
const raw = JSON.parse(readFileSync(baselinePath, "utf8"));
|
|
2792
|
-
if (raw && typeof raw.sites === "object") baseline = raw.sites;
|
|
2793
|
-
}
|
|
2830
|
+
const baseline = readSiteBaseline(join(ROOT, VARIANT_ATTR_BASELINES));
|
|
2794
2831
|
/** @type {Record<string, number>} */
|
|
2795
2832
|
const counted = {};
|
|
2796
2833
|
/** @type {string[]} */
|
|
2797
2834
|
const candidates = [];
|
|
2798
2835
|
|
|
2799
2836
|
const collect = (filePath) => {
|
|
2800
|
-
if (
|
|
2801
|
-
if (VARIANT_ATTR_EXEMPT_RE.test(filePath)) return;
|
|
2802
|
-
if (VARIANT_ATTR_GNOME_RE.test(relative(ROOT, filePath).replaceAll("\\", "/"))) return;
|
|
2803
|
-
const src = readFileSync(filePath, "utf8");
|
|
2804
|
-
if (!VARIANT_ATTR_CANDIDATE_RE.test(src)) return;
|
|
2805
|
-
candidates.push(filePath);
|
|
2837
|
+
if (isVariantAttrCandidate(filePath)) candidates.push(filePath);
|
|
2806
2838
|
};
|
|
2807
2839
|
for (const dir of [PUBLIC_DIR, PACKAGES_DIR, APPS_DIR, FEATURES_DIR]) walkFiles(dir, collect);
|
|
2808
2840
|
if (!candidates.length) return violations;
|
|
2809
2841
|
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
// The parser is this package's own dependency, not the consumer tree's
|
|
2813
|
-
// content, so it resolves from here and not from the scanned root.
|
|
2814
|
-
ts = createRequire(import.meta.url)("typescript");
|
|
2815
|
-
} catch {
|
|
2842
|
+
const ts = loadConfigTypescript();
|
|
2843
|
+
if (!ts) {
|
|
2816
2844
|
return [
|
|
2817
2845
|
`typescript could not be resolved from @multiplatform.one/config, so ${candidates.length} styled() file(s) went unparsed — install it rather than let this check go quiet`,
|
|
2818
2846
|
];
|
|
@@ -2820,27 +2848,63 @@ function checkStyledVariantAttrs() {
|
|
|
2820
2848
|
|
|
2821
2849
|
for (const filePath of candidates) {
|
|
2822
2850
|
const rel = relative(ROOT, filePath).replaceAll("\\", "/");
|
|
2823
|
-
const
|
|
2824
|
-
const lines = src.split("\n");
|
|
2825
|
-
let open = 0;
|
|
2826
|
-
for (const site of styledVariantAttrSites(ts, src, filePath)) {
|
|
2827
|
-
open += 1;
|
|
2828
|
-
if (open > (baseline[rel] ?? 0)) {
|
|
2829
|
-
violations.push(
|
|
2830
|
-
site.where === "the options object"
|
|
2831
|
-
? `${rel}:${site.line} — \`${site.key}\` in a styled() options object with no \`context\` is dropped from every usage the compiler can flatten; write it at the call site (LC-303)\n ${(lines[site.line - 1] ?? "").trim()}`
|
|
2832
|
-
: `${rel}:${site.line} — \`${site.key}\` in ${site.where} reaches no element on ${VARIANT_DROPPED_ATTRS.get(site.key)}; write it at the call site (LC-303)\n ${(lines[site.line - 1] ?? "").trim()}`,
|
|
2833
|
-
);
|
|
2834
|
-
}
|
|
2835
|
-
}
|
|
2851
|
+
const open = pushVariantAttrViolations(ts, filePath, rel, baseline, violations);
|
|
2836
2852
|
if (open > 0) counted[rel] = open;
|
|
2837
2853
|
}
|
|
2838
2854
|
|
|
2855
|
+
violations.push(...ratchetDownViolations(VARIANT_ATTR_BASELINES, baseline, counted));
|
|
2856
|
+
return violations;
|
|
2857
|
+
}
|
|
2858
|
+
|
|
2859
|
+
function isVariantAttrCandidate(filePath) {
|
|
2860
|
+
if (!RETIRED_SCANNED_RE.test(filePath) || filePath.endsWith(".d.ts")) return false;
|
|
2861
|
+
if (VARIANT_ATTR_EXEMPT_RE.test(filePath)) return false;
|
|
2862
|
+
if (VARIANT_ATTR_GNOME_RE.test(relative(ROOT, filePath).replaceAll("\\", "/"))) return false;
|
|
2863
|
+
const src = readFileSync(filePath, "utf8");
|
|
2864
|
+
return VARIANT_ATTR_CANDIDATE_RE.test(src);
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
function loadConfigTypescript() {
|
|
2868
|
+
try {
|
|
2869
|
+
// The parser is this package's own dependency, not the consumer tree's
|
|
2870
|
+
// content, so it resolves from here and not from the scanned root.
|
|
2871
|
+
return createRequire(import.meta.url)("typescript");
|
|
2872
|
+
} catch {
|
|
2873
|
+
return undefined;
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
function pushVariantAttrViolations(ts, filePath, rel, baseline, violations) {
|
|
2878
|
+
const src = readFileSync(filePath, "utf8");
|
|
2879
|
+
const lines = src.split("\n");
|
|
2880
|
+
let open = 0;
|
|
2881
|
+
for (const site of styledVariantAttrSites(ts, src, filePath)) {
|
|
2882
|
+
open += 1;
|
|
2883
|
+
if (open > (baseline[rel] ?? 0)) violations.push(variantAttrViolation(rel, site, lines));
|
|
2884
|
+
}
|
|
2885
|
+
return open;
|
|
2886
|
+
}
|
|
2887
|
+
|
|
2888
|
+
function variantAttrViolation(rel, site, lines) {
|
|
2889
|
+
const text = (lines[site.line - 1] ?? "").trim();
|
|
2890
|
+
return site.where === "the options object"
|
|
2891
|
+
? `${rel}:${site.line} — \`${site.key}\` in a styled() options object with no \`context\` is dropped from every usage the compiler can flatten; write it at the call site (LC-303)\n ${text}`
|
|
2892
|
+
: `${rel}:${site.line} — \`${site.key}\` in ${site.where} reaches no element on ${VARIANT_DROPPED_ATTRS.get(site.key)}; write it at the call site (LC-303)\n ${text}`;
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
function readSiteBaseline(baselinePath) {
|
|
2896
|
+
if (!existsSync(baselinePath)) return {};
|
|
2897
|
+
const raw = JSON.parse(readFileSync(baselinePath, "utf8"));
|
|
2898
|
+
return raw && typeof raw.sites === "object" ? raw.sites : {};
|
|
2899
|
+
}
|
|
2900
|
+
|
|
2901
|
+
function ratchetDownViolations(baselineFile, baseline, counted) {
|
|
2902
|
+
const violations = [];
|
|
2839
2903
|
for (const [rel, allowed] of Object.entries(baseline)) {
|
|
2840
2904
|
const now = counted[rel] ?? 0;
|
|
2841
2905
|
if (now < allowed) {
|
|
2842
2906
|
violations.push(
|
|
2843
|
-
`${
|
|
2907
|
+
`${baselineFile}: ${rel} is down to ${now} from ${allowed} — lower the ratchet`,
|
|
2844
2908
|
);
|
|
2845
2909
|
}
|
|
2846
2910
|
}
|
|
@@ -2924,8 +2988,48 @@ function checkOneSidebar() {
|
|
|
2924
2988
|
return violations;
|
|
2925
2989
|
}
|
|
2926
2990
|
|
|
2927
|
-
const
|
|
2928
|
-
|
|
2991
|
+
const justifyValueStart = /justifyContent\s*(?:=\s*(?:\{\s*)?|:\s*)["']/g;
|
|
2992
|
+
const spreadAfterBreak = /[\s:](space-between|space-around|space-evenly)(?=["'\s])/;
|
|
2993
|
+
const spreadAtStart = /^(space-between|space-around|space-evenly)(?=["'\s])/;
|
|
2994
|
+
const longestSpread = "space-between".length;
|
|
2995
|
+
|
|
2996
|
+
/**
|
|
2997
|
+
* Every spread `justifyContent` value in a source file, as `{ index, value }`
|
|
2998
|
+
* with the index of its `justifyContent`. A value names the first spread word
|
|
2999
|
+
* that follows a space or colon inside the quotes, else a spread word that
|
|
3000
|
+
* opens them. A newline closes the quotes but may itself be that space.
|
|
3001
|
+
* @param {string} src
|
|
3002
|
+
* @returns {{ index: number, value: string }[]}
|
|
3003
|
+
*/
|
|
3004
|
+
function spreadJustifyHits(src) {
|
|
3005
|
+
const hits = [];
|
|
3006
|
+
justifyValueStart.lastIndex = 0;
|
|
3007
|
+
let start;
|
|
3008
|
+
while ((start = justifyValueStart.exec(src))) {
|
|
3009
|
+
const open = start.index + start[0].length;
|
|
3010
|
+
let close = open;
|
|
3011
|
+
while (close < src.length && !"\"'\n".includes(src[close])) close++;
|
|
3012
|
+
const window = src.slice(open, close + longestSpread + 2);
|
|
3013
|
+
const after = spreadAfterBreak.exec(window);
|
|
3014
|
+
let value;
|
|
3015
|
+
let end;
|
|
3016
|
+
if (after && after.index <= close - open) {
|
|
3017
|
+
value = after[1];
|
|
3018
|
+
end = open + after.index + after[0].length;
|
|
3019
|
+
} else {
|
|
3020
|
+
const first = spreadAtStart.exec(window);
|
|
3021
|
+
if (first) {
|
|
3022
|
+
value = first[1];
|
|
3023
|
+
end = open + first[0].length;
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3026
|
+
if (value) {
|
|
3027
|
+
hits.push({ index: start.index, value });
|
|
3028
|
+
justifyValueStart.lastIndex = end;
|
|
3029
|
+
} else justifyValueStart.lastIndex = start.index + 1;
|
|
3030
|
+
}
|
|
3031
|
+
return hits;
|
|
3032
|
+
}
|
|
2929
3033
|
|
|
2930
3034
|
/**
|
|
2931
3035
|
* LC-102 HUG-CONTENT: rows and columns hug their content; a spread
|
|
@@ -2949,13 +3053,13 @@ function checkHugContent() {
|
|
|
2949
3053
|
)
|
|
2950
3054
|
continue;
|
|
2951
3055
|
const live = nonCommentOffsets(src);
|
|
2952
|
-
const hits =
|
|
3056
|
+
const hits = spreadJustifyHits(src).filter((m) => live[m.index] === 1);
|
|
2953
3057
|
const allowed = baselines.hugContent[path] ?? 0;
|
|
2954
3058
|
if (allowed > 0) seen.add(path);
|
|
2955
3059
|
if (hits.length > allowed) {
|
|
2956
3060
|
const first = hits[allowed] ?? hits[0];
|
|
2957
3061
|
violations.push(
|
|
2958
|
-
`${path}:${lineAt(src, first.index
|
|
3062
|
+
`${path}:${lineAt(src, first.index)} — justifyContent="${first.value}" (${hits.length} in file, baseline ${allowed}); hug the content with a gap instead`,
|
|
2959
3063
|
);
|
|
2960
3064
|
} else if (hits.length < allowed) {
|
|
2961
3065
|
violations.push(
|
|
@@ -3226,7 +3330,7 @@ const PSEUDO_PROP_TOOLING_RE = /(?:^|\/)public\/config\//;
|
|
|
3226
3330
|
* `styled(` to its matching paren and reports only keys at brace depth 1,
|
|
3227
3331
|
* which is the options object itself.
|
|
3228
3332
|
*/
|
|
3229
|
-
const DOTTED_TOKEN_RE = /(?:^|[\s{,(])([a-zA-Z]
|
|
3333
|
+
const DOTTED_TOKEN_RE = /(?:^|[\s{,(])([a-zA-Z]\w*)\s*[:=]\s*(?:\{\s*)?["']\$(\d+\.\d+)["']/g;
|
|
3230
3334
|
|
|
3231
3335
|
/**
|
|
3232
3336
|
* Props a size or space token is meaningful on, so a `price: "$2.50"` in a
|
|
@@ -3298,46 +3402,60 @@ function findStyledNameOptions(src) {
|
|
|
3298
3402
|
const sites = [];
|
|
3299
3403
|
let control = 0;
|
|
3300
3404
|
for (const call of src.matchAll(/\bstyled\(/g)) {
|
|
3301
|
-
|
|
3302
|
-
let quote = null;
|
|
3303
|
-
let i = call.index + call[0].length - 1;
|
|
3304
|
-
let end = -1;
|
|
3305
|
-
while (i < src.length) {
|
|
3306
|
-
const ch = src[i];
|
|
3307
|
-
if (quote) {
|
|
3308
|
-
if (ch === "\\") {
|
|
3309
|
-
i += 2;
|
|
3310
|
-
continue;
|
|
3311
|
-
}
|
|
3312
|
-
if (ch === quote) quote = null;
|
|
3313
|
-
} else if (ch === '"' || ch === "'" || ch === "`") quote = ch;
|
|
3314
|
-
else if (ch === "(") depth += 1;
|
|
3315
|
-
else if (ch === ")") {
|
|
3316
|
-
depth -= 1;
|
|
3317
|
-
if (depth === 0) {
|
|
3318
|
-
end = i;
|
|
3319
|
-
break;
|
|
3320
|
-
}
|
|
3321
|
-
}
|
|
3322
|
-
i += 1;
|
|
3323
|
-
}
|
|
3405
|
+
const end = closingParenIndex(src, call.index + call[0].length - 1);
|
|
3324
3406
|
if (end < 0) continue;
|
|
3325
3407
|
const start = call.index + call[0].length;
|
|
3326
3408
|
const body = src.slice(start, end);
|
|
3327
|
-
|
|
3328
|
-
for (const token of body.matchAll(/[{}]|\bname\s*:|\bdisplayName\s*:/g)) {
|
|
3329
|
-
const text = token[0];
|
|
3330
|
-
if (text === "{") braces += 1;
|
|
3331
|
-
else if (text === "}") braces -= 1;
|
|
3332
|
-
else if (braces === 1) {
|
|
3333
|
-
if (text.startsWith("displayName")) control += 1;
|
|
3334
|
-
else sites.push(start + token.index);
|
|
3335
|
-
}
|
|
3336
|
-
}
|
|
3409
|
+
control += collectStyledNameTokens(body, start, sites);
|
|
3337
3410
|
}
|
|
3338
3411
|
return { sites: [...new Set(sites)], control };
|
|
3339
3412
|
}
|
|
3340
3413
|
|
|
3414
|
+
function closingParenIndex(src, from) {
|
|
3415
|
+
let depth = 0;
|
|
3416
|
+
let i = from;
|
|
3417
|
+
while (i < src.length) {
|
|
3418
|
+
const ch = src[i];
|
|
3419
|
+
if (ch === '"' || ch === "'" || ch === "`") i = closingQuoteIndex(src, i);
|
|
3420
|
+
else if (ch === "(") depth += 1;
|
|
3421
|
+
else if (ch === ")") {
|
|
3422
|
+
depth -= 1;
|
|
3423
|
+
if (depth === 0) return i;
|
|
3424
|
+
}
|
|
3425
|
+
i += 1;
|
|
3426
|
+
}
|
|
3427
|
+
return -1;
|
|
3428
|
+
}
|
|
3429
|
+
|
|
3430
|
+
function closingQuoteIndex(src, from) {
|
|
3431
|
+
const quote = src[from];
|
|
3432
|
+
let i = from + 1;
|
|
3433
|
+
while (i < src.length) {
|
|
3434
|
+
if (src[i] === "\\") {
|
|
3435
|
+
i += 2;
|
|
3436
|
+
continue;
|
|
3437
|
+
}
|
|
3438
|
+
if (src[i] === quote) return i;
|
|
3439
|
+
i += 1;
|
|
3440
|
+
}
|
|
3441
|
+
return i;
|
|
3442
|
+
}
|
|
3443
|
+
|
|
3444
|
+
function collectStyledNameTokens(body, start, sites) {
|
|
3445
|
+
let braces = 0;
|
|
3446
|
+
let control = 0;
|
|
3447
|
+
for (const token of body.matchAll(/[{}]|\bname\s*:|\bdisplayName\s*:/g)) {
|
|
3448
|
+
const text = token[0];
|
|
3449
|
+
if (text === "{") braces += 1;
|
|
3450
|
+
else if (text === "}") braces -= 1;
|
|
3451
|
+
else if (braces === 1) {
|
|
3452
|
+
if (text.startsWith("displayName")) control += 1;
|
|
3453
|
+
else sites.push(start + token.index);
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
return control;
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3341
3459
|
/**
|
|
3342
3460
|
* FZ-10849 V3-CLAUSE: Tamagui 3 removed every v2 pseudo-style prop and every
|
|
3343
3461
|
* `$`-prefixed style prop. They are not errors. They typecheck, they render,
|
|
@@ -3367,13 +3485,8 @@ function findStyledNameOptions(src) {
|
|
|
3367
3485
|
function checkV2PseudoProps() {
|
|
3368
3486
|
/** @type {string[]} */
|
|
3369
3487
|
const violations = [];
|
|
3370
|
-
const baselinePath = join(ROOT, PSEUDO_PROP_BASELINES);
|
|
3371
3488
|
/** @type {Record<string, number>} */
|
|
3372
|
-
|
|
3373
|
-
if (existsSync(baselinePath)) {
|
|
3374
|
-
const raw = JSON.parse(readFileSync(baselinePath, "utf8"));
|
|
3375
|
-
if (raw && typeof raw.sites === "object") baseline = raw.sites;
|
|
3376
|
-
}
|
|
3489
|
+
const baseline = readSiteBaseline(join(ROOT, PSEUDO_PROP_BASELINES));
|
|
3377
3490
|
let registry;
|
|
3378
3491
|
try {
|
|
3379
3492
|
registry = readPseudoPropEscapeRegistry(join(ROOT, "docs/theme-propagation-spec.md"));
|
|
@@ -3389,98 +3502,19 @@ function checkV2PseudoProps() {
|
|
|
3389
3502
|
const counted = {};
|
|
3390
3503
|
|
|
3391
3504
|
const scan = (filePath) => {
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
const src = readFileSync(filePath, "utf8");
|
|
3396
|
-
if (!/Style\s*[:=]|\$[a-z]|\$\d+\.\d|\bstyled\(|(?:^|\s)tag=/m.test(src)) return;
|
|
3397
|
-
const code = codeOffsets(src);
|
|
3505
|
+
const source = pseudoPropSource(filePath);
|
|
3506
|
+
if (!source) return;
|
|
3507
|
+
const { rel, src } = source;
|
|
3398
3508
|
const lines = src.split("\n");
|
|
3399
|
-
const escapedLines =
|
|
3400
|
-
|
|
3401
|
-
const reasonAt = new Map();
|
|
3402
|
-
for (const { line, reason } of findPseudoPropEscapes(src)) {
|
|
3403
|
-
for (const at of [line, line + 1]) {
|
|
3404
|
-
escapedLines.add(at);
|
|
3405
|
-
if (!reasonAt.has(at)) reasonAt.set(at, reason);
|
|
3406
|
-
}
|
|
3407
|
-
}
|
|
3408
|
-
|
|
3409
|
-
/** @type {Map<number, string>} */
|
|
3410
|
-
const hits = new Map();
|
|
3411
|
-
for (const match of src.matchAll(V2_PSEUDO_KEY_RE)) {
|
|
3412
|
-
const index = (match.index ?? 0) + match[0].indexOf(match[2]);
|
|
3413
|
-
if (code[index] !== 1) continue;
|
|
3414
|
-
hits.set(
|
|
3415
|
-
index,
|
|
3416
|
-
`\`${match[2]}\` emits nothing; write the \`${V2_PSEUDO_PROPS.get(
|
|
3417
|
-
match[2],
|
|
3418
|
-
)}\` clause on the style's own property`,
|
|
3419
|
-
);
|
|
3420
|
-
}
|
|
3421
|
-
if (STYLES_FROM_TAMAGUI_RE.test(src)) {
|
|
3422
|
-
for (const match of src.matchAll(DOLLAR_PROP_RE)) {
|
|
3423
|
-
const index = (match.index ?? 0) + match[0].indexOf("$");
|
|
3424
|
-
// A quoted key — `{ "$max-sm": {…} }` — is just as inert and is how two
|
|
3425
|
-
// live sites hid from the first draft of this check. The `$` then sits
|
|
3426
|
-
// inside a string, so the code test reads the character before the
|
|
3427
|
-
// opening quote, which is the one in code.
|
|
3428
|
-
if (code[match[1] ? index - 2 : index] !== 1) continue;
|
|
3429
|
-
if (src[index - 1] === "$" || src[index - 1] === ".") continue;
|
|
3430
|
-
const clause = match[2].replace(/^gt([A-Z])/, (_, c) => `gt${c}`);
|
|
3431
|
-
hits.set(
|
|
3432
|
-
index,
|
|
3433
|
-
`\`$${match[2]}\` emits nothing; write the \`${clause}:\` clause on the style's own property`,
|
|
3434
|
-
);
|
|
3435
|
-
}
|
|
3436
|
-
}
|
|
3437
|
-
|
|
3438
|
-
for (const match of src.matchAll(DOTTED_TOKEN_RE)) {
|
|
3439
|
-
const index = (match.index ?? 0) + match[0].indexOf("$");
|
|
3440
|
-
// The `$` is inside the quoted value, so the code test reads the prop
|
|
3441
|
-
// name, which is the part in code.
|
|
3442
|
-
if (code[(match.index ?? 0) + match[0].indexOf(match[1])] !== 1) continue;
|
|
3443
|
-
if (!TOKEN_GEOMETRY_PROPS.has(match[1])) continue;
|
|
3444
|
-
hits.set(
|
|
3445
|
-
index,
|
|
3446
|
-
`\`${match[1]}="$${match[2]}"\` emits nothing; a dotted token reaches the DOM verbatim, so the property is dropped — the v3 scale key is kebab and bare: \`${match[1]}="${match[2].replace(".", "-")}"\``,
|
|
3447
|
-
);
|
|
3448
|
-
}
|
|
3449
|
-
if (STYLES_FROM_TAMAGUI_RE.test(src)) {
|
|
3450
|
-
for (const match of src.matchAll(TAG_PROP_RE)) {
|
|
3451
|
-
const index = (match.index ?? 0) + match[0].indexOf("tag");
|
|
3452
|
-
if (code[index] !== 1) continue;
|
|
3453
|
-
hits.set(
|
|
3454
|
-
index,
|
|
3455
|
-
'`tag` is gone in v3 and renders the base element instead; write `render` — `render="button"`, or `render={<a href={link} />}` when the element carries attributes',
|
|
3456
|
-
);
|
|
3457
|
-
}
|
|
3458
|
-
}
|
|
3459
|
-
const styledNames = findStyledNameOptions(src);
|
|
3460
|
-
for (const index of styledNames.sites) {
|
|
3461
|
-
if (code[index] !== 1) continue;
|
|
3462
|
-
hits.set(
|
|
3463
|
-
index,
|
|
3464
|
-
"`name` is not a `styled()` option in v3; it falls into `...defaultProps`, so it emits no class and, on an input-like base, reaches the DOM as the form field's `name` — rename it to `displayName`, and write `className` by hand where a selector needs the class",
|
|
3465
|
-
);
|
|
3466
|
-
}
|
|
3509
|
+
const { escapedLines, reasonAt } = pseudoPropEscapeLines(src);
|
|
3510
|
+
const hits = collectPseudoPropHits(src, codeOffsets(src));
|
|
3467
3511
|
|
|
3468
3512
|
let open = 0;
|
|
3469
3513
|
for (const [index, what] of [...hits].sort((a, b) => a[0] - b[0])) {
|
|
3470
3514
|
const line = lineAt(src, index);
|
|
3471
3515
|
if (escapedLines.has(line)) {
|
|
3472
|
-
const
|
|
3473
|
-
if (
|
|
3474
|
-
violations.push(`${rel}:${line} — pseudo-prop-escape with no written reason`);
|
|
3475
|
-
continue;
|
|
3476
|
-
}
|
|
3477
|
-
const key = `${rel}\n${reason}`;
|
|
3478
|
-
if (!registry.present) continue;
|
|
3479
|
-
if (declared.has(key)) {
|
|
3480
|
-
declared.set(key, true);
|
|
3481
|
-
continue;
|
|
3482
|
-
}
|
|
3483
|
-
violations.push(`${rel}:${line} — undeclared escape "${reason}"`);
|
|
3516
|
+
const violation = escapedHitViolation(rel, line, reasonAt, registry, declared);
|
|
3517
|
+
if (violation) violations.push(violation);
|
|
3484
3518
|
continue;
|
|
3485
3519
|
}
|
|
3486
3520
|
open += 1;
|
|
@@ -3493,14 +3527,7 @@ function checkV2PseudoProps() {
|
|
|
3493
3527
|
|
|
3494
3528
|
for (const dir of [PUBLIC_DIR, PACKAGES_DIR, APPS_DIR, FEATURES_DIR]) walkFiles(dir, scan);
|
|
3495
3529
|
|
|
3496
|
-
|
|
3497
|
-
const now = counted[rel] ?? 0;
|
|
3498
|
-
if (now < allowed) {
|
|
3499
|
-
violations.push(
|
|
3500
|
-
`${PSEUDO_PROP_BASELINES}: ${rel} is down to ${now} from ${allowed} — lower the ratchet`,
|
|
3501
|
-
);
|
|
3502
|
-
}
|
|
3503
|
-
}
|
|
3530
|
+
violations.push(...ratchetDownViolations(PSEUDO_PROP_BASELINES, baseline, counted));
|
|
3504
3531
|
for (const [key, seen] of declared) {
|
|
3505
3532
|
if (seen) continue;
|
|
3506
3533
|
const [file, reason] = key.split("\n");
|
|
@@ -3509,6 +3536,117 @@ function checkV2PseudoProps() {
|
|
|
3509
3536
|
return violations;
|
|
3510
3537
|
}
|
|
3511
3538
|
|
|
3539
|
+
function pseudoPropSource(filePath) {
|
|
3540
|
+
if (!RETIRED_SCANNED_RE.test(filePath) || filePath.endsWith(".d.ts")) return undefined;
|
|
3541
|
+
const rel = relative(ROOT, filePath).replaceAll("\\", "/");
|
|
3542
|
+
if (PSEUDO_PROP_TOOLING_RE.test(`/${rel}`)) return undefined;
|
|
3543
|
+
const src = readFileSync(filePath, "utf8");
|
|
3544
|
+
if (!/Style\s*[:=]|\$[a-z]|\$\d+\.\d|\bstyled\(|(?:^|\s)tag=/m.test(src)) return undefined;
|
|
3545
|
+
return { rel, src };
|
|
3546
|
+
}
|
|
3547
|
+
|
|
3548
|
+
function pseudoPropEscapeLines(src) {
|
|
3549
|
+
const escapedLines = new Set();
|
|
3550
|
+
/** @type {Map<number, string>} */
|
|
3551
|
+
const reasonAt = new Map();
|
|
3552
|
+
for (const { line, reason } of findPseudoPropEscapes(src)) {
|
|
3553
|
+
for (const at of [line, line + 1]) {
|
|
3554
|
+
escapedLines.add(at);
|
|
3555
|
+
if (!reasonAt.has(at)) reasonAt.set(at, reason);
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
return { escapedLines, reasonAt };
|
|
3559
|
+
}
|
|
3560
|
+
|
|
3561
|
+
function escapedHitViolation(rel, line, reasonAt, registry, declared) {
|
|
3562
|
+
const reason = reasonAt.get(line) ?? "";
|
|
3563
|
+
if (!reason) return `${rel}:${line} — pseudo-prop-escape with no written reason`;
|
|
3564
|
+
const key = `${rel}\n${reason}`;
|
|
3565
|
+
if (!registry.present) return undefined;
|
|
3566
|
+
if (declared.has(key)) {
|
|
3567
|
+
declared.set(key, true);
|
|
3568
|
+
return undefined;
|
|
3569
|
+
}
|
|
3570
|
+
return `${rel}:${line} — undeclared escape "${reason}"`;
|
|
3571
|
+
}
|
|
3572
|
+
|
|
3573
|
+
function collectPseudoPropHits(src, code) {
|
|
3574
|
+
/** @type {Map<number, string>} */
|
|
3575
|
+
const hits = new Map();
|
|
3576
|
+
addV2PseudoKeyHits(src, code, hits);
|
|
3577
|
+
if (STYLES_FROM_TAMAGUI_RE.test(src)) addDollarPropHits(src, code, hits);
|
|
3578
|
+
addDottedTokenHits(src, code, hits);
|
|
3579
|
+
if (STYLES_FROM_TAMAGUI_RE.test(src)) addTagPropHits(src, code, hits);
|
|
3580
|
+
addStyledNameHits(src, code, hits);
|
|
3581
|
+
return hits;
|
|
3582
|
+
}
|
|
3583
|
+
|
|
3584
|
+
function addV2PseudoKeyHits(src, code, hits) {
|
|
3585
|
+
for (const match of src.matchAll(V2_PSEUDO_KEY_RE)) {
|
|
3586
|
+
const index = (match.index ?? 0) + match[0].indexOf(match[2]);
|
|
3587
|
+
if (code[index] !== 1) continue;
|
|
3588
|
+
hits.set(
|
|
3589
|
+
index,
|
|
3590
|
+
`\`${match[2]}\` emits nothing; write the \`${V2_PSEUDO_PROPS.get(
|
|
3591
|
+
match[2],
|
|
3592
|
+
)}\` clause on the style's own property`,
|
|
3593
|
+
);
|
|
3594
|
+
}
|
|
3595
|
+
}
|
|
3596
|
+
|
|
3597
|
+
function addDollarPropHits(src, code, hits) {
|
|
3598
|
+
for (const match of src.matchAll(DOLLAR_PROP_RE)) {
|
|
3599
|
+
const index = (match.index ?? 0) + match[0].indexOf("$");
|
|
3600
|
+
// A quoted key — `{ "$max-sm": {…} }` — is just as inert and is how two
|
|
3601
|
+
// live sites hid from the first draft of this check. The `$` then sits
|
|
3602
|
+
// inside a string, so the code test reads the character before the
|
|
3603
|
+
// opening quote, which is the one in code.
|
|
3604
|
+
if (code[match[1] ? index - 2 : index] !== 1) continue;
|
|
3605
|
+
if (src[index - 1] === "$" || src[index - 1] === ".") continue;
|
|
3606
|
+
const clause = match[2].replace(/^gt([A-Z])/, (_, c) => `gt${c}`);
|
|
3607
|
+
hits.set(
|
|
3608
|
+
index,
|
|
3609
|
+
`\`$${match[2]}\` emits nothing; write the \`${clause}:\` clause on the style's own property`,
|
|
3610
|
+
);
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
|
|
3614
|
+
function addDottedTokenHits(src, code, hits) {
|
|
3615
|
+
for (const match of src.matchAll(DOTTED_TOKEN_RE)) {
|
|
3616
|
+
const index = (match.index ?? 0) + match[0].indexOf("$");
|
|
3617
|
+
// The `$` is inside the quoted value, so the code test reads the prop
|
|
3618
|
+
// name, which is the part in code.
|
|
3619
|
+
if (code[(match.index ?? 0) + match[0].indexOf(match[1])] !== 1) continue;
|
|
3620
|
+
if (!TOKEN_GEOMETRY_PROPS.has(match[1])) continue;
|
|
3621
|
+
hits.set(
|
|
3622
|
+
index,
|
|
3623
|
+
`\`${match[1]}="$${match[2]}"\` emits nothing; a dotted token reaches the DOM verbatim, so the property is dropped — the v3 scale key is kebab and bare: \`${match[1]}="${match[2].replace(".", "-")}"\``,
|
|
3624
|
+
);
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
|
|
3628
|
+
function addTagPropHits(src, code, hits) {
|
|
3629
|
+
for (const match of src.matchAll(TAG_PROP_RE)) {
|
|
3630
|
+
const index = (match.index ?? 0) + match[0].indexOf("tag");
|
|
3631
|
+
if (code[index] !== 1) continue;
|
|
3632
|
+
hits.set(
|
|
3633
|
+
index,
|
|
3634
|
+
'`tag` is gone in v3 and renders the base element instead; write `render` — `render="button"`, or `render={<a href={link} />}` when the element carries attributes',
|
|
3635
|
+
);
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
|
|
3639
|
+
function addStyledNameHits(src, code, hits) {
|
|
3640
|
+
const styledNames = findStyledNameOptions(src);
|
|
3641
|
+
for (const index of styledNames.sites) {
|
|
3642
|
+
if (code[index] !== 1) continue;
|
|
3643
|
+
hits.set(
|
|
3644
|
+
index,
|
|
3645
|
+
"`name` is not a `styled()` option in v3; it falls into `...defaultProps`, so it emits no class and, on an input-like base, reaches the DOM as the form field's `name` — rename it to `displayName`, and write `className` by hand where a selector needs the class",
|
|
3646
|
+
);
|
|
3647
|
+
}
|
|
3648
|
+
}
|
|
3649
|
+
|
|
3512
3650
|
/**
|
|
3513
3651
|
* Run structural convention checks over a consumer tree.
|
|
3514
3652
|
*
|
package/oxlint.mjs
CHANGED
|
@@ -84,8 +84,29 @@ export function findHexEscapes(src) {
|
|
|
84
84
|
* A `pseudo-prop-escape: <reason>` line or block comment (FZ-10849). A JSDoc
|
|
85
85
|
* `*` line or a backticked mention is prose about the marker, not the marker.
|
|
86
86
|
*/
|
|
87
|
-
const
|
|
88
|
-
|
|
87
|
+
const PSEUDO_PROP_ESCAPE_HEAD = /(?<!`)(?:\/\/|\/\*)\s*pseudo-prop-escape:/g;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The reason a `pseudo-prop-escape:` comment on one line writes: the text
|
|
91
|
+
* after the marker up to a closing `*\/`, trimmed. A line break other than
|
|
92
|
+
* `\n` may sit only in the space before or after the reason.
|
|
93
|
+
* @param {string} text
|
|
94
|
+
* @returns {string | undefined}
|
|
95
|
+
*/
|
|
96
|
+
function pseudoPropEscapeReason(text) {
|
|
97
|
+
for (const head of text.matchAll(PSEUDO_PROP_ESCAPE_HEAD)) {
|
|
98
|
+
const body = text.slice(head.index + head[0].length).trimStart();
|
|
99
|
+
const lastBreak = Math.max(
|
|
100
|
+
body.lastIndexOf("\r"),
|
|
101
|
+
body.lastIndexOf("\u2028"),
|
|
102
|
+
body.lastIndexOf("\u2029"),
|
|
103
|
+
);
|
|
104
|
+
const close = body.indexOf("*/", lastBreak + 1);
|
|
105
|
+
const reason = (close < 0 ? body : body.slice(0, close)).trimEnd();
|
|
106
|
+
if (!/[\r\u2028\u2029]/.test(reason)) return reason;
|
|
107
|
+
}
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
89
110
|
|
|
90
111
|
/**
|
|
91
112
|
* Every `pseudo-prop-escape:` comment in a source file, with the reason it
|
|
@@ -99,8 +120,8 @@ export function findPseudoPropEscapes(src) {
|
|
|
99
120
|
const sites = [];
|
|
100
121
|
src.split("\n").forEach((text, index) => {
|
|
101
122
|
if (text.trim().startsWith("*")) return;
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
123
|
+
const reason = pseudoPropEscapeReason(text);
|
|
124
|
+
if (reason !== undefined) sites.push({ line: index + 1, reason });
|
|
104
125
|
});
|
|
105
126
|
return sites;
|
|
106
127
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/config",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.6.0",
|
|
4
4
|
"description": "Shared build and test configuration presets for multiplatform.one",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
"@babel/parser": "^7.29.9",
|
|
123
123
|
"@babel/plugin-transform-block-scoping": "^7.29.7",
|
|
124
124
|
"@babel/traverse": "^7.29.10",
|
|
125
|
-
"@multiplatform.one/utils": "^10.
|
|
125
|
+
"@multiplatform.one/utils": "^10.6.0",
|
|
126
126
|
"@tamagui/vite-plugin": "3.2.3",
|
|
127
127
|
"@vitejs/plugin-react": "^6.1.2",
|
|
128
128
|
"dotenv": "^17.4.2",
|