Skip to content

fix: preserve non-Latin scripts in select-option values and detail linting - #53

Merged
luandro merged 7 commits into
mainfrom
fix/unicode-option-values-and-lint-fixes
Jul 23, 2026
Merged

luandro merged 7 commits into
mainfrom
fix/unicode-option-values-and-lint-fixes

Conversation

@luandro

@luandro luandro commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two related bugs found while working on Thai/non-Latin-script support: select-option machine values and the "unreferenced detail" linter both relied on slugify(), which is ASCII-only.

The bugs

  1. Option values collapsed for non-Latin scripts. parseOptions/parseCanonicalOptions derived a select option's stored value from slugify(label). For all-Thai / all-Vietnamese / all-Cyrillic / all-Greek option lists, every label slugified to "" (or to the same collapsed string), so distinct options collided and the linter flagged/deleted the "duplicates". Diacritics (Café) and tone marks (má vs mà) were also stripped even though they're semantically distinct in those languages.
  2. False "unreferenced detail" warnings for non-Latin field names. checkUnreferencedDetails only matched a detail against a category's Fields column via slugify(token). The builder (payloadBuilder.ts fieldNameToId) actually resolves references by exact/lowercase name first, falling back to slug — the linter didn't mirror that, so every non-Latin-named detail (e.g. Thai) was falsely reported as unreferenced.

The fix

  • Add canonicalizeOptionValue() (utils.ts): a Unicode-safe canonicalizer for option values that keeps letters/marks/numbers from any script (only strips variation selectors and orphan combining marks), unlike slugify() which stays ASCII-only for entity IDs (.comapeocat packager restricts those to ^[a-zA-Z0-9_-]+$). Falls back to the raw label when nothing usable remains (emoji-/punctuation-only options).
  • Wire it into the builder (payloadBuilder.ts), the linter (lint/shared.ts, lint/strictMetrics.ts), and import (applyFields.ts) so generation, validation, and round-trip all agree.
  • validateAndCapitalizeCommaList now capitalizes only the label half of an explicit value:label option instead of corrupting the value prefix.
  • checkManualIdHygiene's warning text now only claims "non-ASCII" when the ID actually is — the slug-safety regex also rejects plain-ASCII input (uppercase, spaces, underscores), which was getting the same misleading message.
  • checkUnreferencedDetails now matches a detail's raw/lowercase name (in addition to slug and explicit ID), mirroring the builder's actual resolution order.
  • Adds regression tests for Thai, Vietnamese, Cyrillic, Greek, and emoji-only option values.

Verification

  • bunx tsc --noEmit — clean
  • bunx biome lint . — clean
  • Manually re-derived canonicalizeOptionValue() in Node against every assertion in the new test to confirm behavior (Thai/Vietnamese/Cyrillic/Greek stay distinct, diacritics preserved, emoji-only → falls back to raw label).

Note

This branch was rebuilt from a clean main base after an earlier push accidentally landed these commits on PR #51's branch, which explicitly scoped them out. That mistake was corrected before opening this PR.

Greptile Summary

This PR preserves non-Latin select-option values and aligns lint/import behavior around the same canonical form. The main changes are:

  • Adds canonicalizeOptionValue() for Unicode-safe option machine values.
  • Uses the new option canonicalization in build, import, lint parsing, and lint metrics paths.
  • Matches unreferenced details by raw and lowercase names as well as slug/explicit ID.
  • Keeps explicit value:label option prefixes unchanged during label capitalization.
  • Adds tests for Thai, Vietnamese, Cyrillic, Greek, diacritics, and emoji-only option fallback.
  • Regenerates src/version.ts metadata for the current branch.

Confidence Score: 5/5

Safe to merge with low risk.

The changed build, import, lint, and translation paths now share the same Unicode option canonicalization and raw-label fallback behavior. Prior emoji fallback drift cases are addressed in the updated reconstruction code. No blocking correctness or security issues were found.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • Ran the Unicode preservation harness to validate Thai distinctness, Vietnamese tone distinctness, Cyrillic and Greek distinctness, diacritic preservation, emoji raw-label fallback through parseOptions, and explicit value:label capitalization preservation.
  • Verified that Typecheck exited with status 0.
  • Verified that Biome lint exited with status 0.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/utils.ts Documents ASCII-only slug behavior and adds Unicode-preserving canonicalizeOptionValue for select option machine values.
src/builders/payloadBuilder.ts Swaps select option default values to Unicode-safe canonicalization and keeps translation-source reconstruction aligned with emoji fallback.
src/importCategory/applyFields.ts Preserves explicit imported option values and writes bare labels only when stored values match canonical label fallback.
src/importCategory/parseFiles.ts Normalizes missing imported option values with Unicode-safe canonicalization instead of ASCII slug fallbacks.
src/lint/shared.ts Keeps explicit option value prefixes unchanged during label capitalization and aligns canonical option parsing/manual ID messages.
src/lint/details.ts Updates unreferenced-detail detection to match raw and lowercase detail names in addition to slug/explicit IDs.
src/lint/strictMetrics.ts Aligns lint translation option-string reconstruction with the builder’s Unicode canonicalization and raw-label fallback.
src/test/testUtilsSlugify.ts Adds regression coverage for Unicode option canonicalization across Thai, Vietnamese, Cyrillic, Greek, diacritics, and emoji fallback.
src/version.ts Regenerates version metadata for the current branch with a clean build marker.

Sequence Diagram

sequenceDiagram
participant Sheet as Spreadsheet Details/Categories
participant Builder as payloadBuilder.parseOptions
participant Canon as canonicalizeOptionValue
participant Lint as lint shared/details/metrics
participant Import as importCategory apply/parse
Sheet->>Builder: option label or value:label
Builder->>Canon: bare option label
Canon-->>Builder: Unicode value or empty
Builder-->>Builder: fallback to raw label when empty
Sheet->>Lint: fields/options/detail references
Lint->>Canon: parseCanonicalOptions and option matching
Lint-->>Sheet: warnings only when canonical/raw-name checks fail
Import->>Canon: imported option labels missing explicit value
Import-->>Sheet: bare label or explicit value:label preserving value
Loading

Reviews (4): Last reviewed commit: "test: replace tautological emoji-collisi..." | Re-trigger Greptile

luandro added 3 commits July 22, 2026 20:32
slugify() is ASCII-only, so it was reused to derive select-option
machine values from labels. All-Thai/Vietnamese/Cyrillic/Greek option
lists folded to the same empty/collapsed value, and the linter then
flagged and deleted the "duplicates". Diacritics (Café) and tone marks
(má vs mà) were also stripped even though they're semantically
distinct.

- Add canonicalizeOptionValue() (utils.ts): Unicode-safe canonicalizer
  that keeps letters/marks/numbers from any script, only drops
  variation selectors and orphan combining marks. Falls back to the
  raw label when nothing usable remains (emoji-/punctuation-only).
- Wire it into the builder (payloadBuilder.ts parseOptions,
  buildTranslationsPayload), the linter (lint/shared.ts
  parseCanonicalOptions, lint/strictMetrics.ts), and import
  (applyFields.ts) so generation, validation, and round-trip agree.
- validateAndCapitalizeCommaList (lint/shared.ts) now capitalizes only
  the label half of an explicit "value:label" option, instead of
  corrupting the value prefix.
- checkManualIdHygiene (lint/shared.ts) warning text now only claims
  "non-ASCII" when the offending ID actually is; the slug-safety regex
  also rejects plain-ASCII input (uppercase, spaces, underscores),
  which was getting the same misleading message.
- Add regression tests for Thai, Vietnamese, Cyrillic, Greek, and
  emoji-only option values.
checkUnreferencedDetails only matched a detail against a category's
Fields column via slug (slugify(token)), but slugify() is ASCII-only
and returns "" for names like Thai. Every such detail was flagged and
reported as unreferenced even when correctly referenced by name,
because the linter's matching didn't mirror the builder.

The builder (payloadBuilder fieldNameToId) actually resolves a
category's field reference by exact name or lowercase name first,
falling back to the slug. Match the detail's raw/lowercase name the
same way, in addition to slug and explicit ID.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e8105aba07

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/builders/payloadBuilder.ts Resolved
Comment thread src/builders/payloadBuilder.ts Resolved
Comment thread src/importCategory/applyFields.ts Resolved
Comment thread src/lint/strictMetrics.ts Resolved
Comment thread src/version.ts Resolved
@digidem digidem deleted a comment from qodo-code-review Bot Jul 23, 2026
luandro added 4 commits July 22, 2026 20:39
parseOptions falls back to the raw label as `value` when
canonicalizeOptionValue(label) is empty (emoji-/punctuation-only
labels, e.g. "❤️"). Three call sites that reconstruct the same
"value:label" string for matching against spreadsheet/translation
source text compared `value` against the empty canonical form
instead of that same fallback, so bare options like "❤️" were
rewritten as "❤️:❤️" and no longer exact-matched the source string —
silently dropping option translations and lint metrics.

Fixes reported by automated review (Codex, Greptile) on PR #53:
- payloadBuilder.ts buildTranslationsPayload
- lint/strictMetrics.ts buildLintTranslationsByLocale
- importCategory/applyFields.ts (import round-trip)

Also regenerates version.ts, which still pointed at the branch this
work was originally (mistakenly) committed on before being moved to
this branch.
parseExtractedFiles (the live import path from src/importCategory.ts)
fell back to createOptionValue() -> slugify() when an imported option
lacked an explicit `value`. slugify() is ASCII-only, so a third-party
or older .comapeocat with non-Latin option labels and no explicit
values would get index-based fallback values (e.g. "field-1") on
import instead of the label. Because applyFields.ts now treats any
value differing from canonicalizeOptionValue(label) as "explicit" and
preserves it verbatim as "value:label", that collapsed fallback value
would then survive every future round-trip.

Use canonicalizeOptionValue(label) || label, matching parseOptions'
own fallback, so import stays consistent with generation.

Reported by Greptile CLI review of PR #53.
The old assertTrue OR'd in canonicalizeOptionValue("hearts") === "",
which the preceding assertEqual already established as true — making
the assertion pass unconditionally regardless of its left side. It
never actually exercised cross-emoji collision behavior.

Assert what the comment claims: two different emoji-only options both
canonicalize to "", but the `canonicalizeOptionValue(x) || x` fallback
callers actually use keeps them distinct.

Found by pr-critical-reviewer during final PR readiness pass on #53.
@luandro
luandro merged commit 5e8724d into main Jul 23, 2026
3 checks passed
@luandro
luandro deleted the fix/unicode-option-values-and-lint-fixes branch July 23, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant