@multiplatform.one/config 7.67.0 → 7.69.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.
Files changed (3) hide show
  1. package/README.md +55 -8
  2. package/design-lint.mjs +720 -28
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -162,9 +162,49 @@ MPO-ONLY-REUSE), with the MPO component to use. So is a card painted in place:
162
162
  a fill plus a radius, border or shadow around inset content. Composing the MPO
163
163
  role passes. A stopgap declares `// mpo-role-escape: <reason>` above it.
164
164
 
165
+ The rules harvested from SHC (FZ-8025, FZ-8033) travel with the lint so every
166
+ MPO app gets them (LC-192):
167
+
168
+ - UI copy (JSX text, copy attributes and keys such as `label`, `title` and
169
+ `placeholder`, `t()` keys and `defaultValue`, and every value in a string
170
+ catalog under `i18n/`, `locales/` or `localizations/`, JSON included) is
171
+ sentence case (`copy-title-case`), never hedges a plural with "(s)"
172
+ (`copy-plural`), writes "and" for "&" (`copy-ampersand`) and carries no em
173
+ dash except the lone placeholder "—" (`copy-em-dash`, all LC-202).
174
+ - `user-words` (LC-203) rejects implementation words in UI copy. The house list
175
+ is `houseBannedWords`; a baseline's `bannedWords` replaces it for that app,
176
+ and its `properNames` lists the names `copy-title-case` leaves alone.
177
+ - `error-copy` (LC-204) rejects error copy (a key or catalog path naming an
178
+ error or failure) that leads with a number, a code or an identifier.
179
+ - `refresh-label` (LC-216) and `zoom-button` (LC-217) reject a standing
180
+ Refresh or Reload control and zoom-in/out buttons; `zoom-lock` (LC-196)
181
+ rejects a viewport, in source or an `.html` page, that disables pinch zoom.
182
+ - `web-paint` (LC-206) rejects paint React Native can't draw: `mixBlendMode`,
183
+ `clipPath`, `textShadow*`, `backdropFilter`, masks, CSS `filter` functions
184
+ and the same properties in CSS text. SVG artwork keeps its `clipPath`. The
185
+ MPO `Material` component is the one file allowed a backdrop blur.
186
+ - `action-word` (LC-260 ICONS-OVER-WORDS) rejects a button or pressable whose
187
+ whole visible label (children, `label`, `title`, `Button.Text`, a `t()`
188
+ default or the last segment of its key) is a standard action word: Add,
189
+ Remove, Replace, Delete, Edit, Save, Cancel, Close, Done, Share, Search,
190
+ Filter, Sort, Upload, Download, Copy, Refresh, Settings, More, Back, Next,
191
+ Send, Export or Import. Draw the icon and put the word in the accessibility
192
+ label. Only a form's submit (`type="submit"` or inside `Form.Trigger`) and a
193
+ destructive confirm (Delete or Remove in a Danger section, confirm alert or
194
+ destructive action, or carrying a destructive `intent`) stay words.
195
+ - `art-tint` (LC-207) rejects `tintColor` on an image whose source isn't a
196
+ glyph (a source naming an icon, glyph or symbol).
197
+ - `link-chrome` (LC-181) rejects `color`, `fontWeight` and text decoration set
198
+ on an `Anchor`, `Link` or `a`, directly or in a style.
199
+ - `api-vocabulary` (LC-180) checks exported `*Props` types: `density`, `scale`
200
+ and a string-valued `level` are `size`; `enabled` is `disabled`; `isOpen`,
201
+ `opened` and `isVisible` are the `open` triad; a hue-valued enum or a
202
+ `variant` carrying a semantic colour is `intent`, `severity` or `tone`; a
203
+ negative boolean (`noX`, `hideX`, `disableX`) is named positively.
204
+
165
205
  Every violation is tagged with its rule: `field-action`, `field-focus`, `hex`,
166
- `geometry`, `inline-spacing`, `mpo-role`, `raw-control`, `styled-mpo` or
167
- `token-file`.
206
+ `geometry`, `inline-spacing`, `mpo-role`, `raw-control`, `styled-mpo`,
207
+ `token-file` or one of the harvested rules above (`harvestRules`).
168
208
 
169
209
  #### Ratchet
170
210
 
@@ -181,15 +221,22 @@ run rewrites the baseline down and exits 0; commit it. `--frozen` fails that
181
221
  case instead, so CI catches a lowered count nobody committed. `--list` prints
182
222
  the violations on a passing run. `--baseline` may repeat; MPO's `pnpm
183
223
  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,
224
+ `packages`, `public/backoffice`, `public/frappe-ui` and `public` (the harvested
225
+ rules over every MPO package) this way.
226
+
227
+ `mpo-role` and the harvested rules are also recorded by offender (file and
228
+ component, or file and string), so a new offender fails even when another was
229
+ fixed in the same change, and line moves don't count. `--only <rule>`
230
+ (repeatable) cuts a baseline that ratchets just those rules; `--only harvest`
231
+ takes all the harvested rules. `--init` on an existing baseline adopts the rules it doesn't record yet,
190
232
  such as `mpo-role` in a baseline cut before it shipped, and leaves the recorded
191
233
  ceilings alone.
192
234
 
235
+ `mpo-design-lint --verify-ci [dir]` is LC-192's fitness check: it fails when
236
+ the repo's `.gitlab-ci.yml` or GitHub workflows never run the lint, run it
237
+ without `--frozen`, or skip a committed `design-baseline.json`. It follows a CI
238
+ line into `package.json` scripts and `Makefile` recipes.
239
+
193
240
  The implementation is also exported from `@multiplatform.one/config/design-lint`
194
241
  as `inspectDesign(source, filename)`, `designFiles(path)` and `runDesignLint(paths)`.
195
242
  It derives from Pelt's `db7ce75c` guard. TypeScript ships as a runtime dependency.
package/design-lint.mjs CHANGED
@@ -63,6 +63,11 @@ const fieldTag =
63
63
  const actionTag =
64
64
  /^(?:Button|IconButton|TamaguiButton|Pressable|TouchableOpacity|TouchableHighlight|button)$|\.Button$/;
65
65
  const rowTag = /^(?:XStack|XGroup)$|\.XGroup$/;
66
+ // LC-176 ICON-BUTTON: an icon-only button is a bare tinted glyph. A prop that
67
+ // paints a plate or a ring around the glyph needs the over-media plate.
68
+ const buttonTag = /^(?:Button|IconButton|TamaguiButton|PageBarButton)$|\.Button$/;
69
+ const platePaint =
70
+ /^(?:outlined|circular|bordered|elevate|elevation|bg|backgroundColor|background|borderWidth|borderColor|variant)$/;
66
71
  const tokenFactories = new Set([
67
72
  "createTokens",
68
73
  "createTamagui",
@@ -148,11 +153,30 @@ const rawPrimitive =
148
153
  const surfacePaint =
149
154
  /^(?: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)$/;
150
155
 
156
+ // FZ-8033: the rules harvested from SHC (FZ-8025) that every MPO app and
157
+ // package carries, public/* included.
158
+ export const harvestRules = [
159
+ "api-vocabulary",
160
+ "art-tint",
161
+ "copy-ampersand",
162
+ "copy-em-dash",
163
+ "copy-plural",
164
+ "copy-title-case",
165
+ "action-word",
166
+ "error-copy",
167
+ "link-chrome",
168
+ "refresh-label",
169
+ "user-words",
170
+ "web-paint",
171
+ "zoom-button",
172
+ "zoom-lock",
173
+ ];
151
174
  export const designRules = [
152
175
  "field-action",
153
176
  "field-focus",
154
177
  "hex",
155
178
  "geometry",
179
+ "icon-button",
156
180
  "inline-spacing",
157
181
  "mpo-role",
158
182
  "phosphor-import",
@@ -160,10 +184,196 @@ export const designRules = [
160
184
  "raw-icon",
161
185
  "styled-mpo",
162
186
  "token-file",
187
+ ...harvestRules,
163
188
  ];
164
189
  // Rules whose baseline records each offender, so a new offender fails even
165
190
  // when another one was fixed in the same change.
166
- export const identityRules = new Set(["mpo-role"]);
191
+ export const identityRules = new Set(["icon-button", "mpo-role", ...harvestRules]);
192
+ // LC-203 USER-WORDS: implementation words a user never reads. A baseline's
193
+ // bannedWords replaces this list for its app; --init seeds it.
194
+ export const houseBannedWords = [
195
+ "API",
196
+ "GraphQL",
197
+ "HTTP",
198
+ "JSON",
199
+ "RPC",
200
+ "SQL",
201
+ "Tamagui",
202
+ "UUID",
203
+ "WebSocket",
204
+ "endpoint",
205
+ "localStorage",
206
+ "null",
207
+ "payload",
208
+ "stderr",
209
+ "stdout",
210
+ "undefined",
211
+ "websocket",
212
+ ];
213
+ // LC-202: proper names keep their capitals, so they are not Title Case.
214
+ export const houseProperNames = [
215
+ "Kitchen Sink",
216
+ "Multiplatform One",
217
+ "Pro Manager",
218
+ "Self Hosted Cloud",
219
+ ];
220
+ const copyAttribute =
221
+ /^(?:label|title|subtitle|description|placeholder|aria-label|aria-description|accessibilityLabel|accessibilityHint|helperText|hint|message|heading|caption|tooltip|emptyText|emptyTitle|emptyDescription|confirmLabel|confirmText|cancelLabel|cancelText|actionLabel|successMessage)$/;
222
+ const errorKey = /(?:^error|Error|^fail|Fail|Failure)\w*$/;
223
+ const pluralHedge = /[a-z]{2,}\(s\)(?=[\s"'`?.,;:!)]|$)/;
224
+ const errorLead =
225
+ /^(?:\d|\{x\}\s*:|[A-Z][A-Z0-9]*_[A-Z0-9_]*\b|[A-Z]{2,}[A-Z0-9]*(?::|\s+\d)|[a-z][a-z0-9]*(?:[A-Z_.][A-Za-z0-9_]*)+\b)/;
226
+ const webPaintKey =
227
+ /^(?:mixBlendMode|clipPath|textShadow(?:Color|Offset|Radius)?|backdropFilter|WebkitBackdropFilter|mask|maskImage|maskSize|WebkitMask|WebkitMaskImage|WebkitMaskSize)$/;
228
+ // LC-260 ICONS-OVER-WORDS: a standard action is drawn as its symbol, its word
229
+ // lives in the accessibility label. Only a form's submit and a destructive
230
+ // confirm stay words (HIG).
231
+ const actionWord =
232
+ /^(?:add|remove|replace|delete|edit|save|cancel|close|done|share|search|filter|sort|upload|download|copy|refresh|settings|more|back|next|send|export|import)$/i;
233
+ const wordControl =
234
+ /^(?:Button|TamaguiButton|Pressable|TouchableOpacity|TouchableHighlight|button|(?!Icon|Action)[A-Z]\w*Button)$|\.Button$/;
235
+ const destructiveWord = /^(?:delete|remove)$/i;
236
+ const destructiveHome = /Confirm|AlertDialog|Danger|Destructive/;
237
+ const destructiveTone = /^(?:intent|tone|severity|theme|variant)$/;
238
+ const destructiveValue = /destructive|danger|red|error/i;
239
+ const backdropKey = /^(?:backdropFilter|WebkitBackdropFilter)$/;
240
+ const materialHome = /(?:^|[\\/])components[\\/]src[\\/]Material[\\/]index\.tsx$/;
241
+ const cssFilter =
242
+ /^\s*(?:blur|grayscale|brightness|contrast|saturate|sepia|invert|hue-rotate|drop-shadow)\(/;
243
+ const cssWebPaint =
244
+ /(?:^|[;{\s"'`])(?:mix-blend-mode|backdrop-filter|-webkit-backdrop-filter|clip-path|text-shadow|-webkit-mask(?:-image)?|mask-image)\s*:/;
245
+ const zoomLock = /user-scalable\s*=\s*(?:no|0)\b|maximum-scale\s*=\s*1(?:\.0)?\b/;
246
+ const linkTag = /^(?:a|Anchor|Link|TextLink|InlineLink|ExternalLink)$|\.(?:Anchor|Link)$/;
247
+ const linkPaint =
248
+ /^(?:color|fontWeight|textDecoration|textDecorationLine|textDecorationColor|textDecorationStyle)$/;
249
+ const imageTag = /^(?:Image|img|ImageBackground|AvatarImage|FastImage|ExpoImage)$|\.Image$/;
250
+ const glyphSource = /glyph|icon|symbol|mono/i;
251
+ const hue =
252
+ /^(?:red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose|gray|grey|slate|black|white|brown)$/;
253
+ const bannedCache = new Map();
254
+ function bannedPattern(words) {
255
+ const key = words.join("\0");
256
+ if (!bannedCache.has(key))
257
+ bannedCache.set(
258
+ key,
259
+ words.length
260
+ ? new RegExp(
261
+ `(?<![\\w-])(?:${words.map((word) => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})(?![\\w-])`,
262
+ )
263
+ : undefined,
264
+ );
265
+ return bannedCache.get(key);
266
+ }
267
+ const clip = (text) => {
268
+ const flat = text.replace(/\s+/g, " ").replaceAll(";", ",").trim();
269
+ return flat.length > 60 ? `${flat.slice(0, 57)}...` : flat;
270
+ };
271
+ function titleCase(text, names) {
272
+ let value = text.replace(/\{x\}/g, " ");
273
+ for (const proper of names) value = value.replaceAll(proper, " ");
274
+ if (/[/=<>$_@#\\|{}[\]]/.test(value)) return false;
275
+ const words = value
276
+ .split(/\s+/)
277
+ .map((word) => word.replace(/^[^A-Za-z]+|[^A-Za-z']+$/g, ""))
278
+ .filter(Boolean);
279
+ if (words.length < 2 || words.length > 8 || !/^[A-Z]/.test(words[0])) return false;
280
+ // Every later word capitalised, small words included. "Terms of Service"
281
+ // reads the same as "Sign in with Google", so a lowercase word clears it.
282
+ const rest = words.slice(1);
283
+ return (
284
+ rest.some((word) => /^[A-Z][a-z']+$/.test(word)) && !rest.some((word) => /^[a-z]/.test(word))
285
+ );
286
+ }
287
+ // The copy rules (LC-202, 203, 204, 216, 217) over one UI string.
288
+ export function copyFindings(text, { error = false, bannedWords, properNames } = {}) {
289
+ const value = text
290
+ .replace(/\{\{[^}]*\}\}|\{[^{}]*\}/g, "{x}")
291
+ .replace(/\s+/g, " ")
292
+ .trim();
293
+ const found = [];
294
+ if (!value || value === "—") return found;
295
+ const quoted = `"${clip(value)}"`;
296
+ if (value.includes("—"))
297
+ found.push([
298
+ "copy-em-dash",
299
+ `${quoted} carries an em dash; use a period, comma or colon (LC-202).`,
300
+ ]);
301
+ if (!/[A-Za-z]/.test(value)) return found;
302
+ if (pluralHedge.test(value) && !/https?\(s\)/.test(value))
303
+ found.push([
304
+ "copy-plural",
305
+ `${quoted} hedges a plural; count through t()'s plural form (LC-202).`,
306
+ ]);
307
+ if (/(?:^|\s)&(?:\s|$)/.test(value))
308
+ found.push(["copy-ampersand", `${quoted} uses "&"; write "and" (LC-202).`]);
309
+ if (titleCase(value, properNames ?? houseProperNames))
310
+ found.push(["copy-title-case", `${quoted} is Title Case; UI copy is sentence case (LC-202).`]);
311
+ const word = value.match(bannedPattern(bannedWords ?? houseBannedWords) ?? /$^/)?.[0];
312
+ if (word)
313
+ found.push([
314
+ "user-words",
315
+ `${quoted} says "${word}", an implementation word; use the app's user-facing name (LC-203).`,
316
+ ]);
317
+ if (error && errorLead.test(value))
318
+ found.push([
319
+ "error-copy",
320
+ `${quoted} leads with a code; say what failed, then what to do (LC-204).`,
321
+ ]);
322
+ if (/^(?:Refresh|Reload)$/i.test(value))
323
+ found.push([
324
+ "refresh-label",
325
+ `${quoted} is a standing refresh control; live data refreshes itself (LC-216).`,
326
+ ]);
327
+ if (/^Zoom (?:in|out)$/i.test(value))
328
+ found.push(["zoom-button", `${quoted} is a zoom button; zoom is a gesture (LC-217).`]);
329
+ return found;
330
+ }
331
+ // A string catalog: a file in an i18n, locales or localizations directory,
332
+ // directly or under a locale code.
333
+ const catalogFile =
334
+ /(?:^|[\\/])(?:i18n|locales|localizations)[\\/](?:[a-z]{2}(?:[-_][A-Za-z]{2,4})?[\\/])?(?!(?:index|env|resources|package|tsconfig)\.)[\w.-]+\.(?:json|[cm]?[jt]s)$/;
335
+ function lineOf(source, index) {
336
+ let line = 1;
337
+ for (let at = source.indexOf("\n"); at !== -1 && at < index; at = source.indexOf("\n", at + 1))
338
+ line++;
339
+ return line;
340
+ }
341
+ // A JSON string catalog: every leaf is UI copy, and a key path naming an
342
+ // error or failure makes it error copy.
343
+ function inspectCatalog(source, filename, options) {
344
+ let data;
345
+ try {
346
+ data = JSON.parse(source);
347
+ } catch {
348
+ return [];
349
+ }
350
+ const errors = [];
351
+ let cursor = 0;
352
+ (function walk(value, keys) {
353
+ if (typeof value === "string") {
354
+ const at = source.indexOf(JSON.stringify(value), cursor);
355
+ if (at !== -1) cursor = at;
356
+ for (const [rule, message] of copyFindings(value, {
357
+ ...options,
358
+ error: keys.some((key) => errorKey.test(key)),
359
+ }))
360
+ errors.push(`${filename}:${lineOf(source, cursor)}:1: [${rule}] ${message}`);
361
+ } else if (value && typeof value === "object")
362
+ for (const [key, inner] of Object.entries(value)) walk(inner, [...keys, key]);
363
+ })(data, []);
364
+ return errors;
365
+ }
366
+ function inspectHtml(source, filename) {
367
+ return source
368
+ .split("\n")
369
+ .flatMap((line, index) =>
370
+ zoomLock.test(line)
371
+ ? [
372
+ `${filename}:${index + 1}:1: [zoom-lock] ${clip(line.match(zoomLock)[0])} disables pinch zoom (LC-196).`,
373
+ ]
374
+ : [],
375
+ );
376
+ }
167
377
  export function isFreeformBoard(filename, projectRoot = process.cwd()) {
168
378
  const root = path.resolve(projectRoot);
169
379
  const absolute = path.resolve(root, filename);
@@ -179,8 +389,12 @@ export function isFreeformBoard(filename, projectRoot = process.cwd()) {
179
389
  );
180
390
  }
181
391
 
182
- export function inspectDesign(source, filename, projectRoot = process.cwd()) {
392
+ export function inspectDesign(source, filename, projectRoot = process.cwd(), options = {}) {
183
393
  if (isFreeformBoard(filename, projectRoot)) return [];
394
+ if (/\.json$/.test(filename)) return inspectCatalog(source, filename, options);
395
+ if (/\.html?$/.test(filename)) return inspectHtml(source, filename);
396
+ const catalog = catalogFile.test(filename);
397
+ const material = materialHome.test(filename);
184
398
  const file = ts.createSourceFile(
185
399
  filename,
186
400
  source,
@@ -188,23 +402,28 @@ export function inspectDesign(source, filename, projectRoot = process.cwd()) {
188
402
  true,
189
403
  ts.ScriptKind.TSX,
190
404
  );
191
- const options = {
192
- noLib: true,
193
- noResolve: true,
194
- types: [],
195
- jsx: ts.JsxEmit.Preserve,
405
+ let lazyChecker;
406
+ const typeChecker = () => {
407
+ if (lazyChecker) return lazyChecker;
408
+ const compilerOptions = {
409
+ noLib: true,
410
+ noResolve: true,
411
+ types: [],
412
+ jsx: ts.JsxEmit.Preserve,
413
+ };
414
+ const host = ts.createCompilerHost(compilerOptions);
415
+ host.getSourceFile = (requested) => (requested === filename ? file : undefined);
416
+ host.fileExists = (requested) => requested === filename;
417
+ host.readFile = (requested) => (requested === filename ? source : undefined);
418
+ host.directoryExists = () => false;
419
+ lazyChecker = ts.createProgram([filename], compilerOptions, host).getTypeChecker();
420
+ return lazyChecker;
196
421
  };
197
- const host = ts.createCompilerHost(options);
198
- host.getSourceFile = (requested) => (requested === filename ? file : undefined);
199
- host.fileExists = (requested) => requested === filename;
200
- host.readFile = (requested) => (requested === filename ? source : undefined);
201
- host.directoryExists = () => false;
202
- const checker = ts.createProgram([filename], options, host).getTypeChecker();
203
422
  const errors = [];
204
423
  function importedFrom(node, test) {
205
424
  const value = resolve(node);
206
425
  const root = ts.isPropertyAccessExpression(value) ? value.expression : value;
207
- const declarations = checker.getSymbolAtLocation(root)?.declarations ?? [];
426
+ const declarations = typeChecker().getSymbolAtLocation(root)?.declarations ?? [];
208
427
  return declarations.some((declaration) => {
209
428
  let current = declaration;
210
429
  while (current && !ts.isImportDeclaration(current)) current = current.parent;
@@ -262,7 +481,7 @@ export function inspectDesign(source, filename, projectRoot = process.cwd()) {
262
481
  )
263
482
  return resolve(node.expression, seen);
264
483
  const declaration = ts.isIdentifier(node)
265
- ? checker.getSymbolAtLocation(node)?.valueDeclaration
484
+ ? typeChecker().getSymbolAtLocation(node)?.valueDeclaration
266
485
  : undefined;
267
486
  if (
268
487
  declaration &&
@@ -298,7 +517,7 @@ export function inspectDesign(source, filename, projectRoot = process.cwd()) {
298
517
  function referenceName(node) {
299
518
  const value = resolve(node);
300
519
  const declaration = ts.isIdentifier(value)
301
- ? checker.getSymbolAtLocation(value)?.declarations?.[0]
520
+ ? typeChecker().getSymbolAtLocation(value)?.declarations?.[0]
302
521
  : undefined;
303
522
  if (declaration && ts.isImportSpecifier(declaration))
304
523
  return (declaration.propertyName ?? declaration.name).text;
@@ -423,6 +642,331 @@ export function inspectDesign(source, filename, projectRoot = process.cwd()) {
423
642
  const { line, character } = file.getLineAndCharacterOfPosition(node.getStart(file));
424
643
  errors.push(`${filename}:${line + 1}:${character + 1}: [${rule}] ${message}`);
425
644
  }
645
+ const tCall = (node) =>
646
+ ts.isCallExpression(node) && /^(?:t|\w+\.t)$/.test(node.expression.getText(file));
647
+ function keyPath(node) {
648
+ const keys = [];
649
+ for (let current = node; current; current = current.parent)
650
+ if (ts.isPropertyAssignment(current)) keys.push(name(current.name));
651
+ return keys;
652
+ }
653
+ // Where a string literal lands decides whether it is UI copy: a JSX child,
654
+ // a copy attribute or key, t()'s key and defaultValue, or a catalog value.
655
+ function copyContext(node) {
656
+ let child = node;
657
+ let parent = node.parent;
658
+ while (
659
+ parent &&
660
+ (ts.isParenthesizedExpression(parent) ||
661
+ ts.isAsExpression(parent) ||
662
+ ts.isSatisfiesExpression(parent) ||
663
+ ts.isTemplateSpan(parent) ||
664
+ (ts.isConditionalExpression(parent) && parent.condition !== child) ||
665
+ (ts.isBinaryExpression(parent) &&
666
+ (parent.operatorToken.kind === ts.SyntaxKind.PlusToken ||
667
+ parent.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken ||
668
+ parent.operatorToken.kind === ts.SyntaxKind.BarBarToken ||
669
+ (parent.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken &&
670
+ parent.right === child))))
671
+ ) {
672
+ child = parent;
673
+ parent = parent.parent;
674
+ }
675
+ if (!parent) return undefined;
676
+ if (ts.isTemplateExpression(parent)) return undefined;
677
+ if (ts.isJsxExpression(parent)) {
678
+ if (ts.isJsxElement(parent.parent) || ts.isJsxFragment(parent.parent)) return {};
679
+ parent = parent.parent;
680
+ }
681
+ if (ts.isJsxAttribute(parent)) {
682
+ const key = name(parent.name);
683
+ if (copyAttribute.test(key)) return { error: errorKey.test(key) };
684
+ return errorKey.test(key) ? { error: true } : undefined;
685
+ }
686
+ if (ts.isPropertyAssignment(parent) && parent.initializer === child) {
687
+ const key = name(parent.name);
688
+ if (catalog) return { error: keyPath(parent).some((item) => errorKey.test(item)) };
689
+ if (key === "defaultValue" && tCall(parent.parent.parent)) {
690
+ const id = parent.parent.parent.arguments[0];
691
+ return { error: !!id && ts.isStringLiteralLike(id) && /error|fail/i.test(id.text) };
692
+ }
693
+ if (copyAttribute.test(key)) return { error: errorKey.test(key) };
694
+ return errorKey.test(key) ? { error: true } : undefined;
695
+ }
696
+ if (tCall(parent) && parent.arguments[0] === child && /\s/.test(node.getText(file))) return {};
697
+ return undefined;
698
+ }
699
+ function stringText(node) {
700
+ if (ts.isJsxText(node))
701
+ return node.text
702
+ .replaceAll("&amp;", "&")
703
+ .replaceAll("&mdash;", "—")
704
+ .replaceAll("&nbsp;", " ");
705
+ if (ts.isTemplateExpression(node))
706
+ return [node.head.text, ...node.templateSpans.map((span) => span.literal.text)].join("{x}");
707
+ return node.text;
708
+ }
709
+ function checkCopy(node) {
710
+ const context = ts.isJsxText(node) ? {} : copyContext(node);
711
+ const text = stringText(node);
712
+ if (!ts.isJsxText(node)) {
713
+ if (zoomLock.test(text))
714
+ report(node, "zoom-lock", `${clip(text.match(zoomLock)[0])} disables pinch zoom (LC-196).`);
715
+ if (cssWebPaint.test(text))
716
+ report(
717
+ node,
718
+ "web-paint",
719
+ `${clip(text.match(cssWebPaint)[0])} is CSS React Native cannot draw (LC-206).`,
720
+ );
721
+ }
722
+ if (!context) return;
723
+ for (const [rule, message] of copyFindings(text, { ...options, ...context }))
724
+ report(node, rule, message);
725
+ }
726
+ function literalTypes(type) {
727
+ if (!type) return [];
728
+ if (ts.isUnionTypeNode(type)) return type.types.flatMap(literalTypes);
729
+ if (ts.isParenthesizedTypeNode(type)) return literalTypes(type.type);
730
+ if (ts.isLiteralTypeNode(type) && ts.isStringLiteral(type.literal)) return [type.literal.text];
731
+ return [];
732
+ }
733
+ const booleanType = (type) =>
734
+ !!type &&
735
+ (type.kind === ts.SyntaxKind.BooleanKeyword ||
736
+ (ts.isLiteralTypeNode(type) &&
737
+ [ts.SyntaxKind.TrueKeyword, ts.SyntaxKind.FalseKeyword].includes(type.literal.kind)));
738
+ // LC-180 API-VOCABULARY over the props a module exports.
739
+ function checkProps(declaration) {
740
+ const members = ts.isInterfaceDeclaration(declaration)
741
+ ? declaration.members
742
+ : (function collect(type) {
743
+ if (ts.isTypeLiteralNode(type)) return [...type.members];
744
+ if (ts.isIntersectionTypeNode(type) || ts.isUnionTypeNode(type))
745
+ return type.types.flatMap(collect);
746
+ if (ts.isParenthesizedTypeNode(type)) return collect(type.type);
747
+ return [];
748
+ })(declaration.type);
749
+ const owner = declaration.name.text;
750
+ for (const member of members) {
751
+ if (!ts.isPropertySignature(member) || !member.name) continue;
752
+ const prop = name(member.name);
753
+ const literals = literalTypes(member.type);
754
+ let problem;
755
+ if (/^(?:density|scale)$/.test(prop) || (prop === "level" && literals.length))
756
+ problem = `${prop} is a synonym for size; take a size token`;
757
+ else if (prop === "enabled") problem = "enabled is a negative of disabled; use disabled";
758
+ else if (/^(?:isOpen|opened|isVisible|onVisibleChange|onIsOpenChange)$/.test(prop))
759
+ problem = `${prop} names disclosure; use open, defaultOpen and onOpenChange`;
760
+ else if (
761
+ /^(?:color|tone|intent|severity|variant|kind|status)$/.test(prop) &&
762
+ literals.some((value) => hue.test(value))
763
+ )
764
+ problem = `${prop} is a hue-valued enum; semantic colour is intent, severity or tone`;
765
+ else if (
766
+ /^(?:variant|appearance)$/.test(prop) &&
767
+ literals.some((value) => /^(?:danger|destructive|success|warning|error|info)$/.test(value))
768
+ )
769
+ problem = `${prop} carries a semantic colour; that is intent, severity or tone`;
770
+ else if (prop === "kind" && literals.some((value) => /^(?:ghost|outline|solid)$/.test(value)))
771
+ problem = "kind names a look; use the stock variant names";
772
+ else if (
773
+ /^(?:no|not|non|disable|dont|without|hide|skip|omit|exclude)[A-Z]/.test(prop) &&
774
+ booleanType(member.type)
775
+ )
776
+ problem = `${prop} is a negative boolean; name it positively, default false`;
777
+ if (problem) report(member, "api-vocabulary", `${owner}.${problem} (LC-180).`);
778
+ }
779
+ }
780
+ const exported = (node) =>
781
+ !!node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
782
+ function stylePaints(node, test, seen = new Set()) {
783
+ const value = resolve(node);
784
+ if (seen.has(value)) return undefined;
785
+ seen.add(value);
786
+ if (ts.isConditionalExpression(value))
787
+ return stylePaints(value.whenTrue, test, seen) ?? stylePaints(value.whenFalse, test, seen);
788
+ if (ts.isArrayLiteralExpression(value))
789
+ for (const item of value.elements) {
790
+ const inner = stylePaints(item, test, seen);
791
+ if (inner) return inner;
792
+ }
793
+ if (!ts.isObjectLiteralExpression(value)) return undefined;
794
+ for (const prop of value.properties) {
795
+ if (ts.isSpreadAssignment(prop)) {
796
+ const inner = stylePaints(prop.expression, test, seen);
797
+ if (inner) return inner;
798
+ } else if (prop.name && test.test(name(prop.name))) return name(prop.name);
799
+ else if (ts.isPropertyAssignment(prop) && /style$/i.test(name(prop.name))) {
800
+ const inner = stylePaints(prop.initializer, test, seen);
801
+ if (inner) return inner;
802
+ }
803
+ }
804
+ return undefined;
805
+ }
806
+ function paintedBy(element, test) {
807
+ for (const attr of element.attributes.properties) {
808
+ if (ts.isJsxSpreadAttribute(attr)) continue;
809
+ const key = name(attr.name);
810
+ if (test.test(key)) return key;
811
+ const value =
812
+ attr.initializer && ts.isJsxExpression(attr.initializer)
813
+ ? attr.initializer.expression
814
+ : undefined;
815
+ if (value && /style$/i.test(key)) {
816
+ const inner = stylePaints(value, test);
817
+ if (inner) return inner;
818
+ }
819
+ }
820
+ return undefined;
821
+ }
822
+ function visibleText(node) {
823
+ if (!node) return [];
824
+ if (ts.isJsxText(node)) return node.text.trim() ? [node.text.trim()] : [];
825
+ if (ts.isStringLiteralLike(node)) return [node.text];
826
+ if (ts.isJsxExpression(node) || ts.isParenthesizedExpression(node))
827
+ return visibleText(node.expression);
828
+ if (tCall(node)) {
829
+ const [id, fallback] = node.arguments;
830
+ if (fallback && ts.isStringLiteralLike(fallback)) return [fallback.text];
831
+ const value =
832
+ fallback &&
833
+ ts.isObjectLiteralExpression(fallback) &&
834
+ fallback.properties.find(
835
+ (prop) => ts.isPropertyAssignment(prop) && name(prop.name) === "defaultValue",
836
+ )?.initializer;
837
+ if (value && ts.isStringLiteralLike(value)) return [value.text];
838
+ if (id && ts.isStringLiteralLike(id)) return [id.text.split(/[.:]/).pop()];
839
+ return [];
840
+ }
841
+ if (ts.isJsxElement(node) && /Text$/.test(tagText(node.openingElement.tagName)))
842
+ return node.children.flatMap(visibleText);
843
+ return [];
844
+ }
845
+ function actionLabel(element) {
846
+ const parts = ["label", "title", "children"].flatMap((key) => {
847
+ const attr = attribute(element, key);
848
+ return attr?.initializer ? visibleText(attr.initializer) : [];
849
+ });
850
+ if (ts.isJsxElement(element)) parts.push(...element.children.flatMap(visibleText));
851
+ return parts
852
+ .join(" ")
853
+ .replace(/(?:…|\.\.\.|:)\s*$/, "")
854
+ .trim();
855
+ }
856
+ function keptAsWord(element, word) {
857
+ if (attribute(element, "type")?.initializer?.getText(file).includes("submit")) return true;
858
+ for (let current = element.parent; current; current = current.parent) {
859
+ const owner =
860
+ ts.isJsxElement(current) || ts.isJsxSelfClosingElement(current)
861
+ ? tagText(opening(current).tagName)
862
+ : (ts.isFunctionDeclaration(current) || ts.isVariableDeclaration(current)) &&
863
+ current.name &&
864
+ ts.isIdentifier(current.name)
865
+ ? current.name.text
866
+ : "";
867
+ if (/^Form\.Trigger$/.test(owner)) return true;
868
+ if (destructiveWord.test(word) && destructiveHome.test(owner)) return true;
869
+ }
870
+ if (!destructiveWord.test(word)) return false;
871
+ if (destructiveHome.test(tagText(opening(element).tagName))) return true;
872
+ return opening(element).attributes.properties.some(
873
+ (attr) =>
874
+ ts.isJsxAttribute(attr) &&
875
+ destructiveTone.test(name(attr.name)) &&
876
+ destructiveValue.test(attr.initializer?.getText(file) ?? ""),
877
+ );
878
+ }
879
+ function platedIconButton(element) {
880
+ const tag = opening(element);
881
+ if (!buttonTag.test(tagText(tag.tagName)) || !iconOnly(element)) return undefined;
882
+ if (attribute(element, "verb") || attribute(element, "children")) return undefined;
883
+ const plate = attribute(element, "plate");
884
+ if (plate?.initializer && /["'](?:media|primary)["']/.test(plate.initializer.getText(file)))
885
+ return undefined;
886
+ return tag.attributes.properties.find((attr) => {
887
+ if (!ts.isJsxAttribute(attr)) return false;
888
+ const key = name(attr.name);
889
+ const value =
890
+ attr.initializer && ts.isJsxExpression(attr.initializer)
891
+ ? attr.initializer.expression
892
+ : attr.initializer;
893
+ const off = !!value && (inert(value) || value.kind === ts.SyntaxKind.FalseKeyword);
894
+ if (key === "chromeless") return !!value && value.kind === ts.SyntaxKind.FalseKeyword;
895
+ return platePaint.test(key) && !off;
896
+ });
897
+ }
898
+ function checkIconButton(element) {
899
+ const plated = platedIconButton(element);
900
+ if (plated)
901
+ report(
902
+ plated,
903
+ "icon-button",
904
+ `An icon-only button is a bare tinted glyph; drop ${name(plated.name)}, or pass plate="media" over imagery (LC-176 ICON-BUTTON).`,
905
+ );
906
+ }
907
+ // LC-260 ICONS-OVER-WORDS at a pressable's visible label.
908
+ function checkActionWord(element) {
909
+ if (!wordControl.test(tagText(opening(element).tagName))) return;
910
+ // A domain verb that shares a standard word (Frappe's docstatus Cancel)
911
+ // names itself: `// action-word-escape: <reason>` inside the tag.
912
+ if (opening(element).getText(file).includes("action-word-escape:")) return;
913
+ const label = actionLabel(element);
914
+ if (!actionWord.test(label) || keptAsWord(element, label)) return;
915
+ report(
916
+ element,
917
+ "action-word",
918
+ `"${label}" is a standard action spelled as a word; draw its icon and put the word in the accessibility label (LC-260).`,
919
+ );
920
+ }
921
+ // LC-181 LINK-CHROME and LC-207 ART-NEVER-TINTED at a JSX use site.
922
+ function checkElement(element) {
923
+ const tag = tagText(element.tagName);
924
+ if (linkTag.test(tag)) {
925
+ const key = paintedBy(element, linkPaint);
926
+ if (key)
927
+ report(
928
+ element,
929
+ "link-chrome",
930
+ `${tag} sets ${key}; a link's ink, weight and underline come from the theme (LC-181).`,
931
+ );
932
+ }
933
+ if (imageTag.test(tag) && !svgArtwork(element) && paintedBy(element, /^tintColor$/)) {
934
+ const source = attribute(element, "source") ?? attribute(element, "src");
935
+ if (!source?.initializer || !glyphSource.test(source.initializer.getText(file)))
936
+ report(
937
+ element,
938
+ "art-tint",
939
+ `${tag} tints an image that is not a glyph asset; multi-colour art keeps its colours (LC-207).`,
940
+ );
941
+ }
942
+ for (const attr of element.attributes.properties)
943
+ if (
944
+ ts.isJsxAttribute(attr) &&
945
+ webPaintKey.test(name(attr.name)) &&
946
+ !(material && backdropKey.test(name(attr.name))) &&
947
+ !svgArtwork(element) &&
948
+ !/^[a-z]/.test(tag)
949
+ )
950
+ report(attr, "web-paint", `${name(attr.name)} is paint React Native cannot draw (LC-206).`);
951
+ }
952
+ function checkPaintKey(prop) {
953
+ if (!prop.name || ts.isComputedPropertyName(prop.name)) return;
954
+ const key = name(prop.name);
955
+ if (webPaintKey.test(key)) {
956
+ if (!(material && backdropKey.test(key)))
957
+ report(prop, "web-paint", `${key} is paint React Native cannot draw (LC-206).`);
958
+ } else if (
959
+ key === "filter" &&
960
+ ts.isPropertyAssignment(prop) &&
961
+ ts.isStringLiteralLike(prop.initializer) &&
962
+ cssFilter.test(prop.initializer.text)
963
+ )
964
+ report(
965
+ prop,
966
+ "web-paint",
967
+ `filter ${clip(prop.initializer.text)} is CSS React Native cannot draw (LC-206).`,
968
+ );
969
+ }
426
970
  let tokenFile = false;
427
971
  if (/^(?:design-)?tokens\.[cm]?[jt]sx?$/.test(path.basename(filename))) {
428
972
  tokenFile = true;
@@ -451,7 +995,7 @@ export function inspectDesign(source, filename, projectRoot = process.cwd()) {
451
995
  if (ts.isSpreadAssignment(prop)) inspectProps(prop.expression, seen, deep);
452
996
  if (ts.isPropertyAssignment(prop) || ts.isShorthandPropertyAssignment(prop)) {
453
997
  const initializer = ts.isShorthandPropertyAssignment(prop)
454
- ? checker.getShorthandAssignmentValueSymbol(prop)?.valueDeclaration?.initializer
998
+ ? typeChecker().getShorthandAssignmentValueSymbol(prop)?.valueDeclaration?.initializer
455
999
  : prop.initializer;
456
1000
  if (!initializer) return;
457
1001
  const key = name(prop.name);
@@ -484,6 +1028,29 @@ export function inspectDesign(source, filename, projectRoot = process.cwd()) {
484
1028
  }
485
1029
  const phosphorShimFile = phosphorShim.test(filename);
486
1030
  function visit(node) {
1031
+ if (
1032
+ ts.isStringLiteral(node) ||
1033
+ ts.isNoSubstitutionTemplateLiteral(node) ||
1034
+ ts.isTemplateExpression(node) ||
1035
+ ts.isJsxText(node)
1036
+ )
1037
+ checkCopy(node);
1038
+ if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) checkElement(node);
1039
+ if (ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node))
1040
+ checkPaintKey(node);
1041
+ if (
1042
+ (ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) &&
1043
+ /Props$/.test(node.name.text) &&
1044
+ exported(node)
1045
+ )
1046
+ checkProps(node);
1047
+ if (
1048
+ ts.isIdentifier(node) &&
1049
+ /^MagnifyingGlass(?:Plus|Minus)(?:Icon)?$/.test(node.text) &&
1050
+ !ts.isImportSpecifier(node.parent) &&
1051
+ !ts.isImportClause(node.parent)
1052
+ )
1053
+ report(node, "zoom-button", `${node.text} draws a zoom button; zoom is a gesture (LC-217).`);
487
1054
  const imported = moduleImported(node);
488
1055
  if (imported && !phosphorShimFile && phosphorBypass.test(imported))
489
1056
  report(
@@ -504,6 +1071,10 @@ export function inspectDesign(source, filename, projectRoot = process.cwd()) {
504
1071
  "Wrap Phosphor icons in themed() before rendering, or pass the component to an MPO icon slot.",
505
1072
  );
506
1073
  if (ts.isJsxElement(node)) checkFieldAction(node);
1074
+ if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
1075
+ checkActionWord(node);
1076
+ checkIconButton(node);
1077
+ }
507
1078
  if (
508
1079
  !tokenFile &&
509
1080
  ts.isCallExpression(node) &&
@@ -611,7 +1182,7 @@ export function inspectDesign(source, filename, projectRoot = process.cwd()) {
611
1182
  }
612
1183
  function localFrame(tag) {
613
1184
  if (!ts.isIdentifier(tag)) return undefined;
614
- const declaration = checker.getSymbolAtLocation(tag)?.valueDeclaration;
1185
+ const declaration = typeChecker().getSymbolAtLocation(tag)?.valueDeclaration;
615
1186
  if (!declaration || !ts.isVariableDeclaration(declaration) || !declaration.initializer)
616
1187
  return undefined;
617
1188
  return styledPrimitive(unwrapComponent(declaration.initializer));
@@ -815,7 +1386,9 @@ export function designFiles(input, projectRoot = process.cwd()) {
815
1386
  const info = statSync(root);
816
1387
  const eligible = (filename) =>
817
1388
  !isFreeformBoard(path.resolve(root, filename), projectRoot) &&
818
- /\.[cm]?[jt]sx?$/.test(filename) &&
1389
+ (/\.[cm]?[jt]sx?$/.test(filename) ||
1390
+ /\.html?$/.test(filename) ||
1391
+ (/\.json$/.test(filename) && catalogFile.test(filename))) &&
819
1392
  !/\.(?:test|spec|stories|config|gen|generated|d)\.[cm]?[jt]sx?$/.test(filename);
820
1393
  if (info.isFile()) return eligible(root) ? [root] : [];
821
1394
  let candidates;
@@ -872,27 +1445,52 @@ export function countDesign(errors) {
872
1445
  return { total: errors.length, rules };
873
1446
  }
874
1447
 
875
- export function scanDesign(paths) {
1448
+ // Baselines overlap (public/backoffice sits under public), so one run
1449
+ // inspects each file once per word list.
1450
+ const inspected = new Map();
1451
+ function inspectCached(filename, options) {
1452
+ const source = readFileSync(filename, "utf8");
1453
+ const key = `${filename}\0${JSON.stringify(options)}`;
1454
+ const hit = inspected.get(key);
1455
+ if (hit?.source === source) return hit.errors;
1456
+ const errors = inspectDesign(source, filename, process.cwd(), options);
1457
+ inspected.set(key, { source, errors });
1458
+ return errors;
1459
+ }
1460
+
1461
+ export function scanDesign(paths, options = {}) {
876
1462
  const files = [...new Set(paths.flatMap((input) => designFiles(input)))];
877
1463
  if (!files.length) throw new Error("No application source files found in the supplied paths.");
878
- const errors = files.flatMap((filename) =>
879
- inspectDesign(readFileSync(filename, "utf8"), filename),
880
- );
1464
+ const errors = files.flatMap((filename) => inspectCached(filename, options));
881
1465
  return { files, errors, ...countDesign(errors) };
882
1466
  }
883
1467
 
884
1468
  function parseArgs(args) {
885
- const options = { paths: [], baselines: [], frozen: false, init: false, list: false, only: [] };
1469
+ const options = {
1470
+ paths: [],
1471
+ baselines: [],
1472
+ frozen: false,
1473
+ init: false,
1474
+ list: false,
1475
+ only: [],
1476
+ verifyCi: false,
1477
+ };
886
1478
  for (let index = 0; index < args.length; index++) {
887
1479
  const arg = args[index];
888
1480
  if (arg === "--baseline") {
889
1481
  if (!args[index + 1]) throw new Error("--baseline needs a file.");
890
1482
  options.baselines.push(args[++index]);
891
1483
  } else if (arg === "--only") {
1484
+ if (args[index + 1] === "harvest") {
1485
+ options.only.push(...harvestRules);
1486
+ index++;
1487
+ continue;
1488
+ }
892
1489
  if (!designRules.includes(args[index + 1]))
893
- throw new Error(`--only needs one of ${designRules.join(", ")}.`);
1490
+ throw new Error(`--only needs harvest or one of ${designRules.join(", ")}.`);
894
1491
  options.only.push(args[++index]);
895
1492
  } else if (arg === "--frozen") options.frozen = true;
1493
+ else if (arg === "--verify-ci") options.verifyCi = true;
896
1494
  else if (arg === "--init") options.init = true;
897
1495
  else if (arg === "--list") options.list = true;
898
1496
  else if (arg.startsWith("--")) throw new Error(`Unknown option ${arg}.`);
@@ -926,7 +1524,7 @@ export function offenderKey(error, base) {
926
1524
 
927
1525
  function offendersOf(scan, base) {
928
1526
  const offenders = {};
929
- for (const rule of [...identityRules].sort()) {
1527
+ for (const rule of [...identityRules].filter((item) => item in scan.rules).sort()) {
930
1528
  const keys = {};
931
1529
  for (const error of scan.errors.filter((item) => ruleOf(item) === rule)) {
932
1530
  const key = offenderKey(error, base);
@@ -951,7 +1549,16 @@ function ratchet(file, options) {
951
1549
  // A baseline cut with --only ratchets just those rules (the desk packages
952
1550
  // carry LC-175 without taking on the app-only rules).
953
1551
  const only = previous ? previous.only : options.only.length ? options.only : undefined;
954
- const full = scanDesign(paths.map((input) => path.resolve(base, input)));
1552
+ // LC-203: each app registers its banned words (and LC-202 its proper
1553
+ // names) in its own baseline.
1554
+ const words = {
1555
+ bannedWords: previous?.bannedWords ?? houseBannedWords,
1556
+ properNames: previous?.properNames ?? houseProperNames,
1557
+ };
1558
+ const full = scanDesign(
1559
+ paths.map((input) => path.resolve(base, input)),
1560
+ words,
1561
+ );
955
1562
  const scan = only
956
1563
  ? (() => {
957
1564
  const errors = full.errors.filter((error) => only.includes(ruleOf(error)));
@@ -967,6 +1574,7 @@ function ratchet(file, options) {
967
1574
  const next = {
968
1575
  paths,
969
1576
  ...(only ? { only } : {}),
1577
+ ...(!only || only.includes("user-words") ? words : {}),
970
1578
  total: scan.total,
971
1579
  rules: Object.fromEntries(Object.entries(scan.rules).sort()),
972
1580
  offenders: offendersOf(scan, base),
@@ -1002,7 +1610,7 @@ function ratchet(file, options) {
1002
1610
  : ""
1003
1611
  }${
1004
1612
  added.length
1005
- ? `; 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`
1613
+ ? `; 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`
1006
1614
  : ". "
1007
1615
  }${summary(scan)}.\n`,
1008
1616
  );
@@ -1036,9 +1644,93 @@ function ratchet(file, options) {
1036
1644
  return 0;
1037
1645
  }
1038
1646
 
1647
+ // LC-192 CHECKS-TRAVEL: an MPO app's CI runs this lint frozen against every
1648
+ // design baseline it commits. CI lines are followed one level into package
1649
+ // scripts and Makefile recipes.
1650
+ export function verifyCi(root = process.cwd()) {
1651
+ const read = (file) => {
1652
+ try {
1653
+ return readFileSync(path.join(root, file), "utf8");
1654
+ } catch {
1655
+ return "";
1656
+ }
1657
+ };
1658
+ const workflows = existsSync(path.join(root, ".github/workflows"))
1659
+ ? readdirSync(path.join(root, ".github/workflows"))
1660
+ .filter((file) => /\.ya?ml$/.test(file))
1661
+ .map((file) => read(`.github/workflows/${file}`))
1662
+ : [];
1663
+ const ci = [read(".gitlab-ci.yml"), ...workflows].join("\n");
1664
+ if (!ci.trim())
1665
+ return ["no .gitlab-ci.yml or .github/workflows; CI must run mpo-design-lint --frozen."];
1666
+ let scripts = {};
1667
+ try {
1668
+ scripts = JSON.parse(read("package.json") || "{}").scripts ?? {};
1669
+ } catch {}
1670
+ const makefile = read("Makefile");
1671
+ const recipe = (target) => {
1672
+ const match = makefile.match(
1673
+ new RegExp(`^${target.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}:.*\n((?:\t.*\n?)*)`, "m"),
1674
+ );
1675
+ return match ? match[1] : "";
1676
+ };
1677
+ const expand = (line, depth = 0) => {
1678
+ if (depth > 3) return line;
1679
+ const parts = [line];
1680
+ for (const match of line.matchAll(/\b(?:pnpm|npm run|yarn)\s+(?:-s\s+|run\s+)?([\w:.-]+)/g))
1681
+ if (scripts[match[1]]) parts.push(expand(scripts[match[1]], depth + 1));
1682
+ for (const match of line.matchAll(/\bmake\s+(?:-s\s+)?([\w/.-]+)/g))
1683
+ parts.push(expand(recipe(match[1]), depth + 1));
1684
+ return parts.join("\n");
1685
+ };
1686
+ const lint = /mpo-design-lint|lint-mpo-design|design-lint\.mjs/;
1687
+ const runs = ci
1688
+ .split("\n")
1689
+ .filter((line) => !/^\s*#/.test(line))
1690
+ .map((line) => expand(line))
1691
+ .filter((text) => lint.test(text));
1692
+ if (!runs.length) return ["CI never runs mpo-design-lint (LC-192)."];
1693
+ const frozen = runs.filter((text) => /--frozen\b/.test(text));
1694
+ if (!frozen.length) return ["CI runs mpo-design-lint without --frozen (LC-192)."];
1695
+ const text = frozen.join("\n");
1696
+ return committedBaselines(root)
1697
+ .filter((file) => !text.includes(file))
1698
+ .map(
1699
+ (file) => `${file} is committed but CI never passes it to mpo-design-lint --frozen (LC-192).`,
1700
+ );
1701
+ }
1702
+
1703
+ /**
1704
+ * Every committed design baseline: `design-baseline.json`, a scoped
1705
+ * `design-baseline.<scope>.json` and a per-rule `design-<rule>-baseline.json`
1706
+ * (the phosphor ratchet), so none can drop out of the frozen CI run.
1707
+ */
1708
+ export function committedBaselines(root) {
1709
+ try {
1710
+ return execFileSync("git", ["ls-files", "-z", "--", "*design*baseline*.json"], {
1711
+ cwd: root,
1712
+ encoding: "utf8",
1713
+ stdio: ["ignore", "pipe", "ignore"],
1714
+ })
1715
+ .split("\0")
1716
+ .filter(Boolean);
1717
+ } catch {
1718
+ return [];
1719
+ }
1720
+ }
1721
+
1039
1722
  export function runDesignLint(args = process.argv.slice(2)) {
1040
1723
  try {
1041
1724
  const options = parseArgs(args);
1725
+ if (options.verifyCi) {
1726
+ const problems = verifyCi(options.paths[0] ?? process.cwd());
1727
+ if (problems.length) {
1728
+ process.stderr.write(`${problems.map((item) => `MPO design guard: ${item}`).join("\n")}\n`);
1729
+ return 1;
1730
+ }
1731
+ process.stdout.write("MPO design guard: CI runs the design lint frozen (LC-192).\n");
1732
+ return 0;
1733
+ }
1042
1734
  if (options.baselines.length)
1043
1735
  return options.baselines.reduce((status, file) => ratchet(file, options) || status, 0);
1044
1736
  const scan = scanDesign(options.paths.length ? options.paths : scopeFrom(process.cwd()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/config",
3
- "version": "7.67.0",
3
+ "version": "7.69.0",
4
4
  "description": "Shared build and test configuration presets for multiplatform.one",
5
5
  "keywords": [
6
6
  "config",
@@ -114,7 +114,7 @@
114
114
  "access": "public"
115
115
  },
116
116
  "dependencies": {
117
- "@multiplatform.one/utils": "^7.67.0",
117
+ "@multiplatform.one/utils": "^7.69.0",
118
118
  "@tamagui/vite-plugin": "2.7.6",
119
119
  "@vitejs/plugin-react": "^6.1.2",
120
120
  "dotenv": "^17.4.2",