@multiplatform.one/config 7.56.0 → 7.58.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/README.md +20 -2
- package/design-lint.mjs +363 -10
- package/lint.mjs +71 -0
- package/package.json +2 -2
- package/src/lint.spec.ts +63 -0
package/README.md
CHANGED
|
@@ -153,8 +153,18 @@ An icon-only button laid in a row beside a field (`Input`, `Select`, an
|
|
|
153
153
|
field's own action, such as reveal, clear, copy or an eyedropper, is
|
|
154
154
|
`Input.Action` inside the field's trailing slot.
|
|
155
155
|
|
|
156
|
+
An app-local component named for an MPO role (`TabBar`, `Header`, `Nav`,
|
|
157
|
+
`Layout`, `Shell`, `Card`, `Tile`, `Panel`, `Row`, `Sheet`, `Drawer`, `Menu`,
|
|
158
|
+
`Field`, `EmptyState`, `Skeleton`, `Banner`, `Pager`, `Toolbar`, `Badge`,
|
|
159
|
+
`Chip`, `Avatar` and the rest of `mpoRoles`) that paints its own surface on a
|
|
160
|
+
raw primitive or a local `styled()` frame is reported as `mpo-role` (LC-175
|
|
161
|
+
MPO-ONLY-REUSE), with the MPO component to use. So is a card painted in place:
|
|
162
|
+
a fill plus a radius, border or shadow around inset content. Composing the MPO
|
|
163
|
+
role passes. A stopgap declares `// mpo-role-escape: <reason>` above it.
|
|
164
|
+
|
|
156
165
|
Every violation is tagged with its rule: `field-action`, `field-focus`, `hex`,
|
|
157
|
-
`geometry`, `inline-spacing`, `raw-control`, `styled-mpo` or
|
|
166
|
+
`geometry`, `inline-spacing`, `mpo-role`, `raw-control`, `styled-mpo` or
|
|
167
|
+
`token-file`.
|
|
158
168
|
|
|
159
169
|
#### Ratchet
|
|
160
170
|
|
|
@@ -170,7 +180,15 @@ a drop in one rule never pays for a rise in another. When counts only fall, the
|
|
|
170
180
|
run rewrites the baseline down and exits 0; commit it. `--frozen` fails that
|
|
171
181
|
case instead, so CI catches a lowered count nobody committed. `--list` prints
|
|
172
182
|
the violations on a passing run. `--baseline` may repeat; MPO's `pnpm
|
|
173
|
-
lint:design` ratchets `apps/one
|
|
183
|
+
lint:design` ratchets `apps/one`, `apps/storybook-expo`, `features`,
|
|
184
|
+
`packages`, `public/backoffice` and `public/frappe-ui` this way.
|
|
185
|
+
|
|
186
|
+
`mpo-role` is also recorded by offender (file and component), so a new fork
|
|
187
|
+
fails even when another was fixed in the same change, and line moves don't
|
|
188
|
+
count. `--only <rule>` (repeatable) cuts a baseline that ratchets just those
|
|
189
|
+
rules. `--init` on an existing baseline adopts the rules it doesn't record yet,
|
|
190
|
+
such as `mpo-role` in a baseline cut before it shipped, and leaves the recorded
|
|
191
|
+
ceilings alone.
|
|
174
192
|
|
|
175
193
|
The implementation is also exported from `@multiplatform.one/config/design-lint`
|
|
176
194
|
as `inspectDesign(source, filename)`, `designFiles(path)` and `runDesignLint(paths)`.
|
package/design-lint.mjs
CHANGED
|
@@ -70,17 +70,93 @@ const tokenFactories = new Set([
|
|
|
70
70
|
"createThemes",
|
|
71
71
|
"createFont",
|
|
72
72
|
]);
|
|
73
|
+
// LC-175 MPO-ONLY-REUSE: a component or layout an app reuses comes from MPO.
|
|
74
|
+
// An app-local component named for an MPO role that paints its own surface
|
|
75
|
+
// out of raw primitives is a fork of that role. First match wins.
|
|
76
|
+
export const mpoRoles = [
|
|
77
|
+
[
|
|
78
|
+
"form field",
|
|
79
|
+
/(?:Field|FormRow|FormItem|FormGroup|FieldRow)$/,
|
|
80
|
+
"Field / FieldLayout / FieldGroup",
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
"tab bar",
|
|
84
|
+
/(?:Tab[Bb]ar|TabsBar|TabStrip|Bottom[Bb]ar|BottomNav|BottomTabs|BottomNavigation)$/,
|
|
85
|
+
"TabBar / Tabs / Dock",
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
"toolbar",
|
|
89
|
+
/(?:Tool[Bb]ar|Action[Bb]ar|ActionRow|Button[Bb]ar|ButtonRow)$/,
|
|
90
|
+
"Toolbar / ActionBar / ScreenToolbar",
|
|
91
|
+
],
|
|
92
|
+
["sidebar", /(?:Side[Bb]ar|SideNav|NavRail|Rail)$/, "Sidebar / PaneScaffold / ListDetailLayout"],
|
|
93
|
+
[
|
|
94
|
+
"nav bar / header",
|
|
95
|
+
/(?:Header|Nav[Bb]ar|Nav|Navigation|NavigationBar|Top[Bb]ar|App[Bb]ar|Title[Bb]ar|Header[Bb]ar|Status[Bb]ar|Masthead)$/,
|
|
96
|
+
"PageHeader / ScreenToolbar / SystemBar",
|
|
97
|
+
],
|
|
98
|
+
[
|
|
99
|
+
"page shell",
|
|
100
|
+
/(?:Shell|Scaffold|Layout|PageFrame|ScreenFrame|PageContainer|ScreenContainer|PageWrapper|ScreenWrapper)$/,
|
|
101
|
+
"Screen / ListPageLayout / DetailPageLayout / PaneScaffold",
|
|
102
|
+
],
|
|
103
|
+
["sheet", /(?:Sheet|Drawer|Modal|Dialog|Lightbox)$/, "Sheet / SheetModal / Dialog"],
|
|
104
|
+
["menu", /(?:Menu|Dropdown|Popover)$/, "DropdownMenu / ContextMenu / Popover"],
|
|
105
|
+
[
|
|
106
|
+
"empty / loading / error state",
|
|
107
|
+
/(?:Empty|EmptyState|Loading|LoadingState|LoadingScreen|LoadingIndicator|Loader|Spinner|Skeleton|ErrorState|ErrorScreen|ErrorMessage|Error[Bb]anner|ErrorFallback|Fallback|Placeholder|Banner|Notice|Callout)$/,
|
|
108
|
+
"EmptyState / AsyncBoundary / Skeleton / Spinner / Alert",
|
|
109
|
+
],
|
|
110
|
+
[
|
|
111
|
+
"pager",
|
|
112
|
+
/(?:Pager|Pagination|Paginator|PageDots|PageIndicator|Dots)$/,
|
|
113
|
+
"Pagination / DotIndicator / Carousel",
|
|
114
|
+
],
|
|
115
|
+
["avatar", /Avatar$/, "Avatar"],
|
|
116
|
+
["badge / pill", /(?:Badge|Pill|Chip|Tag)$/, "Badge / Chip"],
|
|
117
|
+
["card", /(?:Card|Tile|Panel)$/, "Card / CardHeader / CardFooter / ListCard"],
|
|
118
|
+
["list row", /(?:Row|ListItem|ListRow|Cell)$/, "List / ListRow / DescriptionList"],
|
|
119
|
+
];
|
|
120
|
+
// A role's parts (DrawerContentFrame, CardRoot) report once, under the stem.
|
|
121
|
+
const roleParts =
|
|
122
|
+
/(?:Frame|Root|Content|Overlay|Portal|Container|Inner|Outer|Base|Impl|View|Wrapper|Item|Body|Swipeable)$/;
|
|
123
|
+
export function mpoRoleOf(componentName) {
|
|
124
|
+
let stem = componentName;
|
|
125
|
+
let found;
|
|
126
|
+
for (let current = componentName; current; ) {
|
|
127
|
+
const role = mpoRoles.find(([, pattern]) => pattern.test(current));
|
|
128
|
+
if (role) {
|
|
129
|
+
stem = current;
|
|
130
|
+
found = role;
|
|
131
|
+
}
|
|
132
|
+
const next = current.replace(roleParts, "");
|
|
133
|
+
if (next === current || !next) break;
|
|
134
|
+
current = next;
|
|
135
|
+
}
|
|
136
|
+
return found && { role: found, stem };
|
|
137
|
+
}
|
|
138
|
+
// A spread of a knob bundle that carries surface paint (knobProps.surface).
|
|
139
|
+
const surfaceSpread = /\b(?:surface|elevation|containerRadius|radius|border|card|panel)\w*$/i;
|
|
140
|
+
const rawPrimitive =
|
|
141
|
+
/^(?:View|XStack|YStack|Stack|ZStack|HStack|VStack|SafeAreaView|ScrollView|Pressable|TouchableOpacity|TouchableHighlight|Text|SizableText|Paragraph|Animated\.View|div|section|nav|header|footer|aside|span|li|ul)$/;
|
|
142
|
+
const surfacePaint =
|
|
143
|
+
/^(?:bg|backgroundColor|background|borderRadius|br|border(?:Top|Bottom|Left|Right|Start|End)?(?:Width|Color)?|border(?:Top|Bottom)(?:Left|Right|Start|End)Radius|elevation|elevate|bordered|shadow(?:Color|Opacity|Radius|Offset)?|boxShadow)$/;
|
|
144
|
+
|
|
73
145
|
export const designRules = [
|
|
74
146
|
"field-action",
|
|
75
147
|
"field-focus",
|
|
76
148
|
"hex",
|
|
77
149
|
"geometry",
|
|
78
150
|
"inline-spacing",
|
|
151
|
+
"mpo-role",
|
|
79
152
|
"raw-control",
|
|
80
153
|
"raw-icon",
|
|
81
154
|
"styled-mpo",
|
|
82
155
|
"token-file",
|
|
83
156
|
];
|
|
157
|
+
// Rules whose baseline records each offender, so a new offender fails even
|
|
158
|
+
// when another one was fixed in the same change.
|
|
159
|
+
export const identityRules = new Set(["mpo-role"]);
|
|
84
160
|
export function isFreeformBoard(filename, projectRoot = process.cwd()) {
|
|
85
161
|
const root = path.resolve(projectRoot);
|
|
86
162
|
const absolute = path.resolve(root, filename);
|
|
@@ -477,7 +553,213 @@ export function inspectDesign(source, filename, projectRoot = process.cwd()) {
|
|
|
477
553
|
ts.forEachChild(node, visit);
|
|
478
554
|
}
|
|
479
555
|
visit(file);
|
|
556
|
+
checkMpoRoles();
|
|
480
557
|
return errors;
|
|
558
|
+
|
|
559
|
+
function paintsSurface(node, seen = new Set()) {
|
|
560
|
+
const value = resolve(node);
|
|
561
|
+
if (seen.has(value)) return false;
|
|
562
|
+
seen.add(value);
|
|
563
|
+
if (ts.isArrayLiteralExpression(value))
|
|
564
|
+
return value.elements.some((item) => paintsSurface(item, seen));
|
|
565
|
+
if (ts.isConditionalExpression(value))
|
|
566
|
+
return paintsSurface(value.whenTrue, seen) || paintsSurface(value.whenFalse, seen);
|
|
567
|
+
if (ts.isBinaryExpression(value))
|
|
568
|
+
return paintsSurface(value.left, seen) || paintsSurface(value.right, seen);
|
|
569
|
+
if (ts.isPropertyAccessExpression(value) || ts.isIdentifier(value))
|
|
570
|
+
return surfaceSpread.test(value.getText(file));
|
|
571
|
+
if (!ts.isObjectLiteralExpression(value)) return false;
|
|
572
|
+
return value.properties.some((prop) => {
|
|
573
|
+
if (ts.isSpreadAssignment(prop)) return paintsSurface(prop.expression, seen);
|
|
574
|
+
if (!ts.isPropertyAssignment(prop)) return !!prop.name && surfacePaint.test(name(prop.name));
|
|
575
|
+
const key = name(prop.name);
|
|
576
|
+
if (surfacePaint.test(key)) return !inert(prop.initializer);
|
|
577
|
+
return (/style$/i.test(key) || key.startsWith("$")) && paintsSurface(prop.initializer, seen);
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
function localFrame(tag) {
|
|
581
|
+
if (!ts.isIdentifier(tag)) return undefined;
|
|
582
|
+
const declaration = checker.getSymbolAtLocation(tag)?.valueDeclaration;
|
|
583
|
+
if (!declaration || !ts.isVariableDeclaration(declaration) || !declaration.initializer)
|
|
584
|
+
return undefined;
|
|
585
|
+
return styledPrimitive(unwrapComponent(declaration.initializer));
|
|
586
|
+
}
|
|
587
|
+
function styledPrimitive(value) {
|
|
588
|
+
if (
|
|
589
|
+
!value ||
|
|
590
|
+
!ts.isCallExpression(value) ||
|
|
591
|
+
referenceName(value.expression) !== "styled" ||
|
|
592
|
+
!value.arguments[0]
|
|
593
|
+
)
|
|
594
|
+
return undefined;
|
|
595
|
+
const base = value.arguments[0];
|
|
596
|
+
const primitive = ts.isStringLiteral(base)
|
|
597
|
+
? rawPrimitive.test(base.text)
|
|
598
|
+
: rawPrimitive.test(referenceName(base)) || !!localFrame(base);
|
|
599
|
+
if (!primitive) return undefined;
|
|
600
|
+
return {
|
|
601
|
+
paints:
|
|
602
|
+
value.arguments.slice(1).some((arg) => paintsSurface(arg)) || !!localFrame(base)?.paints,
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
function primitiveTag(tag) {
|
|
606
|
+
if (ts.isIdentifier(tag) && localFrame(tag)) return true;
|
|
607
|
+
const text = ts.isIdentifier(tag) ? referenceName(tag) : tag.getText(file);
|
|
608
|
+
return rawPrimitive.test(text);
|
|
609
|
+
}
|
|
610
|
+
function paintedElement(element) {
|
|
611
|
+
if (!primitiveTag(element.tagName)) return false;
|
|
612
|
+
if (localFrame(element.tagName)?.paints) return true;
|
|
613
|
+
return element.attributes.properties.some((attr) => {
|
|
614
|
+
if (ts.isJsxSpreadAttribute(attr)) return paintsSurface(attr.expression);
|
|
615
|
+
const key = name(attr.name);
|
|
616
|
+
const value =
|
|
617
|
+
attr.initializer && ts.isJsxExpression(attr.initializer)
|
|
618
|
+
? attr.initializer.expression
|
|
619
|
+
: attr.initializer;
|
|
620
|
+
if (surfacePaint.test(key)) return !value || !inert(value);
|
|
621
|
+
return !!value && (/style$/i.test(key) || key.startsWith("$")) && paintsSurface(value);
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
function paintsOwnSurface(body) {
|
|
625
|
+
let painted = false;
|
|
626
|
+
(function walk(node) {
|
|
627
|
+
if (painted) return;
|
|
628
|
+
if (
|
|
629
|
+
(ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) &&
|
|
630
|
+
paintedElement(node)
|
|
631
|
+
)
|
|
632
|
+
painted = true;
|
|
633
|
+
else ts.forEachChild(node, walk);
|
|
634
|
+
})(body);
|
|
635
|
+
return painted;
|
|
636
|
+
}
|
|
637
|
+
function escaped(statement) {
|
|
638
|
+
const ranges = ts.getLeadingCommentRanges(source, statement.getFullStart()) ?? [];
|
|
639
|
+
return ranges.some((range) => /mpo-role-escape: \S/.test(source.slice(range.pos, range.end)));
|
|
640
|
+
}
|
|
641
|
+
function unwrapComponent(node) {
|
|
642
|
+
let current = node;
|
|
643
|
+
for (;;) {
|
|
644
|
+
if (!current) return current;
|
|
645
|
+
if (ts.isParenthesizedExpression(current) || ts.isAsExpression(current)) {
|
|
646
|
+
current = current.expression;
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
if (!ts.isCallExpression(current) || !current.arguments[0]) return current;
|
|
650
|
+
const callee = current.expression.getText(file);
|
|
651
|
+
if (/^(?:(?:React\.)?(?:memo|forwardRef)|observer|withStaticProperties)$/.test(callee))
|
|
652
|
+
current = current.arguments[0];
|
|
653
|
+
else if (/\.styleable$/.test(callee)) current = current.arguments[0];
|
|
654
|
+
else return current;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function paintsComponent(initializer) {
|
|
658
|
+
const value = unwrapComponent(initializer);
|
|
659
|
+
if (!value) return false;
|
|
660
|
+
if (ts.isArrowFunction(value) || ts.isFunctionExpression(value))
|
|
661
|
+
return paintsOwnSurface(value.body);
|
|
662
|
+
if (styledPrimitive(value)?.paints) return true;
|
|
663
|
+
if (ts.isCallExpression(value) && /\.styleable$/.test(value.expression.getText(file)))
|
|
664
|
+
return false;
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
function checkMpoRoles() {
|
|
668
|
+
const fallback = path
|
|
669
|
+
.basename(filename)
|
|
670
|
+
.replace(/\.[^.]+$/, "")
|
|
671
|
+
.replace(/(?:^|[-_.])([a-z])/g, (_, c) => c.toUpperCase());
|
|
672
|
+
const seen = new Set();
|
|
673
|
+
const consider = (node, component, paints) => {
|
|
674
|
+
if (!/^[A-Z]/.test(component)) return;
|
|
675
|
+
const found = mpoRoleOf(component);
|
|
676
|
+
if (!found || seen.has(found.stem) || !paints()) return;
|
|
677
|
+
seen.add(found.stem);
|
|
678
|
+
const [role, , replacement] = found.role;
|
|
679
|
+
report(
|
|
680
|
+
node,
|
|
681
|
+
"mpo-role",
|
|
682
|
+
`${found.stem} reimplements the MPO ${role} role; use ${replacement} (LC-175 MPO-ONLY-REUSE).`,
|
|
683
|
+
);
|
|
684
|
+
};
|
|
685
|
+
const inline = (node, component) => {
|
|
686
|
+
if (!/^[A-Z]/.test(component) || seen.has(component)) return;
|
|
687
|
+
const surface = inlineSurface(node);
|
|
688
|
+
if (!surface) return;
|
|
689
|
+
seen.add(component);
|
|
690
|
+
report(
|
|
691
|
+
surface,
|
|
692
|
+
"mpo-role",
|
|
693
|
+
`${component} paints an inline card surface on a raw primitive; a fill with a radius, border or shadow around inset content is Card / ListCard / Badge (LC-175 MPO-ONLY-REUSE).`,
|
|
694
|
+
);
|
|
695
|
+
};
|
|
696
|
+
for (const statement of file.statements) {
|
|
697
|
+
if (escaped(statement)) continue;
|
|
698
|
+
if (ts.isFunctionDeclaration(statement) && statement.body) {
|
|
699
|
+
const component = statement.name?.text ?? fallback;
|
|
700
|
+
consider(statement.name ?? statement, component, () => paintsOwnSurface(statement.body));
|
|
701
|
+
inline(statement.body, component);
|
|
702
|
+
} else if (ts.isVariableStatement(statement))
|
|
703
|
+
for (const declaration of statement.declarationList.declarations)
|
|
704
|
+
if (ts.isIdentifier(declaration.name) && declaration.initializer) {
|
|
705
|
+
consider(declaration.name, declaration.name.text, () =>
|
|
706
|
+
paintsComponent(declaration.initializer),
|
|
707
|
+
);
|
|
708
|
+
const value = unwrapComponent(declaration.initializer);
|
|
709
|
+
if (value && (ts.isArrowFunction(value) || ts.isFunctionExpression(value)))
|
|
710
|
+
inline(value.body, declaration.name.text);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
// A card built in place: a raw primitive container that fills a background,
|
|
715
|
+
// rounds, borders or lifts it, and insets its content. The page ground
|
|
716
|
+
// ($background), clear fills, and childless marks or swatches are not cards.
|
|
717
|
+
function inlineSurface(body) {
|
|
718
|
+
let hit;
|
|
719
|
+
(function walk(node) {
|
|
720
|
+
if (hit) return;
|
|
721
|
+
if (
|
|
722
|
+
(ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) &&
|
|
723
|
+
primitiveTag(node.tagName) &&
|
|
724
|
+
!localFrame(node.tagName)
|
|
725
|
+
) {
|
|
726
|
+
const keys = new Map();
|
|
727
|
+
for (const attr of node.attributes.properties)
|
|
728
|
+
if (ts.isJsxAttribute(attr)) {
|
|
729
|
+
const value =
|
|
730
|
+
attr.initializer && ts.isJsxExpression(attr.initializer)
|
|
731
|
+
? attr.initializer.expression
|
|
732
|
+
: attr.initializer;
|
|
733
|
+
keys.set(name(attr.name), value);
|
|
734
|
+
}
|
|
735
|
+
const fill = [...keys].find(
|
|
736
|
+
([key, value]) =>
|
|
737
|
+
/^(?:bg|backgroundColor|background)$/.test(key) &&
|
|
738
|
+
value &&
|
|
739
|
+
!inert(value) &&
|
|
740
|
+
!/^["'`]?\$(?:background|backgroundTransparent)["'`]?$/.test(value.getText(file)),
|
|
741
|
+
);
|
|
742
|
+
const shape = [...keys].some(
|
|
743
|
+
([key, value]) =>
|
|
744
|
+
/^(?:borderRadius|br|border(?:Top|Bottom)(?:Left|Right)Radius|borderWidth|bordered|elevation|elevate|shadow(?:Color|Radius|Opacity))$/.test(
|
|
745
|
+
key,
|
|
746
|
+
) &&
|
|
747
|
+
(!value || !inert(value)),
|
|
748
|
+
);
|
|
749
|
+
const inset = [...keys].some(([key]) =>
|
|
750
|
+
/^(?:padding(?:Horizontal|Vertical|Top|Bottom|Left|Right|Start|End)?|p|px|py|pt|pb|pl|pr)$/.test(
|
|
751
|
+
key,
|
|
752
|
+
),
|
|
753
|
+
);
|
|
754
|
+
if (fill && shape && inset && ts.isJsxOpeningElement(node)) {
|
|
755
|
+
hit = node;
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
ts.forEachChild(node, walk);
|
|
760
|
+
})(body);
|
|
761
|
+
return hit;
|
|
762
|
+
}
|
|
481
763
|
}
|
|
482
764
|
|
|
483
765
|
const ignoredDirectories = new Set([
|
|
@@ -568,12 +850,16 @@ export function scanDesign(paths) {
|
|
|
568
850
|
}
|
|
569
851
|
|
|
570
852
|
function parseArgs(args) {
|
|
571
|
-
const options = { paths: [], baselines: [], frozen: false, init: false, list: false };
|
|
853
|
+
const options = { paths: [], baselines: [], frozen: false, init: false, list: false, only: [] };
|
|
572
854
|
for (let index = 0; index < args.length; index++) {
|
|
573
855
|
const arg = args[index];
|
|
574
856
|
if (arg === "--baseline") {
|
|
575
857
|
if (!args[index + 1]) throw new Error("--baseline needs a file.");
|
|
576
858
|
options.baselines.push(args[++index]);
|
|
859
|
+
} else if (arg === "--only") {
|
|
860
|
+
if (!designRules.includes(args[index + 1]))
|
|
861
|
+
throw new Error(`--only needs one of ${designRules.join(", ")}.`);
|
|
862
|
+
options.only.push(args[++index]);
|
|
577
863
|
} else if (arg === "--frozen") options.frozen = true;
|
|
578
864
|
else if (arg === "--init") options.init = true;
|
|
579
865
|
else if (arg === "--list") options.list = true;
|
|
@@ -600,6 +886,25 @@ function scopeFrom(base) {
|
|
|
600
886
|
return scope;
|
|
601
887
|
}
|
|
602
888
|
|
|
889
|
+
export function offenderKey(error, base) {
|
|
890
|
+
const match = /^(.*?):\d+:\d+: \[[a-z-]+\] (.*)$/.exec(error);
|
|
891
|
+
if (!match) return error;
|
|
892
|
+
return `${path.relative(base, match[1]).replaceAll("\\", "/")}: ${match[2].split(";")[0]}`;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
function offendersOf(scan, base) {
|
|
896
|
+
const offenders = {};
|
|
897
|
+
for (const rule of [...identityRules].sort()) {
|
|
898
|
+
const keys = {};
|
|
899
|
+
for (const error of scan.errors.filter((item) => ruleOf(item) === rule)) {
|
|
900
|
+
const key = offenderKey(error, base);
|
|
901
|
+
keys[key] = (keys[key] ?? 0) + 1;
|
|
902
|
+
}
|
|
903
|
+
offenders[rule] = Object.fromEntries(Object.entries(keys).sort());
|
|
904
|
+
}
|
|
905
|
+
return offenders;
|
|
906
|
+
}
|
|
907
|
+
|
|
603
908
|
function ratchet(file, options) {
|
|
604
909
|
const real = (input) => (existsSync(input) ? realpathSync(input) : path.resolve(input));
|
|
605
910
|
const base = real(path.dirname(path.resolve(file)));
|
|
@@ -611,11 +916,28 @@ function ratchet(file, options) {
|
|
|
611
916
|
const paths = options.paths.length
|
|
612
917
|
? options.paths.map(relative)
|
|
613
918
|
: (previous?.paths ?? scopeFrom(process.cwd()).map(relative));
|
|
614
|
-
|
|
919
|
+
// A baseline cut with --only ratchets just those rules (the desk packages
|
|
920
|
+
// carry LC-175 without taking on the app-only rules).
|
|
921
|
+
const only = previous ? previous.only : options.only.length ? options.only : undefined;
|
|
922
|
+
const full = scanDesign(paths.map((input) => path.resolve(base, input)));
|
|
923
|
+
const scan = only
|
|
924
|
+
? (() => {
|
|
925
|
+
const errors = full.errors.filter((error) => only.includes(ruleOf(error)));
|
|
926
|
+
const counted = countDesign(errors);
|
|
927
|
+
return {
|
|
928
|
+
...full,
|
|
929
|
+
errors,
|
|
930
|
+
total: counted.total,
|
|
931
|
+
rules: Object.fromEntries(only.map((rule) => [rule, counted.rules[rule]])),
|
|
932
|
+
};
|
|
933
|
+
})()
|
|
934
|
+
: full;
|
|
615
935
|
const next = {
|
|
616
936
|
paths,
|
|
937
|
+
...(only ? { only } : {}),
|
|
617
938
|
total: scan.total,
|
|
618
939
|
rules: Object.fromEntries(Object.entries(scan.rules).sort()),
|
|
940
|
+
offenders: offendersOf(scan, base),
|
|
619
941
|
};
|
|
620
942
|
const write = () => writeFileSync(file, `${JSON.stringify(next, null, 2)}\n`);
|
|
621
943
|
if (!previous) {
|
|
@@ -623,19 +945,46 @@ function ratchet(file, options) {
|
|
|
623
945
|
process.stdout.write(`MPO design guard: ${file} created at ${summary(scan)}.\n`);
|
|
624
946
|
return 0;
|
|
625
947
|
}
|
|
948
|
+
// --init on an existing baseline adopts only the rules it does not record
|
|
949
|
+
// yet (a rule added to MPO after the baseline was cut); recorded rules keep
|
|
950
|
+
// their ceilings.
|
|
951
|
+
const adopted = options.init
|
|
952
|
+
? (only ?? designRules).filter((rule) => !(rule in (previous.rules ?? {})))
|
|
953
|
+
: [];
|
|
954
|
+
const ceiling = (rule) =>
|
|
955
|
+
adopted.includes(rule) ? next.rules[rule] : (previous.rules?.[rule] ?? 0);
|
|
956
|
+
const recorded = (rule) =>
|
|
957
|
+
adopted.includes(rule) ? next.offenders[rule] : (previous.offenders?.[rule] ?? {});
|
|
626
958
|
const rules = [...new Set([...Object.keys(previous.rules ?? {}), ...Object.keys(next.rules)])];
|
|
627
|
-
const rose = rules.filter((rule) => (next.rules[rule] ?? 0) > (
|
|
628
|
-
const
|
|
629
|
-
|
|
959
|
+
const rose = rules.filter((rule) => (next.rules[rule] ?? 0) > ceiling(rule));
|
|
960
|
+
const added = [...identityRules].flatMap((rule) =>
|
|
961
|
+
Object.entries(next.offenders[rule] ?? {})
|
|
962
|
+
.filter(([key, count]) => count > (recorded(rule)[key] ?? 0))
|
|
963
|
+
.map(([key]) => `[${rule}] ${key}`),
|
|
964
|
+
);
|
|
965
|
+
if (rose.length || added.length) {
|
|
630
966
|
process.stderr.write(
|
|
631
|
-
`${scan.errors.join("\n")}\nMPO design guard: ${file} regressed
|
|
632
|
-
.
|
|
633
|
-
|
|
967
|
+
`${scan.errors.join("\n")}\nMPO design guard: ${file} regressed${
|
|
968
|
+
rose.length
|
|
969
|
+
? `, ${rose.map((rule) => `${rule} ${ceiling(rule)} -> ${next.rules[rule]}`).join(", ")}`
|
|
970
|
+
: ""
|
|
971
|
+
}${
|
|
972
|
+
added.length
|
|
973
|
+
? `; new offenders:\n ${added.join("\n ")}\nRender the MPO component instead (LC-175). A rename of a listed offender renames its key in ${file}.\n`
|
|
974
|
+
: ". "
|
|
975
|
+
}${summary(scan)}.\n`,
|
|
634
976
|
);
|
|
635
977
|
return 1;
|
|
636
978
|
}
|
|
637
979
|
if (options.list && scan.errors.length) process.stderr.write(`${scan.errors.join("\n")}\n`);
|
|
638
|
-
|
|
980
|
+
const fell = rules.filter((rule) => (next.rules[rule] ?? 0) < ceiling(rule));
|
|
981
|
+
const shrank = [...identityRules].some((rule) =>
|
|
982
|
+
Object.entries(recorded(rule)).some(
|
|
983
|
+
([key, count]) => (next.offenders[rule]?.[key] ?? 0) < count,
|
|
984
|
+
),
|
|
985
|
+
);
|
|
986
|
+
const missing = !previous.offenders || adopted.length;
|
|
987
|
+
if (fell.length || shrank || missing) {
|
|
639
988
|
const change = `${previous.total} -> ${next.total}`;
|
|
640
989
|
if (options.frozen) {
|
|
641
990
|
process.stderr.write(
|
|
@@ -644,7 +993,11 @@ function ratchet(file, options) {
|
|
|
644
993
|
return 1;
|
|
645
994
|
}
|
|
646
995
|
write();
|
|
647
|
-
process.stdout.write(
|
|
996
|
+
process.stdout.write(
|
|
997
|
+
adopted.length
|
|
998
|
+
? `MPO design guard: ${file} adopted ${adopted.join(", ")}. ${summary(scan)}.\n`
|
|
999
|
+
: `MPO design guard: ${file} ratcheted down ${change}. ${summary(scan)}.\n`,
|
|
1000
|
+
);
|
|
648
1001
|
return 0;
|
|
649
1002
|
}
|
|
650
1003
|
process.stdout.write(`MPO design guard: ${file} holds at ${summary(scan)}.\n`);
|
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.58.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.58.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
|
+
});
|