Skip to content

Suggest the closest storage key for unknown fields in bs_validate_block() - #198

Merged
dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:feat/validator-unknown-field-suggestion
Nov 4, 2026
Merged

dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:feat/validator-unknown-field-suggestion

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

An unknown_field finding lists every known storage key in expected, but its message does not say which one was probably meant. Unknown settings (Settings::closest_key()) and the PHPStan rules for attribute access, block.json and field.json already add "did you mean", so tooling around bs_validate_block() currently computes the same suggestion itself.

This adds the closest key at the same level to the message, within three edits and case-insensitive, the rule Settings::closest_key() uses:

This storage key is not declared by the block or its extensions. Did you mean "title"?
  • The finding keeps its six stable keys; expected still lists every known key, so tooling that reads code and expected sees no change.
  • Works at every storage level, including repeater rows (rows/0/titel suggests title).
  • New string Did you mean "%s"? in the POT and in the de_DE and de_DE_formal translations; the other locales are left to the translation run, as with Report unknown top-level attributes in bs_validate_block() #194.
  • One sentence in the validation section of docs/blocks/rendering.md (and the same lines in blockstudio-llm-full.txt).
  • Unit test test_unknown_field_message_names_the_closest_key_at_its_level (typo, case, repeater row, no close key).

Checked locally: composer cs and PHPStan on the validator, npm run docs:check, and a WordPress Playground run with this branch as the plugin, where bs_validate_block() reports Did you mean "titel"? for tilte in English and German and no suggestion for a key with nothing close. The PHP unit suite needs wp-env, so it runs in CI here.

…ck()

An unknown_field finding listed every known key in expected but gave no
hint which one was meant, while unknown settings and the PHPStan rules
already say "did you mean". The message now names the closest key at the
same level within three edits, the rule Settings::closest_key() uses. The
finding keeps its six keys; expected is unchanged.
@dnnsjsk
dnnsjsk merged commit d3f6679 into inline0:main Nov 4, 2026
@dnnsjsk

dnnsjsk commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Merged and released in 7.7.12, included in ff1b433. Unknown stored fields now suggest the closest key at the same storage level without changing stored values or the machine-readable finding format. Added regression coverage for prefixed groups, nested repeaters, extensions, bounded matching, and CLI output, plus docs and translations. Full CI and distribution checks passed. Thanks for the contribution.

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