Skip to content

fix(theme): [ENG-46996] harden the zero-with-unit token gate - #850

Merged
isaque-bock-azion merged 4 commits into
mainfrom
fix/ENG-46996-harden-zero-unit-lint
Aug 4, 2026
Merged

fix(theme): [ENG-46996] harden the zero-with-unit token gate#850
isaque-bock-azion merged 4 commits into
mainfrom
fix/ENG-46996-harden-zero-unit-lint

Conversation

@isaque-bock-azion

Copy link
Copy Markdown
Contributor

Summary

Hardens the zero-with-unit discipline that guards the compiled token stylesheet (packages/theme) and its mirror in the shared webkit token-checks engine. Addresses ENG-46996.

  • Complete unit list — adds the CSS length units a partial list dropped: logical viewport (vi/vb), their small/large/dynamic + min/max variants (svi/svb/svmin/svmax/lvi/lvb/lvmin/lvmax/dvi/dvb/dvmin/dvmax), and the root-relative font units (rex/rch/ric/rcap). 0vi no longer slips through.
  • Case-insensitive — already in place (i/gi flag); now pinned by tests (0PX, 0Rem, 0VI, 0SvB).
  • No longer one-declaration-per-line — the assert scans the generated stylesheet as a whole string instead of split('\n'), so a calc()/min()/max()/clamp() wrapped across lines is judged in context (the math-function lookbehind spans the newline) rather than misread as a bare zero. No PostCSS — the theme's node-built-ins-only constraint is preserved.
  • Honest error path — the reported filename is a parameter now, not a hardcoded globals.css.
  • Actionable error — the message names the offending custom property so the source token is greppable under src/tokens/**.
  • Testable — the pure logic moved to packages/theme/src/scripts/zero-unit.mjs (no side effects) so it is unit-testable without running the build. build-tokens.mjs imports assertNoZeroWithUnit. A theme test script runs the suite.
  • Kept in sync — the shared webkit token-checks.js engine gets the identical completed unit list (both zero regexes now carry the same string); both copies are pinned by tests.

Notes

  • Implementation note preserved: the module regexes stay non-global so .test() is stateless; findZeroMisuse clones with the g flag locally to enumerate matches.
  • Item "avaliar checar a fonte": the error names the offending token (greppable in src/tokens/**); full provenance to the exact source file was evaluated and deferred as disproportionate to the single-pass, dependency-free build.
  • CI wiring deferred: a theme-tests job for governance.yml was prepared but left out of this PR (the push token lacks the workflow scope). Until it lands, the theme suite runs via pnpm --filter @aziontech/theme test; the webkit copy is already gated by the existing toolkit job. To be added in a follow-up with a workflow-scoped push.
  • Verified: theme suite 12/12, webkit token-checks 9/9, build:tokens end-to-end clean; the widened list catches no existing component source. Release effect: fix → patch.
  • Touches the same regexes as ENG-47001 (canonical-syntax work, not yet merged) — expect a rebase once that lands.

@isaque-bock-azion

Copy link
Copy Markdown
Contributor Author

Revisei e enxuguei os comentários dos arquivos deste PR em packages/theme (src/scripts/zero-unit.mjs e test/zero-unit.test.mjs) — mais curtos e diretos, sem mudar lógica nem cobertura (theme 12/12, build:tokens limpo).

Escopei a revisão aos arquivos que este PR adiciona/altera no theme, para não misturar um sweep de comentários do pacote inteiro (ex.: o cabeçalho e as seções pré-existentes do build-tokens.mjs, que não fazem parte desta mudança) e evitar diff não-relacionado. Se quiser, faço uma passada separada nos comentários do resto do packages/theme num PR próprio.

@CLAassistant

CLAassistant commented Aug 4, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Complete the CSS length-unit list (vi/vb, the small/large/dynamic
viewport + min/max variants, and rex/rch/ric/rcap — so 0vi no longer
slips through), scan the generated stylesheet as a whole string so a
calc()/min()/max()/clamp() wrapped across lines is judged in context
instead of read as a bare zero, parametrize the reported filename
(no hardcoded globals.css), and name the offending custom property in
the error so the source token is greppable.

Extract the pure logic to zero-unit.mjs so it is unit-testable without
running the build; the module regexes stay non-global so .test() is
stateless (findZeroMisuse clones with the g flag locally). A theme
`test` script runs the suite (node --test).

Mirror the completed unit list in the shared webkit token-checks engine
(both zero regexes now carry the identical list) and pin both copies
with tests.
@isaque-bock-azion
isaque-bock-azion force-pushed the fix/ENG-46996-harden-zero-unit-lint branch from 9e05d51 to a47dc84 Compare August 4, 2026 14:13
@isaque-bock-azion
isaque-bock-azion merged commit a0a63c8 into main Aug 4, 2026
23 checks passed
@isaque-bock-azion
isaque-bock-azion deleted the fix/ENG-46996-harden-zero-unit-lint branch August 4, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants