@multiplatform.one/config 9.17.0 → 10.0.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 +29 -6
- package/lib/index.js +4 -4
- package/lib/{storybook-BpaziEtP.js → storybook-BRZwQLAM.js} +150 -9
- package/lib/storybook.js +1 -1
- package/lib/{tamaguiWorkspacePaths-DR3dud79.js → tamaguiWorkspacePaths-BFMQNk1l.js} +8 -5
- package/lib/{vite-CgiDLR6V.js → vite-DaBjbGS0.js} +40 -52
- package/lib/vite.js +4 -4
- package/lib/{vitest-B2vcGrZM.js → vitest-NTT7k5jB.js} +97 -10
- package/lib/vitest.js +2 -2
- package/lib/{workspacePublicPackages-DN-1LPcH.js → workspacePublicPackages-z0fVhgGN.js} +121 -8
- package/lint.mjs +874 -52
- package/oxlint.mjs +26 -1
- package/package.json +6 -6
- package/press-lint.mjs +86 -5
- package/spec-registry.mjs +15 -0
- package/src/lint.spec.ts +696 -12
- package/src/movedDepAliases.spec.ts +73 -0
- package/src/movedDepAliases.ts +91 -0
- package/src/nativeBlockScoping.spec.ts +12 -14
- package/src/nativeOnlyDepStubs.spec.ts +178 -0
- package/src/nativeOnlyDepStubs.ts +215 -0
- package/src/noVoicelessText.rule.spec.ts +1 -1
- package/src/noVoicelessText.spec.ts +1 -1
- package/src/oxlint.spec.ts +5 -5
- package/src/phosphorNativeInk.spec.ts +17 -18
- package/src/phosphorTokenColor.spec.ts +35 -0
- package/src/phosphorTokenColor.ts +8 -5
- package/src/press-lint.spec.ts +64 -3
- package/src/react-native.config.cjs +9 -0
- package/src/shims/phosphorThemeInk.js +6 -1
- package/src/shims/svgTouchSound.web.js +23 -0
- package/src/singletonDepAliases.spec.ts +99 -14
- package/src/singletonDepAliases.ts +102 -7
- package/src/storybook.spec.ts +0 -3
- package/src/storybook.ts +17 -6
- package/src/vite.nativeEntries.spec.ts +21 -20
- package/src/vite.spec.ts +11 -20
- package/src/vite.ts +44 -68
- package/src/vitest.spec.ts +142 -4
- package/src/vitest.ts +106 -8
- package/types/movedDepAliases.d.ts +8 -0
- package/types/movedDepAliases.d.ts.map +1 -0
- package/types/nativeOnlyDepStubs.d.ts +41 -0
- package/types/nativeOnlyDepStubs.d.ts.map +1 -0
- package/types/phosphorTokenColor.d.ts.map +1 -1
- package/types/singletonDepAliases.d.ts +55 -3
- package/types/singletonDepAliases.d.ts.map +1 -1
- package/types/storybook.d.ts.map +1 -1
- package/types/vite.d.ts +10 -1
- package/types/vite.d.ts.map +1 -1
- package/types/vitest.d.ts +46 -1
- package/types/vitest.d.ts.map +1 -1
package/src/lint.spec.ts
CHANGED
|
@@ -1033,6 +1033,17 @@ describe("a scaffolded project, where apps/one is renamed and public/ is pruned
|
|
|
1033
1033
|
expect(run(root).code).toBe(token === "ease" ? 1 : 0);
|
|
1034
1034
|
});
|
|
1035
1035
|
|
|
1036
|
+
it("passes a reasoned pseudo-prop escape when the spec, and its escape table, is pruned", () => {
|
|
1037
|
+
const root = makeTree();
|
|
1038
|
+
writeFileSync(
|
|
1039
|
+
join(root, "apps", "demo", "App.tsx"),
|
|
1040
|
+
'import { View } from "tamagui";\n// pseudo-prop-escape: the value is a live measurement, not a token\nexport const App = ({ h }) => <View hoverStyle={{ height: h }} />;\n',
|
|
1041
|
+
);
|
|
1042
|
+
const { code, errors } = run(root);
|
|
1043
|
+
expect(errors).not.toMatch(/undeclared escape/);
|
|
1044
|
+
expect(code).toBe(0);
|
|
1045
|
+
});
|
|
1046
|
+
|
|
1036
1047
|
it("passes a registered transition when the registry is readable", () => {
|
|
1037
1048
|
const root = makeTree();
|
|
1038
1049
|
animationRegistry(root);
|
|
@@ -1332,6 +1343,17 @@ describe("LC-24 enter/exit driver (MPO-327)", () => {
|
|
|
1332
1343
|
});
|
|
1333
1344
|
|
|
1334
1345
|
it("accepts the transitionProps spread as the driver", () => {
|
|
1346
|
+
const root = makeTree();
|
|
1347
|
+
writeFileSync(
|
|
1348
|
+
join(root, "apps", "demo", "App.tsx"),
|
|
1349
|
+
'export const App = () => <View opacity="enter:0" {...transitionProps(knobProps.motion.overlay)} />;\n',
|
|
1350
|
+
);
|
|
1351
|
+
const { code, errors } = run(root);
|
|
1352
|
+
expect(errors).not.toMatch(/LC-24/);
|
|
1353
|
+
expect(code).toBe(0);
|
|
1354
|
+
});
|
|
1355
|
+
|
|
1356
|
+
it("clears LC-24 for a driven v2 enterStyle but still fails it on V3-CLAUSE", () => {
|
|
1335
1357
|
const root = makeTree();
|
|
1336
1358
|
writeFileSync(
|
|
1337
1359
|
join(root, "apps", "demo", "App.tsx"),
|
|
@@ -1339,8 +1361,282 @@ describe("LC-24 enter/exit driver (MPO-327)", () => {
|
|
|
1339
1361
|
);
|
|
1340
1362
|
const { code, errors } = run(root);
|
|
1341
1363
|
expect(errors).not.toMatch(/LC-24/);
|
|
1364
|
+
expect(errors).toMatch(/apps\/demo\/App\.tsx:1 — `enterStyle` emits nothing/);
|
|
1365
|
+
expect(code).toBe(1);
|
|
1366
|
+
});
|
|
1367
|
+
|
|
1368
|
+
it.each([
|
|
1369
|
+
'<View opacity="enter:0" />',
|
|
1370
|
+
'<View opacity="1 exit:0" />',
|
|
1371
|
+
'<View y={"0 dark:enter:-10px"} />',
|
|
1372
|
+
])("fails a Tamagui 3 enter/exit clause with no transition: %s", (tag) => {
|
|
1373
|
+
const root = makeTree();
|
|
1374
|
+
writeFileSync(join(root, "apps", "demo", "App.tsx"), `export const App = () => ${tag};\n`);
|
|
1375
|
+
const { code, errors } = run(root);
|
|
1376
|
+
expect(code).toBe(1);
|
|
1377
|
+
expect(errors).toMatch(/apps\/demo\/App\.tsx:1 — enter\/exitStyle with no `transition` driver/);
|
|
1378
|
+
});
|
|
1379
|
+
|
|
1380
|
+
it.each([
|
|
1381
|
+
'<View opacity="1 enter:0" transition="quick" />',
|
|
1382
|
+
'<View opacity="enter:0" {...transitionProps(knobProps.motion.overlay)} />',
|
|
1383
|
+
'<View opacity="1 group-enter/card:0 hover:0.9" aria-label="exit: now" />',
|
|
1384
|
+
])("passes a driven or unrelated clause: %s", (tag) => {
|
|
1385
|
+
const root = makeTree();
|
|
1386
|
+
writeFileSync(join(root, "apps", "demo", "App.tsx"), `export const App = () => ${tag};\n`);
|
|
1387
|
+
expect(run(root).errors).not.toMatch(/LC-24/);
|
|
1388
|
+
});
|
|
1389
|
+
});
|
|
1390
|
+
|
|
1391
|
+
describe("v2 pseudo style props (FZ-10849 V3-CLAUSE)", () => {
|
|
1392
|
+
const spec = "docs/theme-propagation-spec.md";
|
|
1393
|
+
|
|
1394
|
+
/** A tree with the escape table, and the ratchet when `baseline` is given. */
|
|
1395
|
+
function tree(escapes: [string, string][], baseline?: Record<string, number>) {
|
|
1396
|
+
const root = makeTree();
|
|
1397
|
+
mkdirSync(join(root, "docs"), { recursive: true });
|
|
1398
|
+
const rows = escapes.length
|
|
1399
|
+
? escapes.map(([file, reason]) => `| \`${file}\` | \`${reason}\` |`).join("\n")
|
|
1400
|
+
: "| _(none)_ | _(none)_ |";
|
|
1401
|
+
writeFileSync(
|
|
1402
|
+
join(root, spec),
|
|
1403
|
+
`## Pseudo-prop escapes\n\n| File | Reason |\n| --- | --- |\n${rows}\n`,
|
|
1404
|
+
);
|
|
1405
|
+
if (baseline) {
|
|
1406
|
+
writeFileSync(
|
|
1407
|
+
join(root, "docs", "pseudo-prop-baselines.json"),
|
|
1408
|
+
`${JSON.stringify({ sites: baseline })}\n`,
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1411
|
+
return root;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
function run(root: string) {
|
|
1415
|
+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
1416
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
1417
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
1418
|
+
const code = runConventionChecks({ roots: { root } });
|
|
1419
|
+
const messages = error.mock.calls.map((call) => String(call[0])).join("\n");
|
|
1420
|
+
error.mockRestore();
|
|
1421
|
+
log.mockRestore();
|
|
1422
|
+
warn.mockRestore();
|
|
1423
|
+
return { code, messages };
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
const app = join("apps", "demo", "App.tsx");
|
|
1427
|
+
|
|
1428
|
+
it.each([
|
|
1429
|
+
["hoverStyle", "hover:"],
|
|
1430
|
+
["pressStyle", "press:"],
|
|
1431
|
+
["focusStyle", "focus:"],
|
|
1432
|
+
["focusVisibleStyle", "focus-visible:"],
|
|
1433
|
+
["focusWithinStyle", "focus-within:"],
|
|
1434
|
+
["enterStyle", "enter:"],
|
|
1435
|
+
["exitStyle", "exit:"],
|
|
1436
|
+
])("fails the JSX attribute %s and names the %s clause", (prop, clause) => {
|
|
1437
|
+
const root = tree([]);
|
|
1438
|
+
writeFileSync(
|
|
1439
|
+
join(root, app),
|
|
1440
|
+
`import { View } from "tamagui";\nexport const App = () => <View transition="quick" ${prop}={{ opacity: 0.5 }} />;\n`,
|
|
1441
|
+
);
|
|
1442
|
+
const { code, messages } = run(root);
|
|
1443
|
+
expect(code).toBe(1);
|
|
1444
|
+
expect(messages).toContain(`apps/demo/App.tsx:2 — \`${prop}\` emits nothing`);
|
|
1445
|
+
expect(messages).toContain(`write the \`${clause}\` clause`);
|
|
1446
|
+
});
|
|
1447
|
+
|
|
1448
|
+
it("fails the same key inside styled() options, where it is just as inert", () => {
|
|
1449
|
+
const root = tree([]);
|
|
1450
|
+
writeFileSync(
|
|
1451
|
+
join(root, app),
|
|
1452
|
+
'import { View, styled } from "tamagui";\nexport const Frame = styled(View, { opacity: 1, hoverStyle: { opacity: 0.5 } });\n',
|
|
1453
|
+
);
|
|
1454
|
+
const { code, messages } = run(root);
|
|
1455
|
+
expect(code).toBe(1);
|
|
1456
|
+
expect(messages).toContain("apps/demo/App.tsx:2 — `hoverStyle` emits nothing");
|
|
1457
|
+
});
|
|
1458
|
+
|
|
1459
|
+
it("fails a $-prefixed media prop", () => {
|
|
1460
|
+
const root = tree([]);
|
|
1461
|
+
writeFileSync(
|
|
1462
|
+
join(root, app),
|
|
1463
|
+
'import { View } from "tamagui";\nexport const App = () => <View $sm={{ opacity: 0.5 }} $max-md={{ display: "none" }} />;\n',
|
|
1464
|
+
);
|
|
1465
|
+
const { code, messages } = run(root);
|
|
1466
|
+
expect(code).toBe(1);
|
|
1467
|
+
expect(messages).toContain("`$sm` emits nothing; write the `sm:` clause");
|
|
1468
|
+
expect(messages).toContain("`$max-md` emits nothing; write the `max-md:` clause");
|
|
1469
|
+
});
|
|
1470
|
+
|
|
1471
|
+
it("passes the clause forms, kebab focus-visible included", () => {
|
|
1472
|
+
const root = tree([]);
|
|
1473
|
+
writeFileSync(
|
|
1474
|
+
join(root, app),
|
|
1475
|
+
'import { View } from "tamagui";\nexport const App = () => <View backgroundColor="background hover:background-hover" opacity="1 focus-visible:0.5" padding="4 sm:6" transition="quick" y="0px enter:-25px" />;\n',
|
|
1476
|
+
);
|
|
1477
|
+
const { code, messages } = run(root);
|
|
1478
|
+
expect(messages).not.toContain("V3-CLAUSE");
|
|
1342
1479
|
expect(code).toBe(0);
|
|
1343
1480
|
});
|
|
1481
|
+
|
|
1482
|
+
it("passes a typed clause object and the house state fragments", () => {
|
|
1483
|
+
const root = tree([]);
|
|
1484
|
+
writeFileSync(
|
|
1485
|
+
join(root, app),
|
|
1486
|
+
'import { View } from "tamagui";\nimport { composeKnobs, pickStates } from "@multiplatform.one/theme";\nexport const App = ({ control, props }) => <View {...composeKnobs({ backgroundColor: { default: "background", hover: "background-hover" } }, pickStates(control, "hover", "press"), props)} />;\n',
|
|
1487
|
+
);
|
|
1488
|
+
expect(run(root).code).toBe(0);
|
|
1489
|
+
});
|
|
1490
|
+
|
|
1491
|
+
it("leaves a styled-components transient prop alone: $ means something else there", () => {
|
|
1492
|
+
const root = tree([]);
|
|
1493
|
+
writeFileSync(
|
|
1494
|
+
join(root, app),
|
|
1495
|
+
'import styled from "styled-components";\nexport const Button = styled.button`\n color: red;\n`;\nexport const o = { $variant: "primary", $useTheme: true, $small: false };\n',
|
|
1496
|
+
);
|
|
1497
|
+
expect(run(root).code).toBe(0);
|
|
1498
|
+
});
|
|
1499
|
+
|
|
1500
|
+
it("leaves MPO's own disabledStyle knob alone", () => {
|
|
1501
|
+
const root = tree([]);
|
|
1502
|
+
writeFileSync(
|
|
1503
|
+
join(root, app),
|
|
1504
|
+
'import { View } from "tamagui";\nexport const knobs = { disabledStyle: "keepLabel", timestampStyle: "absolute", fillStyle: "solid" };\n',
|
|
1505
|
+
);
|
|
1506
|
+
expect(run(root).code).toBe(0);
|
|
1507
|
+
});
|
|
1508
|
+
|
|
1509
|
+
it("counts a baselined file as owed, not as a failure, and fails one site over", () => {
|
|
1510
|
+
const root = tree([], { "apps/demo/App.tsx": 1 });
|
|
1511
|
+
writeFileSync(
|
|
1512
|
+
join(root, app),
|
|
1513
|
+
'import { View } from "tamagui";\nexport const App = () => <View transition="quick" enterStyle={{ opacity: 0 }} />;\n',
|
|
1514
|
+
);
|
|
1515
|
+
expect(run(root).code).toBe(0);
|
|
1516
|
+
|
|
1517
|
+
writeFileSync(
|
|
1518
|
+
join(root, app),
|
|
1519
|
+
'import { View } from "tamagui";\nexport const App = () => <View transition="quick" enterStyle={{ opacity: 0 }} exitStyle={{ opacity: 0 }} />;\n',
|
|
1520
|
+
);
|
|
1521
|
+
const { code, messages } = run(root);
|
|
1522
|
+
expect(code).toBe(1);
|
|
1523
|
+
expect(messages).toContain("`exitStyle` emits nothing");
|
|
1524
|
+
});
|
|
1525
|
+
|
|
1526
|
+
it("fails a ratchet nobody lowered after the conversion landed", () => {
|
|
1527
|
+
const root = tree([], { "apps/demo/App.tsx": 2 });
|
|
1528
|
+
writeFileSync(
|
|
1529
|
+
join(root, app),
|
|
1530
|
+
'import { View } from "tamagui";\nexport const App = () => <View opacity="1 enter:0" transition="quick" />;\n',
|
|
1531
|
+
);
|
|
1532
|
+
const { code, messages } = run(root);
|
|
1533
|
+
expect(code).toBe(1);
|
|
1534
|
+
expect(messages).toContain("apps/demo/App.tsx is down to 0 from 2 — lower the ratchet");
|
|
1535
|
+
});
|
|
1536
|
+
|
|
1537
|
+
it("needs the spec row as well as the comment, and fails a stale row", () => {
|
|
1538
|
+
const reason = "the value is a live measurement, not a token";
|
|
1539
|
+
const escaped =
|
|
1540
|
+
'import { View } from "tamagui";\n// pseudo-prop-escape: the value is a live measurement, not a token\nexport const App = ({ h }) => <View hoverStyle={{ height: h }} />;\n';
|
|
1541
|
+
|
|
1542
|
+
const undeclared = tree([]);
|
|
1543
|
+
writeFileSync(join(undeclared, app), escaped);
|
|
1544
|
+
const first = run(undeclared);
|
|
1545
|
+
expect(first.code).toBe(1);
|
|
1546
|
+
expect(first.messages).toContain(`apps/demo/App.tsx:3 — undeclared escape "${reason}"`);
|
|
1547
|
+
|
|
1548
|
+
const declared = tree([["apps/demo/App.tsx", reason]]);
|
|
1549
|
+
writeFileSync(join(declared, app), escaped);
|
|
1550
|
+
expect(run(declared).code).toBe(0);
|
|
1551
|
+
|
|
1552
|
+
const stale = tree([["apps/demo/App.tsx", reason]]);
|
|
1553
|
+
writeFileSync(
|
|
1554
|
+
join(stale, app),
|
|
1555
|
+
'import { View } from "tamagui";\nexport const App = () => null;\n',
|
|
1556
|
+
);
|
|
1557
|
+
const third = run(stale);
|
|
1558
|
+
expect(third.code).toBe(1);
|
|
1559
|
+
expect(third.messages).toContain(
|
|
1560
|
+
`apps/demo/App.tsx — declared escape "${reason}" has no comment in the code`,
|
|
1561
|
+
);
|
|
1562
|
+
});
|
|
1563
|
+
|
|
1564
|
+
it("fails a quoted `$` modifier key, which the first draft of this check missed", () => {
|
|
1565
|
+
const root = tree([]);
|
|
1566
|
+
writeFileSync(
|
|
1567
|
+
join(root, app),
|
|
1568
|
+
'import { View } from "tamagui";\nexport const f = { "$max-sm": { padding: 0 } };\n',
|
|
1569
|
+
);
|
|
1570
|
+
const { code, messages } = run(root);
|
|
1571
|
+
expect(code).toBe(1);
|
|
1572
|
+
expect(messages).toContain("`$max-sm` emits nothing");
|
|
1573
|
+
});
|
|
1574
|
+
|
|
1575
|
+
it("fails `name` at styled() options level but not a data or story `name` key", () => {
|
|
1576
|
+
const root = tree([]);
|
|
1577
|
+
writeFileSync(
|
|
1578
|
+
join(root, app),
|
|
1579
|
+
'import { View, styled } from "tamagui";\n' +
|
|
1580
|
+
'export const Frame = styled(View, { name: "Frame", opacity: 1 });\n' +
|
|
1581
|
+
'export const Ok = styled(View, { displayName: "Ok", opacity: 1 });\n' +
|
|
1582
|
+
'export const rows = [{ name: "alice" }, { name: "bob" }];\n' +
|
|
1583
|
+
'export const meta = { title: "X", args: { name: "n" } };\n' +
|
|
1584
|
+
'export const Nested = styled(View, { displayName: "N", variants: { v: { true: { name: 1 } } } });\n',
|
|
1585
|
+
);
|
|
1586
|
+
const { code, messages } = run(root);
|
|
1587
|
+
expect(code).toBe(1);
|
|
1588
|
+
const clause = messages.slice(messages.indexOf("FZ-10849 V3-CLAUSE"));
|
|
1589
|
+
const block = clause.includes("\nConvention (")
|
|
1590
|
+
? clause.slice(0, clause.indexOf("\nConvention ("))
|
|
1591
|
+
: clause;
|
|
1592
|
+
expect(block).toContain("apps/demo/App.tsx:2 — `name` is not a `styled()` option");
|
|
1593
|
+
expect(block).not.toContain("apps/demo/App.tsx:3");
|
|
1594
|
+
expect(block).not.toContain("apps/demo/App.tsx:4");
|
|
1595
|
+
expect(block).not.toContain("apps/demo/App.tsx:5");
|
|
1596
|
+
expect(block).not.toContain("apps/demo/App.tsx:6");
|
|
1597
|
+
});
|
|
1598
|
+
|
|
1599
|
+
it("fails a dotted token on a geometry prop and leaves a currency string alone", () => {
|
|
1600
|
+
const root = tree([]);
|
|
1601
|
+
writeFileSync(
|
|
1602
|
+
join(root, app),
|
|
1603
|
+
'import { View } from "tamagui";\n' +
|
|
1604
|
+
'export const A = () => <View paddingHorizontal="$2.5" gap="2" price="$2.50" />;\n' +
|
|
1605
|
+
'export const d = { price: "$9.99", label: "$1.50" };\n',
|
|
1606
|
+
);
|
|
1607
|
+
const { code, messages } = run(root);
|
|
1608
|
+
expect(code).toBe(1);
|
|
1609
|
+
expect(messages).toContain('`paddingHorizontal="$2.5"` emits nothing');
|
|
1610
|
+
expect(messages).not.toContain('`price="$2.50"` emits nothing');
|
|
1611
|
+
expect(messages).not.toContain("apps/demo/App.tsx:3");
|
|
1612
|
+
});
|
|
1613
|
+
|
|
1614
|
+
it("fails the `tag` ATTRIBUTE and leaves a `tag:` data key alone", () => {
|
|
1615
|
+
const root = tree([]);
|
|
1616
|
+
writeFileSync(
|
|
1617
|
+
join(root, app),
|
|
1618
|
+
'import { View } from "tamagui";\n' +
|
|
1619
|
+
'export const A = () => <View tag="button" />;\n' +
|
|
1620
|
+
'export const map = { h1: { tag: "h1" }, h2: { tag: "h2" } };\n' +
|
|
1621
|
+
"export const sel = 'style[data-tag=\"content\"]';\n",
|
|
1622
|
+
);
|
|
1623
|
+
const { code, messages } = run(root);
|
|
1624
|
+
expect(code).toBe(1);
|
|
1625
|
+
expect(messages).toContain("apps/demo/App.tsx:2 — `tag` is gone in v3");
|
|
1626
|
+
expect(messages).not.toContain("apps/demo/App.tsx:3");
|
|
1627
|
+
expect(messages).not.toContain("apps/demo/App.tsx:4");
|
|
1628
|
+
});
|
|
1629
|
+
|
|
1630
|
+
it("fails an escape comment with no written reason", () => {
|
|
1631
|
+
const root = tree([]);
|
|
1632
|
+
writeFileSync(
|
|
1633
|
+
join(root, app),
|
|
1634
|
+
'import { View } from "tamagui";\n// pseudo-prop-escape:\nexport const App = ({ h }) => <View hoverStyle={{ height: h }} />;\n',
|
|
1635
|
+
);
|
|
1636
|
+
const { code, messages } = run(root);
|
|
1637
|
+
expect(code).toBe(1);
|
|
1638
|
+
expect(messages).toContain("apps/demo/App.tsx:3 — pseudo-prop-escape with no written reason");
|
|
1639
|
+
});
|
|
1344
1640
|
});
|
|
1345
1641
|
|
|
1346
1642
|
describe("foreign control specimen in stories (LC-56 STORY-HONESTY / MPO-316)", () => {
|
|
@@ -1634,12 +1930,12 @@ describe("the v5 theme registry", () => {
|
|
|
1634
1930
|
try {
|
|
1635
1931
|
writeFileSync(
|
|
1636
1932
|
app,
|
|
1637
|
-
'export const App = () => <View theme="gray"><View theme="purple" color="$
|
|
1933
|
+
'export const App = () => <View theme="gray"><View theme="purple" color="$neutral-9" /><View theme="SliderActive" color="$teal-9" backgroundColor="$background-press" borderColor="$border-color" /><View theme="active" color="$color-0" /><View theme="alt1" color="$accent-color" /><View color="$syntax-blue" /><View color="$color-transparent" /></View>;',
|
|
1638
1934
|
);
|
|
1639
1935
|
expect(runConventionChecks({ roots: { root } })).toBe(0);
|
|
1640
1936
|
writeFileSync(
|
|
1641
1937
|
app,
|
|
1642
|
-
'export const App = () => <View theme="SwitchThumb"><View theme="mauve" /><View theme="teal" /><View theme="neutral" /><View theme="surface1" color="$amber9" /><View backgroundColor="$backgroundStrong" /><View backgroundColor="$backgroundTransparent" /><View color="$
|
|
1938
|
+
'export const App = () => <View theme="SwitchThumb"><View theme="mauve" /><View theme="teal" /><View theme="neutral" /><View theme="surface1" color="$amber9" /><View backgroundColor="$backgroundStrong" /><View backgroundColor="$backgroundTransparent" /><View color="$color-transparent" /></View>;',
|
|
1643
1939
|
);
|
|
1644
1940
|
expect(runConventionChecks({ roots: { root } })).toBe(1);
|
|
1645
1941
|
const errors = error.mock.calls.flat().join("\n");
|
|
@@ -1658,6 +1954,37 @@ describe("the v5 theme registry", () => {
|
|
|
1658
1954
|
}
|
|
1659
1955
|
});
|
|
1660
1956
|
|
|
1957
|
+
it("builds theme names with @tamagui/themes/builder: a known name passes, an unknown one fails", () => {
|
|
1958
|
+
const root = makeTree();
|
|
1959
|
+
symlinkSync(join(process.cwd(), "../../node_modules"), join(root, "node_modules"), "dir");
|
|
1960
|
+
const app = join(root, "apps/demo/App.tsx");
|
|
1961
|
+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
1962
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
1963
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
1964
|
+
try {
|
|
1965
|
+
writeFileSync(
|
|
1966
|
+
app,
|
|
1967
|
+
'export const App = () => <View theme="light_blue_Button"><View theme="dark_accent_Card" /><View theme="warning" /><View theme="alt2" /><Theme name="light_blue_Button"><Theme\n key="a"\n name="dark" /></Theme></View>;',
|
|
1968
|
+
);
|
|
1969
|
+
expect(runConventionChecks({ roots: { root } })).toBe(0);
|
|
1970
|
+
expect(warn.mock.calls.flat().join("\n")).not.toMatch(/skipped the theme name check/);
|
|
1971
|
+
for (const bad of ["light_blue_alt1_Button", "dark_accent_alt1", "brand", "level2"]) {
|
|
1972
|
+
error.mockClear();
|
|
1973
|
+
writeFileSync(app, `export const App = () => <View theme="${bad}" />;`);
|
|
1974
|
+
expect(runConventionChecks({ roots: { root } }), bad).toBe(1);
|
|
1975
|
+
expect(error.mock.calls.flat().join("\n")).toContain(`theme="${bad}"`);
|
|
1976
|
+
error.mockClear();
|
|
1977
|
+
writeFileSync(app, `export const App = () => <Theme name={"${bad}"}><View /></Theme>;`);
|
|
1978
|
+
expect(runConventionChecks({ roots: { root } }), bad).toBe(1);
|
|
1979
|
+
expect(error.mock.calls.flat().join("\n")).toContain(`<Theme name="${bad}">`);
|
|
1980
|
+
}
|
|
1981
|
+
} finally {
|
|
1982
|
+
error.mockRestore();
|
|
1983
|
+
log.mockRestore();
|
|
1984
|
+
warn.mockRestore();
|
|
1985
|
+
}
|
|
1986
|
+
});
|
|
1987
|
+
|
|
1661
1988
|
it("resolves keys only the theme post-passes write, and still rejects an unknown key", () => {
|
|
1662
1989
|
const root = makeTree();
|
|
1663
1990
|
symlinkSync(join(process.cwd(), "../../node_modules"), join(root, "node_modules"), "dir");
|
|
@@ -1668,7 +1995,7 @@ describe("the v5 theme registry", () => {
|
|
|
1668
1995
|
try {
|
|
1669
1996
|
writeFileSync(
|
|
1670
1997
|
app,
|
|
1671
|
-
'export const App = () => <View borderColor="$
|
|
1998
|
+
'export const App = () => <View borderColor="$border-color-field"><View borderColor="$border-color-field-hover" /><View color="$identity-ink" /><View color="$accent-on-surface" /><View borderColor="$switch-track-off-border" /></View>;',
|
|
1672
1999
|
);
|
|
1673
2000
|
expect(runConventionChecks({ roots: { root } })).toBe(0);
|
|
1674
2001
|
writeFileSync(app, 'export const App = () => <View borderColor="$notAKey" />;');
|
|
@@ -1680,6 +2007,38 @@ describe("the v5 theme registry", () => {
|
|
|
1680
2007
|
warn.mockRestore();
|
|
1681
2008
|
}
|
|
1682
2009
|
});
|
|
2010
|
+
|
|
2011
|
+
it("checks Tamagui 3 kebab keys and flat values: a known key passes, an unknown one fails", () => {
|
|
2012
|
+
const root = makeTree();
|
|
2013
|
+
symlinkSync(join(process.cwd(), "../../node_modules"), join(root, "node_modules"), "dir");
|
|
2014
|
+
const app = join(root, "apps/demo/App.tsx");
|
|
2015
|
+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
2016
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
2017
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
2018
|
+
try {
|
|
2019
|
+
writeFileSync(
|
|
2020
|
+
app,
|
|
2021
|
+
'export const App = () => <View color="$color-11" backgroundColor="background hover:background-hover press:$color-5" borderColor="border-color-field group-hover/card:outline-color" bg="color-2 dark:selected-background" shadowColor="transparent" fill="currentColor" />;',
|
|
2022
|
+
);
|
|
2023
|
+
expect(runConventionChecks({ roots: { root } })).toBe(0);
|
|
2024
|
+
expect(warn.mock.calls.flat().join("\n")).not.toMatch(/skipped the style token check/);
|
|
2025
|
+
for (const bad of [
|
|
2026
|
+
'color="$color-13"',
|
|
2027
|
+
'backgroundColor="background hover:background-hoverr"',
|
|
2028
|
+
'borderColor="border-color press:$border-colour"',
|
|
2029
|
+
'bg="color12"',
|
|
2030
|
+
]) {
|
|
2031
|
+
error.mockClear();
|
|
2032
|
+
writeFileSync(app, `export const App = () => <View ${bad} />;`);
|
|
2033
|
+
expect(runConventionChecks({ roots: { root } }), bad).toBe(1);
|
|
2034
|
+
expect(error.mock.calls.flat().join("\n")).toContain(bad);
|
|
2035
|
+
}
|
|
2036
|
+
} finally {
|
|
2037
|
+
error.mockRestore();
|
|
2038
|
+
log.mockRestore();
|
|
2039
|
+
warn.mockRestore();
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
1683
2042
|
});
|
|
1684
2043
|
|
|
1685
2044
|
describe("layout rules (LC-101 ONE-SIDEBAR, LC-102 HUG-CONTENT, LC-103 RESPONSIVE-PARITY)", () => {
|
|
@@ -1775,6 +2134,26 @@ describe("layout rules (LC-101 ONE-SIDEBAR, LC-102 HUG-CONTENT, LC-103 RESPONSIV
|
|
|
1775
2134
|
expect(messages).not.toContain("Fine.tsx");
|
|
1776
2135
|
});
|
|
1777
2136
|
|
|
2137
|
+
it("counts a spread justification inside a Tamagui 3 flat value", () => {
|
|
2138
|
+
const root = layoutTree({ hugContent: { "features/demo/Row.tsx": 1 } });
|
|
2139
|
+
write(
|
|
2140
|
+
root,
|
|
2141
|
+
"features/demo/Row.tsx",
|
|
2142
|
+
'export const R = () => <><XStack justifyContent="flex-start md:space-between" /><XStack justifyContent={"space-evenly hover:center"} /><XStack justifyContent="center" /></>;\n',
|
|
2143
|
+
);
|
|
2144
|
+
write(
|
|
2145
|
+
root,
|
|
2146
|
+
"features/demo/Fine.tsx",
|
|
2147
|
+
'export const F = () => <XStack justifyContent="flex-start md:center" aria-label="space-between" />;\n',
|
|
2148
|
+
);
|
|
2149
|
+
const { code, messages } = run(root);
|
|
2150
|
+
expect(code).toBe(1);
|
|
2151
|
+
expect(messages).toContain(
|
|
2152
|
+
'features/demo/Row.tsx:1 — justifyContent="space-evenly" (2 in file, baseline 1)',
|
|
2153
|
+
);
|
|
2154
|
+
expect(messages).not.toContain("Fine.tsx");
|
|
2155
|
+
});
|
|
2156
|
+
|
|
1778
2157
|
it("fails content hidden on phones unless it names its phone twin", () => {
|
|
1779
2158
|
const root = layoutTree({});
|
|
1780
2159
|
write(
|
|
@@ -1801,6 +2180,35 @@ describe("layout rules (LC-101 ONE-SIDEBAR, LC-102 HUG-CONTENT, LC-103 RESPONSIV
|
|
|
1801
2180
|
expect(messages).not.toContain("Toolbar.tsx:7");
|
|
1802
2181
|
});
|
|
1803
2182
|
|
|
2183
|
+
it("reads a Tamagui 3 flat display value the same way", () => {
|
|
2184
|
+
const root = layoutTree({});
|
|
2185
|
+
write(
|
|
2186
|
+
root,
|
|
2187
|
+
"features/demo/Toolbar.tsx",
|
|
2188
|
+
[
|
|
2189
|
+
"export const T = () => (",
|
|
2190
|
+
" <XStack>",
|
|
2191
|
+
' <Button display="flex max-sm:none">Export</Button>',
|
|
2192
|
+
' <Chip display="none md:flex">Draft</Chip>',
|
|
2193
|
+
' <Badge display={"max-xs:none"}>New</Badge>',
|
|
2194
|
+
" {/* responsive-parity: the ⋯ menu carries Print on phones */}",
|
|
2195
|
+
' <Button display="max-md:none">Print</Button>',
|
|
2196
|
+
' <Spacer display="none" />',
|
|
2197
|
+
' <Row display="none dark:flex" />',
|
|
2198
|
+
' <Pane display="flex max-lg:none" />',
|
|
2199
|
+
" </XStack>",
|
|
2200
|
+
");",
|
|
2201
|
+
"",
|
|
2202
|
+
].join("\n"),
|
|
2203
|
+
);
|
|
2204
|
+
const { code, messages } = run(root);
|
|
2205
|
+
expect(code).toBe(1);
|
|
2206
|
+
expect(messages).toContain("features/demo/Toolbar.tsx:3 — hidden on phones");
|
|
2207
|
+
expect(messages).toContain("features/demo/Toolbar.tsx:4 — hidden on phones");
|
|
2208
|
+
expect(messages).toContain("features/demo/Toolbar.tsx:5 — hidden on phones");
|
|
2209
|
+
for (const line of [7, 8, 9, 10]) expect(messages).not.toContain(`Toolbar.tsx:${line} `);
|
|
2210
|
+
});
|
|
2211
|
+
|
|
1804
2212
|
it("skips every layout check in a project without the baselines (docs/ pruned)", () => {
|
|
1805
2213
|
const root = makeTree();
|
|
1806
2214
|
write(
|
|
@@ -1934,8 +2342,11 @@ describe("accent solid owners (LC-05 ONE-EMPHASIS)", () => {
|
|
|
1934
2342
|
}
|
|
1935
2343
|
|
|
1936
2344
|
it.each([
|
|
1937
|
-
'export const Selected = () => <View backgroundColor="$
|
|
2345
|
+
'export const Selected = () => <View backgroundColor="$accent-background" />;',
|
|
1938
2346
|
"export const fill = theme.accentBackground?.val;",
|
|
2347
|
+
'export const Selected = () => <View bg="background hover:accent-background" />;',
|
|
2348
|
+
'export const fill = theme["accent-background"]?.val;',
|
|
2349
|
+
'export const fill = "var(--accent-background)";',
|
|
1939
2350
|
])("fails an accent solid in a component: %s", (source) => {
|
|
1940
2351
|
const { code, messages } = run(source);
|
|
1941
2352
|
expect(code).toBe(1);
|
|
@@ -1946,7 +2357,7 @@ describe("accent solid owners (LC-05 ONE-EMPHASIS)", () => {
|
|
|
1946
2357
|
it.each(["apps/demo", "features/demo", "packages/ui/src"])(
|
|
1947
2358
|
"scans %s as well as published sources",
|
|
1948
2359
|
(dir) => {
|
|
1949
|
-
expect(run('export const fill = "$
|
|
2360
|
+
expect(run('export const fill = "$accent-background";', `${dir}/fill.mjs`).code).toBe(1);
|
|
1950
2361
|
},
|
|
1951
2362
|
);
|
|
1952
2363
|
|
|
@@ -1956,14 +2367,16 @@ describe("accent solid owners (LC-05 ONE-EMPHASIS)", () => {
|
|
|
1956
2367
|
"public/theme/src/theme/createThemes.ts",
|
|
1957
2368
|
"public/theme/src/theme/chartPalette.ts",
|
|
1958
2369
|
"public/theme/src/theme/readableColor.ts",
|
|
2370
|
+
"public/theme/src/theme/v5Templates.ts",
|
|
1959
2371
|
])("allows the owner %s", (file) => {
|
|
1960
2372
|
expect(run("export const fill = theme.accentBackground?.val;", file).code).toBe(0);
|
|
2373
|
+
expect(run('export const base = { "accent-background": 0 };', file).code).toBe(0);
|
|
1961
2374
|
});
|
|
1962
2375
|
|
|
1963
2376
|
it("keeps strings containing comment delimiters", () => {
|
|
1964
2377
|
const { code, messages } = run(`const url = "https://example.invalid";
|
|
1965
|
-
const literal = "/* $
|
|
1966
|
-
const value = "// $
|
|
2378
|
+
const literal = "/* $accent-background */";
|
|
2379
|
+
const value = "// $accent-background";`);
|
|
1967
2380
|
expect(code).toBe(1);
|
|
1968
2381
|
expect(messages).toContain("public/components/src/Selected.tsx:2");
|
|
1969
2382
|
expect(messages).toContain("public/components/src/Selected.tsx:3");
|
|
@@ -1971,16 +2384,16 @@ const value = "// $accentBackground";`);
|
|
|
1971
2384
|
|
|
1972
2385
|
it("ignores line, block and JSX comments", () => {
|
|
1973
2386
|
expect(
|
|
1974
|
-
run(`// backgroundColor="$
|
|
2387
|
+
run(`// backgroundColor="$accent-background"
|
|
1975
2388
|
/* theme.accentBackground */
|
|
1976
|
-
export const Selected = () => <View>{/* "$
|
|
2389
|
+
export const Selected = () => <View>{/* "$accent-background" */}</View>;`).code,
|
|
1977
2390
|
).toBe(0);
|
|
1978
2391
|
});
|
|
1979
2392
|
|
|
1980
2393
|
it("ends a quote at the line break, so a JSX apostrophe cannot open a comment", () => {
|
|
1981
2394
|
expect(
|
|
1982
2395
|
run(`export const Hint = () => <Text>Don't pick</Text>;
|
|
1983
|
-
// backgroundColor="$
|
|
2396
|
+
// backgroundColor="$accent-background"
|
|
1984
2397
|
export const Other = () => <Text>It's fine</Text>;`).code,
|
|
1985
2398
|
).toBe(0);
|
|
1986
2399
|
});
|
|
@@ -1988,14 +2401,14 @@ export const Other = () => <Text>It's fine</Text>;`).code,
|
|
|
1988
2401
|
it.each(["stories.tsx", "spec.tsx", "test.tsx", "d.ts"])("ignores %s", (suffix) => {
|
|
1989
2402
|
expect(
|
|
1990
2403
|
run(
|
|
1991
|
-
'const fill = "$
|
|
2404
|
+
'const fill = "$accent-background"; const meta = {};\nexport default meta;',
|
|
1992
2405
|
`public/components/src/Selected.${suffix}`,
|
|
1993
2406
|
).code,
|
|
1994
2407
|
).toBe(0);
|
|
1995
2408
|
});
|
|
1996
2409
|
|
|
1997
2410
|
it("reports every live occurrence with its line", () => {
|
|
1998
|
-
const { messages } = run(`const fill = "$
|
|
2411
|
+
const { messages } = run(`const fill = "$accent-background";
|
|
1999
2412
|
const value = theme.accentBackground;`);
|
|
2000
2413
|
expect(messages).toContain("public/components/src/Selected.tsx:1");
|
|
2001
2414
|
expect(messages).toContain("public/components/src/Selected.tsx:2");
|
|
@@ -2092,3 +2505,274 @@ describe("one tab bar (LC-150 TAB-BAR-ANATOMY, FZ-7995)", () => {
|
|
|
2092
2505
|
expect(code).toBe(0);
|
|
2093
2506
|
});
|
|
2094
2507
|
});
|
|
2508
|
+
|
|
2509
|
+
describe("non-style props in a styled() variant value (LC-303)", () => {
|
|
2510
|
+
/** A tree, and the ratchet when `baseline` is given. */
|
|
2511
|
+
function tree(baseline?: Record<string, number>) {
|
|
2512
|
+
const root = makeTree();
|
|
2513
|
+
mkdirSync(join(root, "public", "demo", "src"), { recursive: true });
|
|
2514
|
+
if (baseline) {
|
|
2515
|
+
mkdirSync(join(root, "docs"), { recursive: true });
|
|
2516
|
+
writeFileSync(
|
|
2517
|
+
join(root, "docs", "variant-attr-baselines.json"),
|
|
2518
|
+
`${JSON.stringify({ sites: baseline })}\n`,
|
|
2519
|
+
);
|
|
2520
|
+
}
|
|
2521
|
+
return root;
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
function run(root: string, source: string, rel = "public/demo/src/Frame.tsx") {
|
|
2525
|
+
writeFileSync(join(root, rel), source);
|
|
2526
|
+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
2527
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
2528
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
2529
|
+
const code = runConventionChecks({ roots: { root } });
|
|
2530
|
+
const messages = error.mock.calls.map((call) => String(call[0])).join("\n");
|
|
2531
|
+
error.mockRestore();
|
|
2532
|
+
log.mockRestore();
|
|
2533
|
+
warn.mockRestore();
|
|
2534
|
+
return { code, messages };
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
const imports = 'import { View, styled } from "tamagui";\n';
|
|
2538
|
+
|
|
2539
|
+
it.each([
|
|
2540
|
+
["role", "web"],
|
|
2541
|
+
["tabIndex", "web"],
|
|
2542
|
+
["accessibilityRole", "native"],
|
|
2543
|
+
["accessibilityLabel", "native"],
|
|
2544
|
+
])("fails `%s` in a variant value and names the target it is missing on", (key, target) => {
|
|
2545
|
+
const root = tree();
|
|
2546
|
+
const { code, messages } = run(
|
|
2547
|
+
root,
|
|
2548
|
+
`${imports}export const Frame = styled(View, {\n variants: { danger: { true: { ${key}: "x" } } },\n});\n`,
|
|
2549
|
+
);
|
|
2550
|
+
expect(code).toBe(1);
|
|
2551
|
+
expect(messages).toContain(
|
|
2552
|
+
`public/demo/src/Frame.tsx:3 — \`${key}\` in variants.danger.true reaches no element on ${target}`,
|
|
2553
|
+
);
|
|
2554
|
+
expect(messages).toContain("write it at the call site (LC-303)");
|
|
2555
|
+
});
|
|
2556
|
+
|
|
2557
|
+
it("follows a variant value that is a module-local constant, the live shape in InputParts", () => {
|
|
2558
|
+
const root = tree();
|
|
2559
|
+
const { code, messages } = run(
|
|
2560
|
+
root,
|
|
2561
|
+
`${imports}const base = {\n borderWidth: 1,\n tabIndex: -1,\n};\nexport const Frame = styled(View, {\n variants: { unstyled: { false: base } },\n});\n`,
|
|
2562
|
+
);
|
|
2563
|
+
expect(code).toBe(1);
|
|
2564
|
+
expect(messages).toContain(
|
|
2565
|
+
"public/demo/src/Frame.tsx:4 — `tabIndex` in variants.unstyled.false = base reaches no element on web",
|
|
2566
|
+
);
|
|
2567
|
+
});
|
|
2568
|
+
|
|
2569
|
+
it("follows either branch of a spread conditional inside a variant value", () => {
|
|
2570
|
+
const root = tree();
|
|
2571
|
+
const { code, messages } = run(
|
|
2572
|
+
root,
|
|
2573
|
+
`${imports}export const Frame = styled(View, {\n variants: { unstyled: { false: { ...(isWeb ? { tabIndex: -1 } : { role: "none" }) } } },\n});\n`,
|
|
2574
|
+
);
|
|
2575
|
+
expect(code).toBe(1);
|
|
2576
|
+
expect(messages).toContain("`tabIndex` in variants.unstyled.false");
|
|
2577
|
+
expect(messages).toContain("`role` in variants.unstyled.false");
|
|
2578
|
+
});
|
|
2579
|
+
|
|
2580
|
+
it("PASSES the same keys in a styled() options object a context guards", () => {
|
|
2581
|
+
const root = tree();
|
|
2582
|
+
const { code, messages } = run(
|
|
2583
|
+
root,
|
|
2584
|
+
`${imports}export const Frame = styled(View, {\n role: "button",\n tabIndex: 0,\n accessibilityRole: "button",\n context: FrameContext,\n variants: { danger: { true: { backgroundColor: "red" } } },\n});\n`,
|
|
2585
|
+
);
|
|
2586
|
+
expect(messages).not.toContain("ATTRIBUTE-AT-THE-CALL-SITE");
|
|
2587
|
+
expect(code).toBe(0);
|
|
2588
|
+
});
|
|
2589
|
+
|
|
2590
|
+
it("PASSES className and a data- key in a variant value, which survive it", () => {
|
|
2591
|
+
const root = tree();
|
|
2592
|
+
const { code, messages } = run(
|
|
2593
|
+
root,
|
|
2594
|
+
`${imports}export const Frame = styled(View, {\n variants: { rail: { true: { className: "is_Rail", "data-radius-class": "R-PILL" } } },\n});\n`,
|
|
2595
|
+
);
|
|
2596
|
+
expect(messages).not.toContain("ATTRIBUTE-AT-THE-CALL-SITE");
|
|
2597
|
+
expect(code).toBe(0);
|
|
2598
|
+
});
|
|
2599
|
+
|
|
2600
|
+
it("PASSES disabled, autoFocus and focusable, which no move would fix", () => {
|
|
2601
|
+
const root = tree();
|
|
2602
|
+
const { code, messages } = run(
|
|
2603
|
+
root,
|
|
2604
|
+
`${imports}export const Frame = styled(View, {\n variants: { off: { true: { disabled: true, autoFocus: false, focusable: false } } },\n});\n`,
|
|
2605
|
+
);
|
|
2606
|
+
expect(messages).not.toContain("ATTRIBUTE-AT-THE-CALL-SITE");
|
|
2607
|
+
expect(code).toBe(0);
|
|
2608
|
+
});
|
|
2609
|
+
|
|
2610
|
+
it("PASSES a props object and a JSX attribute, the shapes a regex cannot tell apart", () => {
|
|
2611
|
+
const root = tree();
|
|
2612
|
+
const { code, messages } = run(
|
|
2613
|
+
root,
|
|
2614
|
+
`${imports}const pressA11y = { role: "button", tabIndex: 0, "aria-label": "Press" };\nexport const Frame = styled(View, { variants: { danger: { true: { opacity: 0.5 } } } });\nexport const App = () => <Frame {...pressA11y} role="button" tabIndex={-1} />;\n`,
|
|
2615
|
+
);
|
|
2616
|
+
expect(messages).not.toContain("ATTRIBUTE-AT-THE-CALL-SITE");
|
|
2617
|
+
expect(code).toBe(0);
|
|
2618
|
+
});
|
|
2619
|
+
|
|
2620
|
+
it("PASSES a styled.dynamic variant, which is a function and holds no keys", () => {
|
|
2621
|
+
const root = tree();
|
|
2622
|
+
const { code, messages } = run(
|
|
2623
|
+
root,
|
|
2624
|
+
`${imports}export const Frame = styled(View, {\n variants: { size: styled.dynamic<number>((val) => ({ height: val })) },\n});\n`,
|
|
2625
|
+
);
|
|
2626
|
+
expect(messages).not.toContain("ATTRIBUTE-AT-THE-CALL-SITE");
|
|
2627
|
+
expect(code).toBe(0);
|
|
2628
|
+
});
|
|
2629
|
+
|
|
2630
|
+
it("holds a baselined file at its count and fails the site past it", () => {
|
|
2631
|
+
const root = tree({ "public/demo/src/Frame.tsx": 1 });
|
|
2632
|
+
const one = run(
|
|
2633
|
+
root,
|
|
2634
|
+
`${imports}export const Frame = styled(View, {\n variants: { unstyled: { false: { tabIndex: -1 } } },\n});\n`,
|
|
2635
|
+
);
|
|
2636
|
+
expect(one.messages).not.toContain("ATTRIBUTE-AT-THE-CALL-SITE");
|
|
2637
|
+
expect(one.code).toBe(0);
|
|
2638
|
+
|
|
2639
|
+
const two = run(
|
|
2640
|
+
root,
|
|
2641
|
+
`${imports}export const Frame = styled(View, {\n variants: { unstyled: { false: { tabIndex: -1, role: "note" } } },\n});\n`,
|
|
2642
|
+
);
|
|
2643
|
+
expect(two.code).toBe(1);
|
|
2644
|
+
expect(two.messages).toContain(
|
|
2645
|
+
"public/demo/src/Frame.tsx:3 — `role` in variants.unstyled.false",
|
|
2646
|
+
);
|
|
2647
|
+
});
|
|
2648
|
+
|
|
2649
|
+
it("ratchets the other way: a row above the live count must come down", () => {
|
|
2650
|
+
const root = tree({ "public/demo/src/Frame.tsx": 2 });
|
|
2651
|
+
const { code, messages } = run(
|
|
2652
|
+
root,
|
|
2653
|
+
`${imports}export const Frame = styled(View, {\n variants: { unstyled: { false: { tabIndex: -1 } } },\n});\n`,
|
|
2654
|
+
);
|
|
2655
|
+
expect(code).toBe(1);
|
|
2656
|
+
expect(messages).toContain(
|
|
2657
|
+
"docs/variant-attr-baselines.json: public/demo/src/Frame.tsx is down to 1 from 2 — lower the ratchet",
|
|
2658
|
+
);
|
|
2659
|
+
});
|
|
2660
|
+
});
|
|
2661
|
+
|
|
2662
|
+
describe("the variant-attr check exempts the files that must write the dead form", () => {
|
|
2663
|
+
function run(rel: string) {
|
|
2664
|
+
const root = makeTree();
|
|
2665
|
+
mkdirSync(join(root, "public", "demo", "src"), { recursive: true });
|
|
2666
|
+
writeFileSync(
|
|
2667
|
+
join(root, rel),
|
|
2668
|
+
'import { View, styled } from "tamagui";\nexport const Frame = styled(View, {\n variants: { unstyled: { false: { role: "note" } } },\n});\n',
|
|
2669
|
+
);
|
|
2670
|
+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
2671
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
2672
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
2673
|
+
const code = runConventionChecks({ roots: { root } });
|
|
2674
|
+
const messages = error.mock.calls.map((call) => String(call[0])).join("\n");
|
|
2675
|
+
error.mockRestore();
|
|
2676
|
+
log.mockRestore();
|
|
2677
|
+
warn.mockRestore();
|
|
2678
|
+
return { code, messages };
|
|
2679
|
+
}
|
|
2680
|
+
|
|
2681
|
+
it.each(["Frame.spec.tsx", "Frame.test.tsx"])("ignores %s", (name) => {
|
|
2682
|
+
const { code, messages } = run(`public/demo/src/${name}`);
|
|
2683
|
+
expect(messages).not.toContain("ATTRIBUTE-AT-THE-CALL-SITE");
|
|
2684
|
+
expect(code).toBe(0);
|
|
2685
|
+
});
|
|
2686
|
+
|
|
2687
|
+
it("still fails the component source beside them", () => {
|
|
2688
|
+
const { code, messages } = run("public/demo/src/Frame.tsx");
|
|
2689
|
+
expect(code).toBe(1);
|
|
2690
|
+
expect(messages).toContain("`role` in variants.unstyled.false");
|
|
2691
|
+
});
|
|
2692
|
+
});
|
|
2693
|
+
|
|
2694
|
+
describe("a semantic attribute in a context-less styled() options object (LC-303)", () => {
|
|
2695
|
+
function tree(baseline?: Record<string, number>) {
|
|
2696
|
+
const root = makeTree();
|
|
2697
|
+
mkdirSync(join(root, "public", "demo", "src"), { recursive: true });
|
|
2698
|
+
mkdirSync(join(root, "public", "demo", "src", "gnome"), { recursive: true });
|
|
2699
|
+
if (baseline) {
|
|
2700
|
+
mkdirSync(join(root, "docs"), { recursive: true });
|
|
2701
|
+
writeFileSync(
|
|
2702
|
+
join(root, "docs", "variant-attr-baselines.json"),
|
|
2703
|
+
`${JSON.stringify({ sites: baseline })}\n`,
|
|
2704
|
+
);
|
|
2705
|
+
}
|
|
2706
|
+
return root;
|
|
2707
|
+
}
|
|
2708
|
+
|
|
2709
|
+
function run(root: string, source: string, rel = "public/demo/src/Frame.tsx") {
|
|
2710
|
+
writeFileSync(join(root, rel), source);
|
|
2711
|
+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
2712
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
2713
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
2714
|
+
const code = runConventionChecks({ roots: { root } });
|
|
2715
|
+
const messages = error.mock.calls.map((call) => String(call[0])).join("\n");
|
|
2716
|
+
error.mockRestore();
|
|
2717
|
+
log.mockRestore();
|
|
2718
|
+
warn.mockRestore();
|
|
2719
|
+
return { code, messages };
|
|
2720
|
+
}
|
|
2721
|
+
|
|
2722
|
+
const imports = 'import { View, styled } from "tamagui";\n';
|
|
2723
|
+
|
|
2724
|
+
it.each(["role", "tabIndex", "accessibilityRole", "accessibilityLabel"])(
|
|
2725
|
+
"fails `%s` in a bag with no context, in a file holding no variants at all",
|
|
2726
|
+
(key) => {
|
|
2727
|
+
const { code, messages } = run(
|
|
2728
|
+
tree(),
|
|
2729
|
+
`${imports}export const Frame = styled(View, {\n ${key}: "x",\n});\n`,
|
|
2730
|
+
);
|
|
2731
|
+
expect(code).toBe(1);
|
|
2732
|
+
expect(messages).toContain(
|
|
2733
|
+
`\`${key}\` in a styled() options object with no \`context\` is dropped from every usage the compiler can flatten`,
|
|
2734
|
+
);
|
|
2735
|
+
expect(messages).toContain("write it at the call site (LC-303)");
|
|
2736
|
+
},
|
|
2737
|
+
);
|
|
2738
|
+
|
|
2739
|
+
it("passes the same bag once it declares a context, which blocks flattening", () => {
|
|
2740
|
+
const { code, messages } = run(
|
|
2741
|
+
tree(),
|
|
2742
|
+
`${imports}export const Frame = styled(View, {\n role: "note",\n context: FrameContext,\n});\n`,
|
|
2743
|
+
);
|
|
2744
|
+
expect(messages).not.toContain("ATTRIBUTE-AT-THE-CALL-SITE");
|
|
2745
|
+
expect(code).toBe(0);
|
|
2746
|
+
});
|
|
2747
|
+
|
|
2748
|
+
it("passes the keys an options object owns legitimately", () => {
|
|
2749
|
+
const { code, messages } = run(
|
|
2750
|
+
tree(),
|
|
2751
|
+
`${imports}export const Frame = styled(View, {\n className: "is_Frame",\n id: "frame",\n testID: "frame",\n htmlFor: "field",\n});\n`,
|
|
2752
|
+
);
|
|
2753
|
+
expect(messages).not.toContain("ATTRIBUTE-AT-THE-CALL-SITE");
|
|
2754
|
+
expect(code).toBe(0);
|
|
2755
|
+
});
|
|
2756
|
+
|
|
2757
|
+
it("passes a gnome path, where the attribute reaches no DOM and no native view", () => {
|
|
2758
|
+
const { code, messages } = run(
|
|
2759
|
+
tree(),
|
|
2760
|
+
`${imports}export const Anchor = styled(View, {\n render: "a",\n role: "link",\n});\n`,
|
|
2761
|
+
"public/demo/src/gnome/Anchor.tsx",
|
|
2762
|
+
);
|
|
2763
|
+
expect(messages).not.toContain("ATTRIBUTE-AT-THE-CALL-SITE");
|
|
2764
|
+
expect(code).toBe(0);
|
|
2765
|
+
});
|
|
2766
|
+
|
|
2767
|
+
it("holds a baselined bag site and fails the second one in the file", () => {
|
|
2768
|
+
const root = tree({ "public/demo/src/Frame.tsx": 1 });
|
|
2769
|
+
const one = run(root, `${imports}export const A = styled(View, {\n role: "note",\n});\n`);
|
|
2770
|
+
expect(one.code).toBe(0);
|
|
2771
|
+
const two = run(
|
|
2772
|
+
root,
|
|
2773
|
+
`${imports}export const A = styled(View, {\n role: "note",\n});\nexport const B = styled(View, {\n tabIndex: -1,\n});\n`,
|
|
2774
|
+
);
|
|
2775
|
+
expect(two.code).toBe(1);
|
|
2776
|
+
expect(two.messages).toContain("public/demo/src/Frame.tsx:6");
|
|
2777
|
+
});
|
|
2778
|
+
});
|