Skip to content

Report unknown field properties in block.json and field.json - #192

Merged
dnnsjsk merged 2 commits into
inline0:mainfrom
Contributolo:feat/phpstan-unknown-field-properties
Oct 28, 2026
Merged

dnnsjsk merged 2 commits into
inline0:mainfrom
Contributolo:feat/phpstan-unknown-field-properties

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

Closes #190. Builds on #191 and contains its commit until that is merged.

BlockJsonShapeRule and FieldJsonShapeRule now report every property a field's type does not accept, with the closest known property as a suggestion:

block.json field "account" of type "text" has unknown property "translat" in blockstudio/hero/block.json. Did you mean "translate"?

How the questions from #190 are answered here (happy to change any of them):

  1. Source of truth: the schema. The package is split into its own repository and cannot read schemas/ at runtime, so Schema\FieldProperties keeps a static list per built-in type, like SettingsGetReturnType does for settings paths. FieldPropertiesTest compares it with every field branch in schemas/block.json (top level, definitions/Attribute, group children) and skips when the schemas are not there, the same way HookInventoryTest skips without includes/. A property added to the schema without the list, or the other way round, fails that test.
  2. Identifier: separate ones, blockstudio.blockJson.property and blockstudio.fieldJson.property, so a project with its own keys can ignore just these.
  3. Custom types: custom/* references and types registered with bs_register_field_type() are not checked; only the 27 built-in types are.

The schema had to be complete first, otherwise valid properties such as radio display or code asset would have been reported. That is #191. With it, the fields in tests/theme produce no finding (the tooling test from #191 checks exactly that), and a real theme with 28 blocks and 263 fields produced none either.

Extension files are not covered: ExtensionJsonShapeRule does not validate fields today, and extend.json has its own common property set.

Tests: fixtures for a block with four unknown properties (text, a repeater, a field in a repeater, an icon field inside tabs with set instead of sets), a block that uses only valid properties including the ones from #191, and a field.json. The two new rule tests fail without the rule change. phpunit for the package passes (306 tests), as does its PHPStan run; lint, format:check, typecheck, audit:tooling, docs:check, and test:tooling pass. Docs: the PHPStan page and the package README.

The block and extension schemas did not list radio display and allowNull,
checkbox toggle, code asset, wysiwyg mode, and repeater default, although
the editor and the renderer read them and the docs describe asset and
repeater defaults. The default and fallback of color and gradient sat
inside their options property instead of on the field.

A tooling test checks every field in the test theme against the schema
for its type. It also caught the help test block, which used set and
subSet instead of sets and subSets.
The shape rules checked a field's type, id, options, and nesting, but not
its properties, so a misspelled property such as "translat" passed and
silently did nothing. Both rules now report every property the field type
does not accept, with the closest known property as a suggestion.

FieldProperties lists the properties per built-in type. A unit test keeps
it equal to the field branches of schemas/block.json and skips outside the
monorepo. custom/* references and registered field types are not checked.
@dnnsjsk

dnnsjsk commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Merged and released in Blockstudio PHPStan 0.1.12, alongside Blockstudio 7.7.10. This resolves #190. Update the standalone extension with composer require --dev blockstudio/phpstan:^0.1.12. Full CI and distribution checks passed.

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.

blockstudio/phpstan: report unknown field properties in block.json and field.json

2 participants