docs: add forms and validation conventions guide - #448
Open
playmaker410 wants to merge 3 commits into
Open
Conversation
- Add docs/forms.md: validator signatures, error-message conventions, TextField ARIA wiring, shared-vs-inline decision table, and a worked end-to-end example of adding a validated field - Update docs/components.md: cross-link to forms.md and expand the TextField section with error wiring details - Expand src/lib/__tests__/validateNumber.test.ts with comprehensive edge-case coverage (empty, whitespace, -0, floats, NaN, Infinity, scientific notation, leading zeros, safe integers) - Lock validateNumber.ts and validateId.ts at ≥ 95% in jest.config.ts coverage thresholds to prevent regressions
- Fix JSDoc comment in validateNumber.ts: 1e2 is accepted (integer 100), not rejected; was incorrectly listed in 'Rejected examples' - Expand validateNumber.test.ts with 5 new edge-case tests: * ParseResult type-level assertion * Hex/binary literal coercion behaviour (0xff, 0b101) * Leading-plus coercion (+1, +0) * parsePositiveInt: leading-zero string resolving to 0 is rejected - Document Number() coercion edge cases in docs/forms.md - Note parsePositiveInt error message inconsistency (missing period) and the conventions new validators should follow
…ve conflict in validateNumber
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #329
Summary
Adds the forms and validation guide requested in issue #329. Documents the shared validation contract so new forms stop inlining their own checks.
What's changed
docs/forms.md— new guidevalidateIdentifier,parseNonNegativeInt,parsePositiveInt, includingNumber()coercion edge cases (hex, binary, leading-plus, trailing.0)parsePositiveInt's default messageTextFieldARIA wiring (aria-invalid,aria-describedby,role="alert")TextField→ submit guard → unit testdocs/components.mdTextFieldentry todocs/forms.mdsrc/lib/validateNumber.ts"1e2"was listed in the Rejected examples but correctly evaluates to the integer 100 and is acceptedsrc/lib/__tests__/validateNumber.test.tsParseResulttype assertion, hex/binary coercion (0xff,0b101), leading-plus (+1,+0), andparsePositiveInt("00000")→ rejectedjest.config.tsvalidateNumber.tsandvalidateId.tsat ≥ 95% coverage thresholds (statements / branches / lines) and 100% functionsTest output
npm run lint,npm test, andnpm run buildall pass. The 3 pre-existing test failures indocs/page.test.tsx,export/page.test.tsx, andevents/page.test.tsxare unrelated to this PR and exist onmainbefore this change.