@multiplatform.one/config 8.2.0 → 8.2.2
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 +3 -2
- package/design-lint.mjs +319 -22
- package/lint.mjs +2 -2
- package/package.json +2 -2
- package/spec-registry.mjs +2 -2
package/README.md
CHANGED
|
@@ -167,13 +167,14 @@ MPO app gets them (LC-192):
|
|
|
167
167
|
|
|
168
168
|
- UI copy (JSX text, copy attributes and keys such as `label`, `title` and
|
|
169
169
|
`placeholder`, `t()` keys and `defaultValue`, and every value in a string
|
|
170
|
-
catalog under `i18n/`, `locales/` or `localizations/`, JSON included)
|
|
170
|
+
catalog under `i18n/`, `locales/` or `localizations/`, JSON included) gives
|
|
171
|
+
labels and titles title-style capitals (`copy-title-style`), keeps running text in
|
|
171
172
|
sentence case (`copy-title-case`), never hedges a plural with "(s)"
|
|
172
173
|
(`copy-plural`) and carries no em dash except the lone placeholder "—"
|
|
173
174
|
(`copy-em-dash`, all LC-202).
|
|
174
175
|
- `user-words` (LC-203) rejects implementation words in UI copy. The house list
|
|
175
176
|
is `houseBannedWords`; a baseline's `bannedWords` replaces it for that app,
|
|
176
|
-
and its `properNames` lists the names
|
|
177
|
+
and its `properNames` lists the names the capitals rules leave alone.
|
|
177
178
|
- `error-copy` (LC-204) rejects error copy (a key or catalog path naming an
|
|
178
179
|
error or failure) that leads with a number, a code or an identifier.
|
|
179
180
|
- `refresh-label` (LC-216) and `zoom-button` (LC-217) reject a standing
|
package/design-lint.mjs
CHANGED
|
@@ -173,6 +173,7 @@ export const harvestRules = [
|
|
|
173
173
|
"copy-em-dash",
|
|
174
174
|
"copy-plural",
|
|
175
175
|
"copy-title-case",
|
|
176
|
+
"copy-title-style",
|
|
176
177
|
"action-word",
|
|
177
178
|
"error-copy",
|
|
178
179
|
"link-chrome",
|
|
@@ -257,6 +258,34 @@ function titleCaseEscapeReason(text) {
|
|
|
257
258
|
const copyAttribute =
|
|
258
259
|
/^(?: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)$/;
|
|
259
260
|
const errorKey = /(?:^error|Error|^fail|Fail|Failure)\w*$/;
|
|
261
|
+
// LC-202 kinds. Text inside a button, link, menu row, tab, trigger, label,
|
|
262
|
+
// heading or title (or an element whose role or text recipe says so) is a
|
|
263
|
+
// label; text in a paragraph, description, hint, caption, error, toast,
|
|
264
|
+
// tooltip, alert banner or empty state is running text, titles included.
|
|
265
|
+
// Text, View and the like pass the question to their parent; the label and
|
|
266
|
+
// body text recipes are type sizes, not kinds, so they pass it on too.
|
|
267
|
+
const labelTag =
|
|
268
|
+
/^(?:a|button|summary|label|legend|th|option|optgroup|h[1-6]|H[1-6])$|(?:Button|Link|Anchor|Label|Title|Heading|Tab|Trigger|MenuItem|ItemText|ItemTitle)$|(?:Menu|Select|Dropdown|Command|Tabs)\w*\.Item$/;
|
|
269
|
+
const textTag =
|
|
270
|
+
/^(?:p|blockquote|figcaption|small|Paragraph)$|(?:Description|Hint|Helper|HelperText|Caption|Subtitle|Message)$|(?:^|\.)(?:Alert|Banner|Callout|Notice)(?:$|\.)|Toast|Tooltip|Empty|Error/;
|
|
271
|
+
const labelRole =
|
|
272
|
+
/^(?:button|link|tab|menuitem|menuitemcheckbox|menuitemradio|option|heading|header|columnheader|rowheader|treeitem)$/;
|
|
273
|
+
// The ruling names no case for a checkbox, radio or switch label, and Apple
|
|
274
|
+
// differs by platform (sentence style on macOS, title style in iOS Settings
|
|
275
|
+
// rows), so those stay undecided.
|
|
276
|
+
const choiceTag = /(?:Checkbox|Switch|Radio\w*)$/;
|
|
277
|
+
const textRole = /^(?:alert|status|tooltip|note|log)$/;
|
|
278
|
+
const labelSpread = /^(?:heading|pageTitle|menuRow|controlType|tabType)$/;
|
|
279
|
+
const textSpread = /^(?:caption|helper|hint)$/;
|
|
280
|
+
// A title or label beside running text in a plain object could head a
|
|
281
|
+
// dialog, a banner, a toast or an empty state, so syntax can't tell.
|
|
282
|
+
const runningSibling = /^(?:description|body|message|detail|details|subtitle|hint|caption|blurb)$/;
|
|
283
|
+
const labelKey =
|
|
284
|
+
/^(?:label|title|heading|confirmLabel|confirmText|cancelLabel|cancelText|actionLabel)$/;
|
|
285
|
+
// An accessibility label, or the label of an icon-only control, is heard,
|
|
286
|
+
// not seen, unless it doubles as the control's tooltip (LC-260), so syntax
|
|
287
|
+
// can't tell which case it takes.
|
|
288
|
+
const spokenKey = /^(?:aria-label|accessibilityLabel)$/;
|
|
260
289
|
const pluralHedge = /[a-z]{2,}\(s\)(?=[\s"'`?.,;:!)]|$)/;
|
|
261
290
|
const errorLead =
|
|
262
291
|
/^(?:\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)/;
|
|
@@ -307,24 +336,111 @@ const clip = (text) => {
|
|
|
307
336
|
const flat = text.replace(/\s+/g, " ").replaceAll(";", ",").trim();
|
|
308
337
|
return flat.length > 60 ? `${flat.slice(0, 57)}...` : flat;
|
|
309
338
|
};
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
339
|
+
// LC-202 capitals (rv_3ac9ab73af109ed0): a control label or a title takes
|
|
340
|
+
// title-style capitals, running text is sentence case. The small words are
|
|
341
|
+
// the Apple Style Guide's: articles, coordinating conjunctions and
|
|
342
|
+
// prepositions of four letters or fewer stay lowercase inside a title.
|
|
343
|
+
export const titleSmallWords = [
|
|
344
|
+
"a",
|
|
345
|
+
"an",
|
|
346
|
+
"and",
|
|
347
|
+
"as",
|
|
348
|
+
"at",
|
|
349
|
+
"but",
|
|
350
|
+
"by",
|
|
351
|
+
"for",
|
|
352
|
+
"from",
|
|
353
|
+
"in",
|
|
354
|
+
"into",
|
|
355
|
+
"nor",
|
|
356
|
+
"of",
|
|
357
|
+
"off",
|
|
358
|
+
"on",
|
|
359
|
+
"onto",
|
|
360
|
+
"or",
|
|
361
|
+
"out",
|
|
362
|
+
"over",
|
|
363
|
+
"per",
|
|
364
|
+
"so",
|
|
365
|
+
"the",
|
|
366
|
+
"to",
|
|
367
|
+
"up",
|
|
368
|
+
"via",
|
|
369
|
+
"with",
|
|
370
|
+
"yet",
|
|
371
|
+
];
|
|
372
|
+
// A preposition that belongs to a phrasal verb takes a capital ("Sign In",
|
|
373
|
+
// "Log Out"). Syntax can't tell the two apart, so these may be either case.
|
|
374
|
+
export const titleParticles = ["by", "in", "off", "on", "out", "over", "up"];
|
|
375
|
+
const smallWord = new Set(titleSmallWords);
|
|
376
|
+
const particle = new Set(titleParticles);
|
|
377
|
+
// The words the capitals rules judge, or undefined when the string is code
|
|
378
|
+
// or has fewer than two real words (one word reads the same in both styles).
|
|
379
|
+
// Interpolations, proper names, numbers, dotted names and words that start
|
|
380
|
+
// with a digit or a lowercase brand ("iPhone") are neutral: they hold their
|
|
381
|
+
// place in the string but take no capitals rule. A string that opens with
|
|
382
|
+
// "e.g." quotes the user's own data and is not judged.
|
|
383
|
+
export function caseWords(text, names = houseProperNames) {
|
|
384
|
+
if (/^(?:e\.g\.|i\.e\.)/i.test(text.trim())) return undefined;
|
|
385
|
+
let value = text.replace(/\{\{[^}]*\}\}|\{[^{}]*\}/g, " {x} ");
|
|
386
|
+
for (const proper of names) value = value.replaceAll(proper, " {x} ");
|
|
387
|
+
if (/[/=<>$_@#\\|{}[\]]/.test(value.replaceAll("{x}", ""))) return undefined;
|
|
388
|
+
const words = value.split(/\s+/).flatMap((raw) => {
|
|
389
|
+
if (raw === "{x}") return [{ neutral: true }];
|
|
390
|
+
const word = raw.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}']+$/gu, "");
|
|
391
|
+
if (!/\p{L}/u.test(word)) return /\p{N}/u.test(word) ? [{ neutral: true }] : [];
|
|
392
|
+
if (!/^[\p{Lu}\p{Ll}]/u.test(word) || /^\p{Ll}+\p{Lu}|[.(]/u.test(word))
|
|
393
|
+
return [{ neutral: true }];
|
|
394
|
+
const lower = word.toLowerCase();
|
|
395
|
+
return [
|
|
396
|
+
{
|
|
397
|
+
word,
|
|
398
|
+
upper: /^\p{Lu}/u.test(word),
|
|
399
|
+
plain: /^\p{Lu}\p{Ll}[\p{Ll}']*$/u.test(word),
|
|
400
|
+
small: smallWord.has(lower),
|
|
401
|
+
particle: particle.has(lower),
|
|
402
|
+
},
|
|
403
|
+
];
|
|
404
|
+
});
|
|
405
|
+
return words.filter((item) => !item.neutral).length < 2 ? undefined : words;
|
|
406
|
+
}
|
|
407
|
+
// A label written as a full sentence keeps sentence capitals (Apple), so the
|
|
408
|
+
// label rule leaves one that ends in a stop, holds a sentence break or runs
|
|
409
|
+
// past eight words.
|
|
410
|
+
export function sentenceLike(text) {
|
|
411
|
+
const value = text.trim().replace(/(?:\.\.\.|…)$/, "");
|
|
412
|
+
return /[.!?](?:\s|$)/u.test(value) || value.split(/\s+/).length > 8;
|
|
413
|
+
}
|
|
414
|
+
// Title style: the first and last word capitalised, every other word too
|
|
415
|
+
// except a small word, which stays lowercase (a particle may be either).
|
|
416
|
+
// A neutral first or last token ("Step {x} of {x}") frees that end.
|
|
417
|
+
export function isTitleStyle(words) {
|
|
418
|
+
return words.every((item, index) => {
|
|
419
|
+
if (item.neutral) return true;
|
|
420
|
+
if (index === 0 || index === words.length - 1) return item.upper;
|
|
421
|
+
if (item.small) return !item.upper || item.particle;
|
|
422
|
+
return item.upper;
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
// Title Case where sentence case belongs: a capitalised first word, a later
|
|
426
|
+
// plain capitalised word, and no later lowercase word but a small word title
|
|
427
|
+
// style keeps lowercase. "Sign in with Google" keeps its particle lowercase,
|
|
428
|
+
// so it reads as a sentence.
|
|
429
|
+
export function readsAsTitleCase(words) {
|
|
430
|
+
const [first, ...rest] = words.filter((item) => !item.neutral);
|
|
431
|
+
const last = words.at(-1);
|
|
322
432
|
return (
|
|
323
|
-
|
|
433
|
+
first.upper &&
|
|
434
|
+
(last.neutral || last.upper) &&
|
|
435
|
+
rest.some((item) => item.plain) &&
|
|
436
|
+
!rest.some((item) => !item.upper && (!item.small || item.particle))
|
|
324
437
|
);
|
|
325
438
|
}
|
|
326
439
|
// The copy rules (LC-202, 203, 204, 216, 217) over one UI string.
|
|
327
|
-
export function copyFindings(
|
|
440
|
+
export function copyFindings(
|
|
441
|
+
text,
|
|
442
|
+
{ error = false, kind, joined = {}, bannedWords, properNames } = {},
|
|
443
|
+
) {
|
|
328
444
|
const value = text
|
|
329
445
|
.replace(/\{\{[^}]*\}\}|\{[^{}]*\}/g, "{x}")
|
|
330
446
|
.replace(/\s+/g, " ")
|
|
@@ -343,8 +459,21 @@ export function copyFindings(text, { error = false, bannedWords, properNames } =
|
|
|
343
459
|
"copy-plural",
|
|
344
460
|
`${quoted} hedges a plural; count through t()'s plural form (LC-202).`,
|
|
345
461
|
]);
|
|
346
|
-
|
|
347
|
-
|
|
462
|
+
const words = caseWords(
|
|
463
|
+
`${joined.before ? "{x} " : ""}${value}${joined.after ? " {x}" : ""}`,
|
|
464
|
+
properNames ?? houseProperNames,
|
|
465
|
+
);
|
|
466
|
+
const role = kind ?? (error ? "text" : undefined);
|
|
467
|
+
if (words && role === "label" && !sentenceLike(value) && !isTitleStyle(words))
|
|
468
|
+
found.push([
|
|
469
|
+
"copy-title-style",
|
|
470
|
+
`${quoted} needs title-style capitals; it labels a control or titles a surface (LC-202).`,
|
|
471
|
+
]);
|
|
472
|
+
if (words && role === "text" && readsAsTitleCase(words))
|
|
473
|
+
found.push([
|
|
474
|
+
"copy-title-case",
|
|
475
|
+
`${quoted} is Title Case; running text is sentence case (LC-202).`,
|
|
476
|
+
]);
|
|
348
477
|
const word = value.match(bannedPattern(bannedWords ?? houseBannedWords) ?? /$^/)?.[0];
|
|
349
478
|
if (word)
|
|
350
479
|
found.push([
|
|
@@ -365,6 +494,11 @@ export function copyFindings(text, { error = false, bannedWords, properNames } =
|
|
|
365
494
|
found.push(["zoom-button", `${quoted} is a zoom button; zoom is a gesture (LC-217).`]);
|
|
366
495
|
return found;
|
|
367
496
|
}
|
|
497
|
+
// LC-202's capitals are English rules: a catalog under another locale is a
|
|
498
|
+
// translation and keeps its language's own capitals.
|
|
499
|
+
const catalogLocale =
|
|
500
|
+
/(?:i18n|locales|localizations)[\\/](?:.*[\\/])?([a-z]{2})(?:[-_][A-Za-z]{2,4})?(?:[\\/]|\.(?:json|[cm]?[jt]s)$)/;
|
|
501
|
+
const translation = (filename) => (catalogLocale.exec(filename)?.[1] ?? "en") !== "en";
|
|
368
502
|
// A string catalog: a file in an i18n, locales or localizations directory,
|
|
369
503
|
// directly or under a locale code.
|
|
370
504
|
const catalogFile =
|
|
@@ -375,6 +509,35 @@ function lineOf(source, index) {
|
|
|
375
509
|
line++;
|
|
376
510
|
return line;
|
|
377
511
|
}
|
|
512
|
+
// LC-202: a catalog value's kind is its key's. A key that names a heading,
|
|
513
|
+
// title, label, button or call to action is a label; one that names an empty
|
|
514
|
+
// state ("noTags", "emptyTitle"), an error or running text (description,
|
|
515
|
+
// hint, placeholder, tooltip, toast, message) is text. Any other key leaves
|
|
516
|
+
// the kind undecided, and the capitals rules say nothing.
|
|
517
|
+
export function catalogKind(keys) {
|
|
518
|
+
const key = [...keys].reverse().find((item) => !/^\d+$/.test(item));
|
|
519
|
+
if (!key || /\s/.test(key)) return undefined;
|
|
520
|
+
const words = key
|
|
521
|
+
.replace(/([\p{Ll}\d])(\p{Lu})/gu, "$1 $2")
|
|
522
|
+
.toLowerCase()
|
|
523
|
+
.split(/[^a-z0-9]+/)
|
|
524
|
+
.filter(Boolean);
|
|
525
|
+
const last = words.at(-1);
|
|
526
|
+
const failure = (item) =>
|
|
527
|
+
errorKey.test(item) ||
|
|
528
|
+
/^no[A-Z]/.test(item) ||
|
|
529
|
+
(/empty|notFound|unavailable|failed|failure/i.test(item) && !/^(?:is|has)[A-Z]/.test(item));
|
|
530
|
+
if (keys.some(failure) || /^(?:errors?|fail(?:ed|ure)?)$/.test(last)) return "text";
|
|
531
|
+
if (words.some((word) => word === "button" || word === "cta")) return "label";
|
|
532
|
+
if (/^(?:title|heading|label|h[1-6]|tab|action)$/.test(last)) return "label";
|
|
533
|
+
if (
|
|
534
|
+
/^(?:description|desc|p|body|hint|helper|placeholder|tooltip|toast|message|caption|subtitle|note|paragraph)$/.test(
|
|
535
|
+
last,
|
|
536
|
+
)
|
|
537
|
+
)
|
|
538
|
+
return "text";
|
|
539
|
+
return undefined;
|
|
540
|
+
}
|
|
378
541
|
// A JSON string catalog: every leaf is UI copy, and a key path naming an
|
|
379
542
|
// error or failure makes it error copy.
|
|
380
543
|
function inspectCatalog(source, filename, options) {
|
|
@@ -390,10 +553,12 @@ function inspectCatalog(source, filename, options) {
|
|
|
390
553
|
if (typeof value === "string") {
|
|
391
554
|
const at = source.indexOf(JSON.stringify(value), cursor);
|
|
392
555
|
if (at !== -1) cursor = at;
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
556
|
+
const error = keys.some((key) => errorKey.test(key));
|
|
557
|
+
const kind = translation(filename)
|
|
558
|
+
? "translation"
|
|
559
|
+
: (catalogKind(keys) ?? (error ? "text" : undefined));
|
|
560
|
+
options.onCopy?.({ filename, line: lineOf(source, cursor), text: value, kind });
|
|
561
|
+
for (const [rule, message] of copyFindings(value, { ...options, error, kind }))
|
|
397
562
|
errors.push(`${filename}:${lineOf(source, cursor)}:1: [${rule}] ${message}`);
|
|
398
563
|
} else if (value && typeof value === "object")
|
|
399
564
|
for (const [key, inner] of Object.entries(value)) walk(inner, [...keys, key]);
|
|
@@ -780,6 +945,109 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
|
|
|
780
945
|
if (tCall(parent) && parent.arguments[0] === child && /\s/.test(node.getText(file))) return {};
|
|
781
946
|
return undefined;
|
|
782
947
|
}
|
|
948
|
+
// LC-202 capitals: a copy string's kind comes from where it sits. "label"
|
|
949
|
+
// names a control or titles a surface, "text" is running text, "data" is
|
|
950
|
+
// a Frappe DocField's own label, and undefined means syntax can't tell.
|
|
951
|
+
function tagKind(element) {
|
|
952
|
+
for (const attr of element.attributes.properties) {
|
|
953
|
+
if (
|
|
954
|
+
ts.isJsxAttribute(attr) &&
|
|
955
|
+
/^(?:role|accessibilityRole)$/.test(name(attr.name)) &&
|
|
956
|
+
attr.initializer &&
|
|
957
|
+
ts.isStringLiteral(attr.initializer)
|
|
958
|
+
) {
|
|
959
|
+
if (labelRole.test(attr.initializer.text)) return "label";
|
|
960
|
+
if (textRole.test(attr.initializer.text)) return "text";
|
|
961
|
+
}
|
|
962
|
+
if (ts.isJsxSpreadAttribute(attr) && ts.isPropertyAccessExpression(attr.expression)) {
|
|
963
|
+
if (labelSpread.test(attr.expression.name.text)) return "label";
|
|
964
|
+
if (textSpread.test(attr.expression.name.text)) return "text";
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
const tag = tagText(element.tagName);
|
|
968
|
+
if (textTag.test(tag)) return "text";
|
|
969
|
+
if (labelTag.test(tag)) return "label";
|
|
970
|
+
return undefined;
|
|
971
|
+
}
|
|
972
|
+
function attributeKind(key, element) {
|
|
973
|
+
if (errorKey.test(key)) return "text";
|
|
974
|
+
if (spokenKey.test(key)) return undefined;
|
|
975
|
+
const host = element && ts.isJsxOpeningElement(element) ? element.parent : element;
|
|
976
|
+
if (key === "label" && host && iconOnly(host)) return undefined;
|
|
977
|
+
const tag = element ? tagText(element.tagName) : "";
|
|
978
|
+
if (labelKey.test(key) && choiceTag.test(tag)) return undefined;
|
|
979
|
+
if (labelKey.test(key) && element && tagKind(element) === "text") return "text";
|
|
980
|
+
if (key === "title" && /^[a-z][\w-]*$/.test(tag)) return "text";
|
|
981
|
+
if (labelKey.test(key)) return "label";
|
|
982
|
+
return copyAttribute.test(key) ? "text" : undefined;
|
|
983
|
+
}
|
|
984
|
+
function elementKind(start) {
|
|
985
|
+
for (let node = start; node; node = node.parent) {
|
|
986
|
+
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
987
|
+
const kind = tagKind(opening(node));
|
|
988
|
+
if (kind) return kind;
|
|
989
|
+
} else if (ts.isJsxAttribute(node)) return attributeKind(name(node.name), node.parent.parent);
|
|
990
|
+
else if (
|
|
991
|
+
!ts.isJsxFragment(node) &&
|
|
992
|
+
!ts.isJsxExpression(node) &&
|
|
993
|
+
!ts.isParenthesizedExpression(node) &&
|
|
994
|
+
!ts.isConditionalExpression(node) &&
|
|
995
|
+
!ts.isBinaryExpression(node)
|
|
996
|
+
)
|
|
997
|
+
return undefined;
|
|
998
|
+
}
|
|
999
|
+
return undefined;
|
|
1000
|
+
}
|
|
1001
|
+
function copyKind(node) {
|
|
1002
|
+
if (ts.isJsxText(node)) return elementKind(node.parent);
|
|
1003
|
+
for (let child = node, parent = node.parent; parent; child = parent, parent = parent.parent) {
|
|
1004
|
+
if (
|
|
1005
|
+
ts.isParenthesizedExpression(parent) ||
|
|
1006
|
+
ts.isAsExpression(parent) ||
|
|
1007
|
+
ts.isSatisfiesExpression(parent) ||
|
|
1008
|
+
(ts.isConditionalExpression(parent) && parent.condition !== child) ||
|
|
1009
|
+
(ts.isBinaryExpression(parent) &&
|
|
1010
|
+
(parent.operatorToken.kind === ts.SyntaxKind.PlusToken ||
|
|
1011
|
+
parent.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken ||
|
|
1012
|
+
parent.operatorToken.kind === ts.SyntaxKind.BarBarToken ||
|
|
1013
|
+
(parent.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken &&
|
|
1014
|
+
parent.right === child))) ||
|
|
1015
|
+
(ts.isArrowFunction(parent) && parent.body === child) ||
|
|
1016
|
+
(tCall(parent) && parent.arguments[0] === child)
|
|
1017
|
+
)
|
|
1018
|
+
continue;
|
|
1019
|
+
if (ts.isJsxExpression(parent)) {
|
|
1020
|
+
if (ts.isJsxElement(parent.parent) || ts.isJsxFragment(parent.parent))
|
|
1021
|
+
return elementKind(parent.parent);
|
|
1022
|
+
continue;
|
|
1023
|
+
}
|
|
1024
|
+
if (ts.isJsxAttribute(parent)) return attributeKind(name(parent.name), parent.parent.parent);
|
|
1025
|
+
if (!ts.isPropertyAssignment(parent) || parent.initializer !== child) return undefined;
|
|
1026
|
+
const key = name(parent.name);
|
|
1027
|
+
const host = parent.parent.parent;
|
|
1028
|
+
if (key === "defaultValue" && tCall(host)) {
|
|
1029
|
+
parent = host;
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
if (catalog)
|
|
1033
|
+
return translation(filename) ? "translation" : catalogKind(keyPath(parent).reverse());
|
|
1034
|
+
if (
|
|
1035
|
+
parent.parent.properties.some(
|
|
1036
|
+
(prop) => prop.name && /^(?:fieldname|fieldtype)$/.test(name(prop.name)),
|
|
1037
|
+
)
|
|
1038
|
+
)
|
|
1039
|
+
return "data";
|
|
1040
|
+
if (ts.isCallExpression(host) && /toast|notif|snack/i.test(host.expression.getText(file)))
|
|
1041
|
+
return "text";
|
|
1042
|
+
if (
|
|
1043
|
+
/^(?:label|title|heading)$/.test(key) &&
|
|
1044
|
+
parent.parent.properties.some((prop) => prop.name && runningSibling.test(name(prop.name)))
|
|
1045
|
+
)
|
|
1046
|
+
return undefined;
|
|
1047
|
+
return attributeKind(key);
|
|
1048
|
+
}
|
|
1049
|
+
return undefined;
|
|
1050
|
+
}
|
|
783
1051
|
function stringText(node) {
|
|
784
1052
|
if (ts.isJsxText(node))
|
|
785
1053
|
return node.text
|
|
@@ -790,6 +1058,21 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
|
|
|
790
1058
|
return [node.head.text, ...node.templateSpans.map((span) => span.literal.text)].join("{x}");
|
|
791
1059
|
return node.text;
|
|
792
1060
|
}
|
|
1061
|
+
// LC-202 capitals: JSX text beside an expression or element is one part of
|
|
1062
|
+
// a longer string ("Continue with {provider}"), so its open ends are not
|
|
1063
|
+
// the string's first or last word.
|
|
1064
|
+
function textJoins(node) {
|
|
1065
|
+
if (!ts.isJsxText(node)) return {};
|
|
1066
|
+
const siblings = node.parent.children ?? [];
|
|
1067
|
+
const at = siblings.indexOf(node);
|
|
1068
|
+
const content = (item) =>
|
|
1069
|
+
!(ts.isJsxText(item) && item.text.trim() === "") &&
|
|
1070
|
+
!(ts.isJsxExpression(item) && !item.expression);
|
|
1071
|
+
return {
|
|
1072
|
+
before: siblings.slice(0, at).some(content),
|
|
1073
|
+
after: siblings.slice(at + 1).some(content),
|
|
1074
|
+
};
|
|
1075
|
+
}
|
|
793
1076
|
function checkCopy(node) {
|
|
794
1077
|
const context = ts.isJsxText(node) ? {} : copyContext(node);
|
|
795
1078
|
const text = stringText(node);
|
|
@@ -804,7 +1087,19 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
|
|
|
804
1087
|
);
|
|
805
1088
|
}
|
|
806
1089
|
if (!context) return;
|
|
807
|
-
|
|
1090
|
+
const kind = copyKind(node);
|
|
1091
|
+
const joined = textJoins(node);
|
|
1092
|
+
if (options.onCopy) {
|
|
1093
|
+
const { line } = file.getLineAndCharacterOfPosition(node.getStart(file));
|
|
1094
|
+
options.onCopy({
|
|
1095
|
+
filename,
|
|
1096
|
+
line: line + 1,
|
|
1097
|
+
text,
|
|
1098
|
+
joined,
|
|
1099
|
+
kind: kind ?? (context.error ? "text" : undefined),
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
for (const [rule, message] of copyFindings(text, { ...options, ...context, kind, joined }))
|
|
808
1103
|
report(node, rule, message);
|
|
809
1104
|
}
|
|
810
1105
|
function literalTypes(type) {
|
|
@@ -1334,7 +1629,9 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
|
|
|
1334
1629
|
visit(file);
|
|
1335
1630
|
checkMpoRoles();
|
|
1336
1631
|
return findTitleCaseEscapes(source).some((site) => site.reason)
|
|
1337
|
-
? errors.filter(
|
|
1632
|
+
? errors.filter(
|
|
1633
|
+
(error) => !error.includes("[copy-title-case]") && !error.includes("[copy-title-style]"),
|
|
1634
|
+
)
|
|
1338
1635
|
: errors;
|
|
1339
1636
|
|
|
1340
1637
|
function paintsSurface(node, seen = new Set()) {
|
package/lint.mjs
CHANGED
|
@@ -940,7 +940,7 @@ function checkUndeclaredHexEscapes() {
|
|
|
940
940
|
|
|
941
941
|
/**
|
|
942
942
|
* LC-202: a file of proper-noun data opts out of the design lint's
|
|
943
|
-
*
|
|
943
|
+
* capitals rules with a `copy-title-case-escape: <reason>` comment.
|
|
944
944
|
* Every one must be a row in the spec's `## Title-case escapes` table by file
|
|
945
945
|
* and exact reason, and a row whose comment is gone fails too.
|
|
946
946
|
*/
|
|
@@ -2832,7 +2832,7 @@ export function runConventionChecks(options = {}) {
|
|
|
2832
2832
|
if (undeclaredTitleCaseEscapes.length) {
|
|
2833
2833
|
failed = true;
|
|
2834
2834
|
console.error(
|
|
2835
|
-
"Convention (LC-202 TITLE-CASE ESCAPE REGISTRY): a `copy-title-case-escape: <reason>` comment exempts its file from the design lint's copy-title-case
|
|
2835
|
+
"Convention (LC-202 TITLE-CASE ESCAPE REGISTRY): a `copy-title-case-escape: <reason>` comment exempts its file from the design lint's capitals rules (copy-title-case and copy-title-style), so every one must be a row in docs/theme-propagation-spec.md `## Title-case escapes`, by file and by the exact reason the comment writes. It is for proper-noun data, never for UI copy. A row whose comment is gone fails too.\n",
|
|
2836
2836
|
);
|
|
2837
2837
|
for (const msg of undeclaredTitleCaseEscapes) console.error(` ${msg}`);
|
|
2838
2838
|
console.error("");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/config",
|
|
3
|
-
"version": "8.2.
|
|
3
|
+
"version": "8.2.2",
|
|
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": "^8.2.
|
|
125
|
+
"@multiplatform.one/utils": "^8.2.2",
|
|
126
126
|
"@tamagui/vite-plugin": "2.7.6",
|
|
127
127
|
"@vitejs/plugin-react": "^6.1.2",
|
|
128
128
|
"dotenv": "^17.4.2",
|
package/spec-registry.mjs
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* no-hex-literals; same verbatim reason (MPO-326).
|
|
19
19
|
* ## Title-case escapes `| File | Reason |`, one row per file whose
|
|
20
20
|
* `copy-title-case-escape:` comment exempts its
|
|
21
|
-
* proper-noun data from
|
|
21
|
+
* proper-noun data from the capitals rules (LC-202).
|
|
22
22
|
*
|
|
23
23
|
* A consumer tree with no spec, or a spec without the section, yields
|
|
24
24
|
* `present: false` rather than throwing, so shc can pick the rules up before
|
|
@@ -166,7 +166,7 @@ export function readHexEscapeRegistry(specPath = defaultSpecPath()) {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
|
-
* Files exempt from the design lint's
|
|
169
|
+
* Files exempt from the design lint's capitals rules: one
|
|
170
170
|
* `{ file, reason }` per row, matched verbatim against the file's
|
|
171
171
|
* `copy-title-case-escape:` comment. These hold proper-noun data (names a
|
|
172
172
|
* picker lists), not UI copy.
|