Skip to content

build(docs): teach wp-hookdoc to read standard PHPDoc#1191

Open
utkarshcloudinary wants to merge 3 commits into
feature/documentationfrom
chore/hookdoc-phpdoc-support
Open

build(docs): teach wp-hookdoc to read standard PHPDoc#1191
utkarshcloudinary wants to merge 3 commits into
feature/documentationfrom
chore/hookdoc-phpdoc-support

Conversation

@utkarshcloudinary

@utkarshcloudinary utkarshcloudinary commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Relates to the PHPStan work in #1180.

When #1180 normalizes the @hook docblocks to standard, PHPStan-clean PHPDoc (@param Type $name / @return Type), the documentation generator breaks. The docs are built with wp-hookdoc, a JSDoc plugin that expects the type in {braces} (@param {Type} $name). With valid PHPDoc the hook pages render the type where the variable name should go, drop the type metadata, and leak the variable name into the description. This PR fixes the docs pipeline so the PHP source can keep valid PHPDoc.

Approach

  • Patch wp-hookdoc@0.2.0 (via patch-package) so its beforeParse hook normalizes standard PHPDoc tag syntax to the JSDoc syntax the parser expects, only inside @hook blocks:
    • @param Type $name Desc (standard PHPDoc) → @param {Type} $name Desc
    • @param $name {Type} Desc (legacy hookdoc) → @param {Type} $name Desc
    • @return Type Desc@return {Type} Desc
    • Tags already using the {Type} form are left untouched.
  • Handle PHPDoc fully-qualified class names that JSDoc's type parser rejects: leading-backslash FQCNs like \WP_Post / \Cloudinary\Sync are normalized to WP_Post / Cloudinary.Sync so they no longer error during the build.
  • Wire patch-package into postinstall (patch-package && composer install) and add it as a devDependency; the committed patch lives in patches/wp-hookdoc+0.2.0.patch.
  • Regenerate package-lock.json so npm ci is in sync (reconciles pre-existing transitive drift, e.g. date-fns 4.1.0 → 4.4.0, and adds patch-package).

This keeps the PHP source as valid PHPDoc (PHPStan stays green) while the generated hook documentation continues to render correctly.

QA notes

  1. npm install — confirm patch-package applies the patch on postinstall (look for wp-hookdoc@0.2.0 ✔).
  2. npm ci — completes without "package.json and package-lock.json are in sync" errors.
  3. npm run build:docs — completes with no Unable to parse a tag's type expression / invalid name or invalid syntax errors.
  4. Spot-check a few generated hook pages (e.g. docs/cloudinary_dns_prefetch_types.html, docs/cloudinary_can_sync_asset.html, docs/cloudinary_context_options.html): the filter signature shows the variable name and → {Type} return, the Parameters table lists $name, its type, and description correctly, including union (bool|WP_Error) and FQCN (WP_Post, Cloudinary.Sync) types.
  5. Verified end-to-end against the level-1 PHPStan branch (a superset of Add PHPStan static analysis at level 0 #1180): docs build cleanly from the converted, valid-PHPDoc source.

Patch wp-hookdoc so @hook docblocks can use standard, PHPStan-clean
PHPDoc syntax (@param Type $name / @return Type) instead of the
JSDoc/legacy brace form. The patch normalizes tags to JSDoc syntax in
the beforeParse hook, so generated hook docs render correctly while the
PHP source keeps valid PHPDoc.

Wired via patch-package on postinstall.
JSDoc rejects leading-backslash FQCNs (\WP_Post, \Cloudinary\Sync).
Normalize them to JSDoc form when converting @hook docblock types.
Fresh lockfile resolution so npm ci passes in CI: reconciles pre-existing
drift in transitive deps (e.g. date-fns 4.1.0 -> 4.4.0) and includes
patch-package.
Comment thread package-lock.json

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Needed to re-generate the lock file.

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