Skip to content

chore: pre-release improvements from multi-lens review#69

Merged
AZagatti merged 3 commits into
mainfrom
chore/review-improvements
Jun 24, 2026
Merged

chore: pre-release improvements from multi-lens review#69
AZagatti merged 3 commits into
mainfrom
chore/review-improvements

Conversation

@AZagatti

Copy link
Copy Markdown
Collaborator

Pre-release hardening from a 6-persona review (domain correctness, tests/QA, packaging/DX, code quality, CI/security, performance) + a focused tsdown pass. Every finding was independently verified before inclusion — including two confident-but-wrong claims that were rejected (see bottom). Do not merge yet — for review.

Included (verified, low-risk)

Correctness / robustness

  • validatePhone(null) no longer throws — added String() coercion to match every other validator. (3 agents)
  • isRepeated rewritten to a char loop — the old new RegExp(ref[0]) threw on regex metachars (*,+,(,[,\) and treated . as a wildcard (false positives); also ~16× faster on the hot path. Behaviour identical for all real (sanitized) inputs.
  • Email TLD cap {2,10}{2,24} — accepts valid long TLDs (.photography, .international). Only loosens; no previously-valid email is now rejected.
  • Dead code removed: validateCPF's unreachable !clearValue; validatePIS's redundant onlyDigitsRegex test.
  • validateCNH: explicit : boolean return type.

Performance (behaviour-preserving)

  • CNPJ/PIS checksums: split('').reduce → index loop (no per-call array alloc).
  • validatePhone: indexOf(...) !== -1includes(...).

Packaging — fixes broken types for all TS consumers

  • types pointed at lib/index.d.ts, which tsdown never emits. Added an exports map + repointed types to lib/index.d.cts. Verified green across node10 / node16 (CJS+ESM) / bundler with @arethetypeswrong/cli ("No problems found 🌟").
  • Structured repository, added bugs, engines (node >=18), publishConfig.provenance, clearer description. tsdown: clean: true.

Tests

  • Coverage thresholds added (lock the floor; CI was green at 0% before).
  • Fixed the duplicate describe('UseValidationBr Pis') block that actually tested UF; added CNH-dispatch, non-string, and long-TLD cases. 119 tests pass; coverage 94.98% / 85.09% / 100% / 94.72%.

Docs

  • validateCEPvalidateCep (broken example), added cnh to the useValidationsBR type union, documented the alphanumeric CNPJ format, translated leftover PT headings in README.en.md.

CI

  • concurrency + timeout-minutes on ci/e2e.

Deferred (your call — not in this PR)

Listed in the review summary I'm sending you. Highlights: full tsdown exports:true auto-gen (would make all 27 IE state files public subpaths), publint/attw/isolatedDeclarations in the build, action SHA-pinning + Dependabot, GH_PATGITHUB_TOKEN, the possible double-GitHub-release config, useValidationsBR dynamic-import tree-shaking, and ~15 per-state branch-coverage tests.

Rejected (verified false)

  • "BA IE digit order reversed" — the official Sefaz-BA example 1234567-48 validates true; the current code is correct. Would have shipped a regression.
  • "biome.jsonc noSubstr comment is wrong"biome lint --only=style/noSubstr flags 49 .substring() calls; the rule does target substring, the comment is accurate.

🤖 Generated with Claude Code

Verified, low-risk improvements surfaced by a 6-persona review pass
(every finding independently confirmed before inclusion).

Correctness / robustness:
- validatePhone: coerce input with String() so non-string args return
  false instead of throwing (every other validator already does this).
- isRepeated: replace the per-call `new RegExp(ref[0])` (which throws on
  regex metacharacters and treats '.' as a wildcard) with a char loop —
  fixes the latent crash/false-positive and is ~16x faster on the hot path.
- validateEmail: raise the TLD cap from {2,10} to {2,24} so valid long
  TLDs (.photography, .international) are accepted.
- Remove dead code: validateCPF's unreachable `!clearValue`, validatePIS's
  redundant onlyDigitsRegex test.
- validateCNH: add the explicit `: boolean` return type for API consistency.

Perf (behaviour-preserving):
- validateCNPJ / validatePIS checksums: replace split('').reduce with a
  plain index loop (no per-call array allocation).
- validatePhone: indexOf(...) !== -1 -> includes(...).

Packaging (fixes broken types for TS consumers):
- Add an `exports` map and point `types` at the emitted lib/index.d.cts
  (the old `types: lib/index.d.ts` referenced a file tsdown never emits;
  verified green across node10/node16/bundler with @arethetypeswrong/cli).
- package.json: structured `repository`, add `bugs`, `engines` (node >=18),
  `publishConfig.provenance`, and a clearer/searchable `description`.
- tsdown: `clean: true`.

Tests:
- Add coverage thresholds (lock the current floor).
- Fix the duplicate `describe('UseValidationBr Pis')` that actually tested
  UF; add CNH dispatch, non-string, and long-TLD cases.

Docs:
- README/README.en: fix validateCEP -> validateCep, add `cnh` to the
  useValidationsBR type union, document the alphanumeric CNPJ format, and
  translate the leftover Portuguese headings in the English README.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coveralls

coveralls commented Jun 24, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 97.765% (+6.3%) from 91.492% — chore/review-improvements into main

AZagatti and others added 2 commits June 24, 2026 03:44
From the review triage you approved:

- #7 Branch-coverage tests: add verified-valid IEs (brute-forced and
  confirmed by the validators themselves) that exercise the previously
  untested ">= 10 -> clamp to 0" check-digit branches across RJ/RS/MT/PR/
  MG/PE/AL/GO/RO, plus 10-digit RN, 9-digit TO, and invalid prefix/length
  cases for DF/BA/TO; add CNH numbers covering the exceptional DV branches.
  Branch coverage 85% -> 92%; thresholds raised to 95/88/100/95.
- #9 tsconfig: module ESNext + moduleResolution bundler (matches the
  tsdown pipeline instead of the misleading commonjs); add
  isolatedDeclarations (faster dts via oxc, enforces explicit return types
  — added the missing one on isRepeated).
- #8 SP: replace `(sum % 11).toString().substring(...)` with `(sum%11)%10`.

Skipped/deferred (see PR discussion): full tsdown publint/attw build flags
(would hard-couple the release build to those tools), the ie calcDigit
dedup and naming nits (cosmetic), and the genuinely-unreachable branches
(AM sum<11 needs an all-zero body; utils mod11 reset is dead defensive code).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adversarial review of the PR flagged two real items (verified):
- The CNH "exceptional branch" comment over-claimed: only 64644399109
  exercises the dv>=10 / dv<0 paths. Comment corrected; kept the extra
  valid samples.
- The "unreachable" framing for AM/AP/GO/RN branches was wrong — they are
  reachable, just untested. Added verified-valid IEs that hit them:
  AM sum<11, both AP body ranges, GO special range, RN 10-digit DV clamp,
  plus the AP wrong-length guard.

Branch coverage 91.8% -> 94.2%; thresholds raised to 97/90/100/97. Only
utils.ts mod11 reset remains genuinely unreachable with current callers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@AZagatti AZagatti merged commit 25a30d3 into main Jun 24, 2026
3 checks passed
@AZagatti AZagatti deleted the chore/review-improvements branch June 24, 2026 07:00
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.

2 participants