Skip to content

fix(validate): type-check list and boolean fields and strip trailing comments in scalars - #128

Closed
rahul05ranjan wants to merge 2 commits into
TMHSDigital:mainfrom
rahul05ranjan:fix/validate-field-types
Closed

rahul05ranjan wants to merge 2 commits into
TMHSDigital:mainfrom
rahul05ranjan:fix/validate-field-types

Conversation

@rahul05ranjan

Copy link
Copy Markdown

Fixes #79

What changed

The parser now strips an unquoted trailing # comment (site/lib/frontmatter.mjs, parseScalar): a # preceded by whitespace and outside quotes ends the value, exactly as YAML reads it. So the template's own line

tags: [low-poly, modular]   # describe the content; never the licence or the publisher (V19, V21)

now parses as the list ["low-poly", "modular"] instead of the string "[low-poly, modular] # describe the content…". A # inside quotes and a URL fragment with no space before it (https://example.com/#anchor) are kept. Comments stay encouraged in entries — only the value parsing changed. Because of this, every new entry from npm run new-entry that keeps the template's comments no longer starts life with string tags; no scaffold change was needed.

The validator now type-checks the shapes (site/checks.mjs, wired in site/validate.mjs):

  • checkListTypes: subcategories, formats, tags, hardware_tags must be lists when present. A string like the old mangled tags is an error instead of silently falling back to [] everywhere downstream.
  • checkBooleanField: commercial must be boolean or unknown|varies; attribution_required must be boolean or unknown. A quoted "true" is rejected as the string it is, instead of passing the enum check and rendering as "commercial ?" on the card.

Per the issue's evidence, no committed entry is affected — this is a trap for the next contributor, now closed at both ends (parser + validator).

Verification (system Node v26.12.1, no installs)

  • node site/lib/lib.test.mjs: 434 ok (425 before; 9 new — URL fragment kept, comment stripped from a flow list and from a boolean, quoted # kept, strip only outside quotes, no-space # kept, and the template's own tags line parses as a list with zero parser errors).
  • node site/checks.test.mjs: 144 ok (134 before; 10 new — string tags/formats rejected, list and absent and empty-list pass, quoted "true"/"false" rejected for both fields, varies/unknown pass).
  • node site/validate.mjs on the full catalog: exit 0, no errors — all 415 committed entries pass the new checks, matching the issue's audit.
  • node --check on all changed files: OK.

AI-assisted implementation and self-review.

rahul05ranjan and others added 2 commits October 22, 2026 14:37
…es as problems

--stale-days given as the last argument or as a non-number became NaN
and the run died in new Date(NaN).toISOString() only after every fetch
had already run. A GitHub API 5xx/timeout/rate limit was written as a
row under 'repository state differs from maintenance' and counted in
problems, so a transient outage opened the correction issue; after a
403/429 the loop broke and the remaining repositories were silently
unchecked. The flag is now validated before anything runs, API
failances land in a 'Could not check (N skipped)' section excluded
from problems, and a rate-limited loop says which repositories were
not checked and why. The helpers moved to lib/link-check.mjs so the
argument parsing and the failure classification are tested.

Fixes TMHSDigital#82

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
…ments in scalars

The validator checked list fields for emptiness but never that they are
lists, and never that commercial/attribution_required are booleans.
The frontmatter parser had no trailing-comment handling, so the
template's own 'tags: [low-poly, modular]   # ...' line parsed as a
string and every new entry from npm run new-entry that kept the
comment started with string tags; a quoted commercial: "true" passed
the enum check and rendered as 'commercial ?'. parseScalar now strips
unquoted trailing comments (a # preceded by whitespace, outside
quotes; URL fragments untouched), and validate rejects non-list lists
and non-boolean boolean fields via two new checks in checks.mjs.

Fixes TMHSDigital#79

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
@TMHSDigital

Copy link
Copy Markdown
Owner

Thank you for this, and for the tests. #124 merged this morning with the same fix for #79 (opened before this PR could be reviewed), so this branch now conflicts with main and the issue is closed. I compared the two line by line and main covers everything here, so I am closing this as superseded rather than asking for a rebase. Contributions are welcome on any of the remaining open issues.

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.

validate: list and boolean fields are never type-checked; a trailing # comment turns tags into a string and the template ships one

2 participants