@multiplatform.one/config 9.9.0 → 9.11.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 +24 -20
- package/design-lint.mjs +81 -40
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -210,28 +210,32 @@ Every violation is tagged with its rule: `field-action`, `field-focus`, `hex`,
|
|
|
210
210
|
#### Ratchet
|
|
211
211
|
|
|
212
212
|
```sh
|
|
213
|
-
pnpm exec mpo-design-lint --baseline design-baseline.json --init
|
|
214
|
-
pnpm exec mpo-design-lint --baseline design-baseline.json
|
|
215
|
-
pnpm exec mpo-design-lint --baseline design-baseline.json --frozen
|
|
213
|
+
pnpm exec mpo-design-lint --baseline design-baseline.json --init # once, commit the file
|
|
214
|
+
pnpm exec mpo-design-lint --baseline design-baseline.json # lint step
|
|
215
|
+
pnpm exec mpo-design-lint --baseline design-baseline.json --frozen # CI
|
|
216
|
+
pnpm exec mpo-design-lint --baseline design-baseline.json --tighten # drop cleared offenders
|
|
216
217
|
```
|
|
217
218
|
|
|
218
|
-
The baseline records the scanned paths (relative to the baseline file) and
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
`
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
219
|
+
The baseline records the scanned paths (relative to the baseline file) and every
|
|
220
|
+
offender by rule, file and message, with how often it occurs. It stores no total
|
|
221
|
+
and no per-rule count; the lint derives both from the offenders
|
|
222
|
+
(`countBaseline(baseline)`). A run fails when it finds an offender the baseline
|
|
223
|
+
doesn't list, or more of one than it lists, so fixing one never pays for a new
|
|
224
|
+
one, and line moves don't count. Clearing offenders passes without touching the
|
|
225
|
+
file, so two changes that each clear a different offender never conflict on the
|
|
226
|
+
baseline. `--tighten` is the explicit step that rewrites the baseline down to
|
|
227
|
+
what the scan finds; nothing else writes it except `--init`, and `--frozen`
|
|
228
|
+
refuses both. The file is written in the shape `oxfmt` gives it. A baseline that
|
|
229
|
+
still stores `total` and `rules` ratchets those counts until `--tighten`
|
|
230
|
+
rewrites it. `--list` prints the violations on a passing run. `--baseline` may
|
|
231
|
+
repeat; MPO's `pnpm lint:design` ratchets `apps/one`, `apps/storybook-expo`,
|
|
232
|
+
`features`, `packages`, `public/backoffice`, `public/frappe-ui` and `public`
|
|
233
|
+
(the harvested rules over every MPO package) this way.
|
|
234
|
+
|
|
235
|
+
`--only <rule>` (repeatable) cuts a baseline that ratchets just those rules;
|
|
236
|
+
`--only harvest` takes all the harvested rules. `--init` on an existing baseline
|
|
237
|
+
adopts the rules it doesn't record yet, such as `mpo-role` in a baseline cut
|
|
238
|
+
before it shipped, and leaves the recorded offenders alone.
|
|
235
239
|
|
|
236
240
|
`mpo-design-lint --verify-ci [dir]` is LC-192's fitness check: it fails when
|
|
237
241
|
the repo's `.gitlab-ci.yml` or GitHub workflows never run the lint, run it
|
package/design-lint.mjs
CHANGED
|
@@ -203,9 +203,6 @@ export const designRules = [
|
|
|
203
203
|
"token-file",
|
|
204
204
|
...harvestRules,
|
|
205
205
|
];
|
|
206
|
-
// Rules whose baseline records each offender, so a new offender fails even
|
|
207
|
-
// when another one was fixed in the same change.
|
|
208
|
-
export const identityRules = new Set(["icon-button", "mpo-role", ...harvestRules]);
|
|
209
206
|
// LC-203 USER-WORDS: implementation words a user never reads. A baseline's
|
|
210
207
|
// bannedWords replaces this list for its app; --init seeds it.
|
|
211
208
|
export const houseBannedWords = [
|
|
@@ -325,6 +322,7 @@ const cssWebPaint =
|
|
|
325
322
|
/(?:^|[;{\s"'`])(?:mix-blend-mode|backdrop-filter|-webkit-backdrop-filter|clip-path|text-shadow|-webkit-mask(?:-image)?|mask-image)\s*:/;
|
|
326
323
|
const zoomLock = /user-scalable\s*=\s*(?:no|0)\b|maximum-scale\s*=\s*1(?:\.0)?\b/;
|
|
327
324
|
const linkTag = /^(?:a|Anchor|Link|TextLink|InlineLink|ExternalLink)$|\.(?:Anchor|Link)$/;
|
|
325
|
+
const linkLabel = /^(?:Text|SizableText|Paragraph|Span|span|Label)$|\.Text$/;
|
|
328
326
|
const linkPaint =
|
|
329
327
|
/^(?:color|fontWeight|textDecoration|textDecorationLine|textDecorationColor|textDecorationStyle)$/;
|
|
330
328
|
const imageTag = /^(?:Image|img|ImageBackground|AvatarImage|FastImage|ExpoImage)$|\.Image$/;
|
|
@@ -1457,7 +1455,11 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
|
|
|
1457
1455
|
// LC-181 LINK-CHROME and LC-207 ART-NEVER-TINTED at a JSX use site.
|
|
1458
1456
|
function checkElement(element) {
|
|
1459
1457
|
const tag = tagText(element.tagName);
|
|
1460
|
-
|
|
1458
|
+
const roleLink = attribute(element, "role")?.initializer?.getText(file) === '"link"';
|
|
1459
|
+
if (
|
|
1460
|
+
(linkTag.test(tag) || roleLink) &&
|
|
1461
|
+
!opening(element).getText(file).includes("link-chrome-escape:")
|
|
1462
|
+
) {
|
|
1461
1463
|
const key = paintedBy(element, linkPaint);
|
|
1462
1464
|
if (key)
|
|
1463
1465
|
report(
|
|
@@ -1465,6 +1467,24 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
|
|
|
1465
1467
|
"link-chrome",
|
|
1466
1468
|
`${tag} sets ${key}; a link's ink, weight and underline come from the theme (LC-181).`,
|
|
1467
1469
|
);
|
|
1470
|
+
if (linkTag.test(tag) && ts.isJsxOpeningElement(element)) {
|
|
1471
|
+
const walk = (node) => {
|
|
1472
|
+
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
1473
|
+
const inner = opening(node);
|
|
1474
|
+
const innerTag = tagText(inner.tagName);
|
|
1475
|
+
if (linkTag.test(innerTag)) return;
|
|
1476
|
+
const innerKey = linkLabel.test(innerTag) && paintedBy(inner, linkPaint);
|
|
1477
|
+
if (innerKey)
|
|
1478
|
+
report(
|
|
1479
|
+
inner,
|
|
1480
|
+
"link-chrome",
|
|
1481
|
+
`${innerTag} inside ${tag} sets ${innerKey}; put the label straight in the link and let the theme draw it (LC-181).`,
|
|
1482
|
+
);
|
|
1483
|
+
}
|
|
1484
|
+
ts.forEachChild(node, walk);
|
|
1485
|
+
};
|
|
1486
|
+
for (const child of element.parent.children) walk(child);
|
|
1487
|
+
}
|
|
1468
1488
|
}
|
|
1469
1489
|
if (
|
|
1470
1490
|
imageTag.test(tag) &&
|
|
@@ -2059,6 +2079,7 @@ function parseArgs(args) {
|
|
|
2059
2079
|
init: false,
|
|
2060
2080
|
list: false,
|
|
2061
2081
|
only: [],
|
|
2082
|
+
tighten: false,
|
|
2062
2083
|
verifyCi: false,
|
|
2063
2084
|
};
|
|
2064
2085
|
for (let index = 0; index < args.length; index++) {
|
|
@@ -2078,12 +2099,15 @@ function parseArgs(args) {
|
|
|
2078
2099
|
} else if (arg === "--frozen") options.frozen = true;
|
|
2079
2100
|
else if (arg === "--verify-ci") options.verifyCi = true;
|
|
2080
2101
|
else if (arg === "--init") options.init = true;
|
|
2102
|
+
else if (arg === "--tighten") options.tighten = true;
|
|
2081
2103
|
else if (arg === "--list") options.list = true;
|
|
2082
2104
|
else if (arg.startsWith("--")) throw new Error(`Unknown option ${arg}.`);
|
|
2083
2105
|
else options.paths.push(arg);
|
|
2084
2106
|
}
|
|
2085
2107
|
if (options.paths.length && options.baselines.length > 1)
|
|
2086
2108
|
throw new Error("Pass paths with at most one --baseline.");
|
|
2109
|
+
if (options.frozen && (options.init || options.tighten))
|
|
2110
|
+
throw new Error("--frozen never writes a baseline; drop --init and --tighten.");
|
|
2087
2111
|
return options;
|
|
2088
2112
|
}
|
|
2089
2113
|
|
|
@@ -2113,7 +2137,7 @@ export function offenderKey(error, base) {
|
|
|
2113
2137
|
|
|
2114
2138
|
function offendersOf(scan, base) {
|
|
2115
2139
|
const offenders = {};
|
|
2116
|
-
for (const rule of
|
|
2140
|
+
for (const rule of Object.keys(scan.rules).sort()) {
|
|
2117
2141
|
const keys = {};
|
|
2118
2142
|
for (const error of scan.errors.filter((item) => ruleOf(item) === rule)) {
|
|
2119
2143
|
const key = offenderKey(error, base);
|
|
@@ -2124,6 +2148,18 @@ function offendersOf(scan, base) {
|
|
|
2124
2148
|
return offenders;
|
|
2125
2149
|
}
|
|
2126
2150
|
|
|
2151
|
+
const sum = (counts) => counts.reduce((total, count) => total + count, 0);
|
|
2152
|
+
|
|
2153
|
+
export function countBaseline(baseline) {
|
|
2154
|
+
const rules = Object.fromEntries(
|
|
2155
|
+
Object.entries(baseline.offenders ?? {}).map(([rule, keys]) => [
|
|
2156
|
+
rule,
|
|
2157
|
+
sum(Object.values(keys)),
|
|
2158
|
+
]),
|
|
2159
|
+
);
|
|
2160
|
+
return { total: sum(Object.values(rules)), rules };
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2127
2163
|
// FZ-10697: a regenerated baseline has to be a file oxfmt leaves alone, or
|
|
2128
2164
|
// every lane that lowers the ratchet fails `scripts/format-changed.sh` and has
|
|
2129
2165
|
// to hand-run the formatter. JSON.stringify's indent puts every array element
|
|
@@ -2164,7 +2200,8 @@ function ratchet(file, options) {
|
|
|
2164
2200
|
const present = existsSync(file);
|
|
2165
2201
|
if (!present && !options.init)
|
|
2166
2202
|
throw new Error(`${file} does not exist; create it with --init and commit it.`);
|
|
2167
|
-
const
|
|
2203
|
+
const text = present ? readFileSync(file, "utf8") : undefined;
|
|
2204
|
+
const previous = present ? JSON.parse(text) : undefined;
|
|
2168
2205
|
const paths = options.paths.length
|
|
2169
2206
|
? options.paths.map(relative)
|
|
2170
2207
|
: (previous?.paths ?? scopeFrom(process.cwd()).map(relative));
|
|
@@ -2203,8 +2240,6 @@ function ratchet(file, options) {
|
|
|
2203
2240
|
paths,
|
|
2204
2241
|
...(only ? { only } : {}),
|
|
2205
2242
|
...(!only || only.includes("user-words") ? words : {}),
|
|
2206
|
-
total: scan.total,
|
|
2207
|
-
rules: Object.fromEntries(Object.entries(scan.rules).sort()),
|
|
2208
2243
|
offenders: offendersOf(scan, base),
|
|
2209
2244
|
};
|
|
2210
2245
|
const write = () => writeFileSync(file, formatBaseline(next));
|
|
@@ -2213,29 +2248,31 @@ function ratchet(file, options) {
|
|
|
2213
2248
|
process.stdout.write(`MPO design guard: ${file} created at ${summary(scan)}.\n`);
|
|
2214
2249
|
return 0;
|
|
2215
2250
|
}
|
|
2251
|
+
const counts = previous.rules ?? {};
|
|
2252
|
+
const recorded = new Set([...Object.keys(previous.offenders ?? {}), ...Object.keys(counts)]);
|
|
2216
2253
|
// --init on an existing baseline adopts only the rules it does not record
|
|
2217
2254
|
// yet (a rule added to MPO after the baseline was cut); recorded rules keep
|
|
2218
2255
|
// their ceilings.
|
|
2219
2256
|
const adopted = options.init
|
|
2220
|
-
? (
|
|
2257
|
+
? Object.keys(next.offenders).filter((rule) => !recorded.has(rule))
|
|
2221
2258
|
: [];
|
|
2222
|
-
const
|
|
2223
|
-
|
|
2224
|
-
const
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2259
|
+
const found = countBaseline(next).rules;
|
|
2260
|
+
const rose = [];
|
|
2261
|
+
const added = [];
|
|
2262
|
+
for (const [rule, keys] of Object.entries(next.offenders)) {
|
|
2263
|
+
if (adopted.includes(rule)) continue;
|
|
2264
|
+
const listed = previous.offenders?.[rule];
|
|
2265
|
+
if (!listed && rule in counts) {
|
|
2266
|
+
if (found[rule] > counts[rule]) rose.push(`${rule} ${counts[rule]} -> ${found[rule]}`);
|
|
2267
|
+
continue;
|
|
2268
|
+
}
|
|
2269
|
+
for (const [key, count] of Object.entries(keys))
|
|
2270
|
+
if (count > (listed?.[key] ?? 0)) added.push(`[${rule}] ${key}`);
|
|
2271
|
+
}
|
|
2233
2272
|
if (rose.length || added.length) {
|
|
2234
2273
|
process.stderr.write(
|
|
2235
2274
|
`${scan.errors.join("\n")}\nMPO design guard: ${file} regressed${
|
|
2236
|
-
rose.length
|
|
2237
|
-
? `, ${rose.map((rule) => `${rule} ${ceiling(rule)} -> ${next.rules[rule]}`).join(", ")}`
|
|
2238
|
-
: ""
|
|
2275
|
+
rose.length ? `, ${rose.join(", ")}` : ""
|
|
2239
2276
|
}${
|
|
2240
2277
|
added.length
|
|
2241
2278
|
? `; new offenders:\n ${added.join("\n ")}\nFix each the way its LC rule says (LC-175: render the MPO component). A rename of a listed offender renames its key in ${file}.\n`
|
|
@@ -2245,30 +2282,34 @@ function ratchet(file, options) {
|
|
|
2245
2282
|
return 1;
|
|
2246
2283
|
}
|
|
2247
2284
|
if (options.list && scan.errors.length) process.stderr.write(`${scan.errors.join("\n")}\n`);
|
|
2248
|
-
const
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2285
|
+
const cleared =
|
|
2286
|
+
sum(
|
|
2287
|
+
Object.entries(previous.offenders ?? {}).flatMap(([rule, keys]) =>
|
|
2288
|
+
Object.entries(keys).map(([key, count]) =>
|
|
2289
|
+
Math.max(0, count - (next.offenders[rule]?.[key] ?? 0)),
|
|
2290
|
+
),
|
|
2291
|
+
),
|
|
2292
|
+
) +
|
|
2293
|
+
sum(
|
|
2294
|
+
Object.entries(counts)
|
|
2295
|
+
.filter(([rule]) => !previous.offenders?.[rule])
|
|
2296
|
+
.map(([rule, count]) => Math.max(0, count - (found[rule] ?? 0))),
|
|
2297
|
+
);
|
|
2298
|
+
const stale = "total" in previous || "rules" in previous;
|
|
2299
|
+
if ((options.tighten || options.init) && text !== formatBaseline(next)) {
|
|
2263
2300
|
write();
|
|
2264
2301
|
process.stdout.write(
|
|
2265
2302
|
adopted.length
|
|
2266
2303
|
? `MPO design guard: ${file} adopted ${adopted.join(", ")}. ${summary(scan)}.\n`
|
|
2267
|
-
: `MPO design guard: ${file}
|
|
2304
|
+
: `MPO design guard: ${file} tightened, ${cleared} offenders cleared. ${summary(scan)}.\n`,
|
|
2268
2305
|
);
|
|
2269
2306
|
return 0;
|
|
2270
2307
|
}
|
|
2271
|
-
process.stdout.write(
|
|
2308
|
+
process.stdout.write(
|
|
2309
|
+
`MPO design guard: ${file} holds at ${summary(scan)}${
|
|
2310
|
+
cleared ? `; ${cleared} cleared offenders stay listed until --tighten` : ""
|
|
2311
|
+
}${stale ? "; it still stores total and rules, which --tighten drops" : ""}.\n`,
|
|
2312
|
+
);
|
|
2272
2313
|
return 0;
|
|
2273
2314
|
}
|
|
2274
2315
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/config",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.11.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": "^9.
|
|
125
|
+
"@multiplatform.one/utils": "^9.11.0",
|
|
126
126
|
"@tamagui/vite-plugin": "2.7.6",
|
|
127
127
|
"@vitejs/plugin-react": "^6.1.2",
|
|
128
128
|
"dotenv": "^17.4.2",
|