@multiplatform.one/config 7.55.0 → 7.57.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/lint.mjs +71 -0
- package/package.json +2 -2
- package/src/lint.spec.ts +63 -0
package/lint.mjs
CHANGED
|
@@ -2331,6 +2331,72 @@ function checkOverlayOwnership() {
|
|
|
2331
2331
|
return { shadows, frames };
|
|
2332
2332
|
}
|
|
2333
2333
|
|
|
2334
|
+
const TAB_BAR_OWNER = "public/components/src/appShell/";
|
|
2335
|
+
const TAB_BAR_DEFINITION_RE =
|
|
2336
|
+
/\b(?:function|class)\s+([A-Z][A-Za-z0-9_]*Tab[bB]ar(?:Button|Item)?|Tab[bB]ar(?:Button|Item)?)\b|\b(?:const|let|var)\s+([A-Z][A-Za-z0-9_]*Tab[bB]ar(?:Button|Item)?|Tab[bB]ar(?:Button|Item)?)\s*(?::[^=\n]*)?=/g;
|
|
2337
|
+
const TAB_BAR_OPTION_RE =
|
|
2338
|
+
/\btabBar(?:Style|ActiveTintColor|InactiveTintColor|ActiveBackgroundColor|InactiveBackgroundColor|LabelStyle|IconStyle|ItemStyle|Background|LabelPosition|ShowLabel|Button|Icon|Label)\b/g;
|
|
2339
|
+
const NAMED_IMPORT_RE = /\bimport\s+(type\s+)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/g;
|
|
2340
|
+
const BOTTOM_TABS_IMPORT_RE = /\bfrom\s*["'](@react-navigation\/bottom-tabs)["']/g;
|
|
2341
|
+
|
|
2342
|
+
/**
|
|
2343
|
+
* LC-150 TAB-BAR-ANATOMY: every MPO app's bottom tab bar is the MPO
|
|
2344
|
+
* `TabBar`, and an app hands it items, never a look. Fails, outside the
|
|
2345
|
+
* component's own folder: a component named `…TabBar`/`…Tabbar` (an app-local
|
|
2346
|
+
* bar, as Pelt's and the One app's old `@package/ui` Tabbar were), a value
|
|
2347
|
+
* import of a `TabBar`/`Tabbar` from anywhere but `@multiplatform.one/components`,
|
|
2348
|
+
* `@react-navigation/bottom-tabs`, and React Navigation's `tabBar*` styling
|
|
2349
|
+
* options (`tabBarStyle`, `tabBarActiveTintColor`, …), which paint a second
|
|
2350
|
+
* bar's look. Freeform boards and stories are exempt.
|
|
2351
|
+
*/
|
|
2352
|
+
function checkOneTabBar() {
|
|
2353
|
+
/** @type {string[]} */
|
|
2354
|
+
const violations = [];
|
|
2355
|
+
walkOwnedSource((filePath) => {
|
|
2356
|
+
if (!/\.(?:tsx|ts|jsx|js|mjs)$/.test(filePath) || /\.(?:spec|test|stories)\./.test(filePath))
|
|
2357
|
+
return;
|
|
2358
|
+
const rel = relative(ROOT, filePath).replaceAll("\\", "/");
|
|
2359
|
+
if (rel.startsWith(TAB_BAR_OWNER) || rel.startsWith("apps/storybook-expo/boards/freeform/"))
|
|
2360
|
+
return;
|
|
2361
|
+
const src = readFileSync(filePath, "utf8");
|
|
2362
|
+
if (!/tab-?bar|bottom-tabs/i.test(src)) return;
|
|
2363
|
+
const mask = codeOffsets(src);
|
|
2364
|
+
const live = nonCommentOffsets(src);
|
|
2365
|
+
const at = (m) => `${rel}:${lineAt(src, m.index ?? 0)}`;
|
|
2366
|
+
for (const m of src.matchAll(TAB_BAR_DEFINITION_RE)) {
|
|
2367
|
+
if (mask[m.index ?? 0] !== 1) continue;
|
|
2368
|
+
violations.push(
|
|
2369
|
+
`${at(m)} — ${m[1] ?? m[2]} defines an app-local tab bar; render TabBar from @multiplatform.one/components`,
|
|
2370
|
+
);
|
|
2371
|
+
}
|
|
2372
|
+
for (const m of src.matchAll(TAB_BAR_OPTION_RE)) {
|
|
2373
|
+
if (mask[m.index ?? 0] !== 1) continue;
|
|
2374
|
+
violations.push(
|
|
2375
|
+
`${at(m)} — ${m[0]} styles a navigator's own tab bar; render TabBar from @multiplatform.one/components`,
|
|
2376
|
+
);
|
|
2377
|
+
}
|
|
2378
|
+
for (const m of src.matchAll(NAMED_IMPORT_RE)) {
|
|
2379
|
+
if (live[m.index ?? 0] !== 1 || m[1] || m[3] === "@multiplatform.one/components") continue;
|
|
2380
|
+
for (const part of m[2].split(",")) {
|
|
2381
|
+
const name = part.trim().replace(/^type\s+/, "");
|
|
2382
|
+
if (part.trim().startsWith("type ")) continue;
|
|
2383
|
+
const imported = name.split(/\s+as\s+/)[0];
|
|
2384
|
+
if (!/^Tab[bB]ar(?:Button)?$/.test(imported)) continue;
|
|
2385
|
+
violations.push(
|
|
2386
|
+
`${at(m)} — ${imported} imported from ${m[3]}; render TabBar from @multiplatform.one/components`,
|
|
2387
|
+
);
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
for (const m of src.matchAll(BOTTOM_TABS_IMPORT_RE)) {
|
|
2391
|
+
if (live[m.index ?? 0] !== 1) continue;
|
|
2392
|
+
violations.push(
|
|
2393
|
+
`${at(m)} — ${m[1]} draws its own tab bar; render TabBar from @multiplatform.one/components`,
|
|
2394
|
+
);
|
|
2395
|
+
}
|
|
2396
|
+
});
|
|
2397
|
+
return violations;
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2334
2400
|
/**
|
|
2335
2401
|
* Run structural convention checks over a consumer tree.
|
|
2336
2402
|
*
|
|
@@ -2593,6 +2659,7 @@ export function runConventionChecks(options = {}) {
|
|
|
2593
2659
|
const hugContent = checkHugContent();
|
|
2594
2660
|
const responsiveParity = checkResponsiveParity();
|
|
2595
2661
|
const nativePressOwner = checkNativePressOwner();
|
|
2662
|
+
const oneTabBar = checkOneTabBar();
|
|
2596
2663
|
let failed = false;
|
|
2597
2664
|
|
|
2598
2665
|
for (const [rule, list] of /** @type {const} */ ([
|
|
@@ -2612,6 +2679,10 @@ export function runConventionChecks(options = {}) {
|
|
|
2612
2679
|
'Convention (FZ-7792 NATIVE-PRESS-OWNER, check 17): one view owns a press. On native, a view with pressStyle or focusVisibleStyle and no handler claims the touch, and React Native gives it to the deepest claimant, so a pressable\'s onPress never runs when the tap lands on that child. Put `group="<name>"` on the pressable and move the child\'s press look to `"$group-<name>-press"`.',
|
|
2613
2680
|
nativePressOwner,
|
|
2614
2681
|
],
|
|
2682
|
+
[
|
|
2683
|
+
"Convention (LC-150 TAB-BAR-ANATOMY): one bottom tab bar for every MPO app. A phone app renders TabBar from @multiplatform.one/components with items (an icon component and a label) and nothing else; the bar owns its metrics and the theme its colours. An app-local tab bar, a navigator's own tab bar, or tabBar* styling options fork the look.",
|
|
2684
|
+
oneTabBar,
|
|
2685
|
+
],
|
|
2615
2686
|
])) {
|
|
2616
2687
|
if (!list.length) continue;
|
|
2617
2688
|
failed = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/config",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.57.0",
|
|
4
4
|
"description": "Shared build and test configuration presets for multiplatform.one",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"access": "public"
|
|
107
107
|
},
|
|
108
108
|
"dependencies": {
|
|
109
|
-
"@multiplatform.one/utils": "^7.
|
|
109
|
+
"@multiplatform.one/utils": "^7.57.0",
|
|
110
110
|
"@tamagui/vite-plugin": "2.7.6",
|
|
111
111
|
"@vitejs/plugin-react": "^6.1.2",
|
|
112
112
|
"dotenv": "^17.4.2",
|
package/src/lint.spec.ts
CHANGED
|
@@ -2006,3 +2006,66 @@ describe("freeform helper layout exploration", () => {
|
|
|
2006
2006
|
}
|
|
2007
2007
|
});
|
|
2008
2008
|
});
|
|
2009
|
+
|
|
2010
|
+
describe("one tab bar (LC-150 TAB-BAR-ANATOMY, FZ-7995)", () => {
|
|
2011
|
+
function run(files: Record<string, string>) {
|
|
2012
|
+
const root = makeTree();
|
|
2013
|
+
for (const [file, source] of Object.entries(files)) {
|
|
2014
|
+
const full = join(root, file);
|
|
2015
|
+
mkdirSync(join(full, ".."), { recursive: true });
|
|
2016
|
+
writeFileSync(full, source);
|
|
2017
|
+
}
|
|
2018
|
+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
2019
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
2020
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
2021
|
+
const code = runConventionChecks({ roots: { root } });
|
|
2022
|
+
const messages = error.mock.calls.map((call) => String(call[0])).join("\n");
|
|
2023
|
+
error.mockRestore();
|
|
2024
|
+
log.mockRestore();
|
|
2025
|
+
warn.mockRestore();
|
|
2026
|
+
return { code, messages };
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
it("fails an app-local tab bar and the screen that imports it (Pelt's scaffold-era Tabbar)", () => {
|
|
2030
|
+
const { code, messages } = run({
|
|
2031
|
+
"packages/ui/src/Tabbar.tsx":
|
|
2032
|
+
"export function TabbarButton() { return null; }\nexport const Tabbar = View.styleable(() => null);\n",
|
|
2033
|
+
"features/pelt/ui/AppShell.tsx":
|
|
2034
|
+
'import { Tabbar } from "@acme/ui";\nexport const S = () => <Tabbar items={[]} />;\n',
|
|
2035
|
+
});
|
|
2036
|
+
expect(code).toBe(1);
|
|
2037
|
+
expect(messages).toContain("LC-150");
|
|
2038
|
+
expect(messages).toContain(
|
|
2039
|
+
"packages/ui/src/Tabbar.tsx:1 — TabbarButton defines an app-local tab bar",
|
|
2040
|
+
);
|
|
2041
|
+
expect(messages).toContain(
|
|
2042
|
+
"packages/ui/src/Tabbar.tsx:2 — Tabbar defines an app-local tab bar",
|
|
2043
|
+
);
|
|
2044
|
+
expect(messages).toContain("features/pelt/ui/AppShell.tsx:1 — Tabbar imported from @acme/ui");
|
|
2045
|
+
});
|
|
2046
|
+
|
|
2047
|
+
it("fails a navigator's own tab bar and its tabBar* styling", () => {
|
|
2048
|
+
const { code, messages } = run({
|
|
2049
|
+
"apps/demo/app/(tabs)/_layout.tsx":
|
|
2050
|
+
'import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";\nexport const o = { tabBarActiveTintColor: "red", tabBarStyle: { height: 60 } };\n',
|
|
2051
|
+
});
|
|
2052
|
+
expect(code).toBe(1);
|
|
2053
|
+
expect(messages).toContain("@react-navigation/bottom-tabs draws its own tab bar");
|
|
2054
|
+
expect(messages).toContain("tabBarActiveTintColor styles a navigator's own tab bar");
|
|
2055
|
+
expect(messages).toContain("tabBarStyle styles a navigator's own tab bar");
|
|
2056
|
+
});
|
|
2057
|
+
|
|
2058
|
+
it("passes the MPO TabBar with items only, its own folder, demos, types and comments", () => {
|
|
2059
|
+
const { code, messages } = run({
|
|
2060
|
+
"packages/layouts/Layout.tsx":
|
|
2061
|
+
'import { TabBar, type TabBarItem } from "@multiplatform.one/components";\nexport const L = () => <TabBar items={[]} />;\n',
|
|
2062
|
+
"public/components/src/appShell/TabBar.tsx":
|
|
2063
|
+
"function TabBarButton() { return null; }\nexport function TabBar() { return <TabBarButton />; }\n",
|
|
2064
|
+
"features/playground/Demo.tsx": "function TabBarDemo() { return null; }\n",
|
|
2065
|
+
"features/demo/Notes.tsx":
|
|
2066
|
+
"// the old Tabbar set tabBarStyle by hand\nimport type { TabBarProps } from './x';\nexport const n = 1;\n",
|
|
2067
|
+
});
|
|
2068
|
+
expect(messages).not.toContain("LC-150");
|
|
2069
|
+
expect(code).toBe(0);
|
|
2070
|
+
});
|
|
2071
|
+
});
|