Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing block/theme json $schema property #57201

Merged
merged 3 commits into from
Dec 21, 2023
Merged

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Dec 19, 2023

What?

Add $schema to block.json and theme.json files to leverage JSON schema support.

Why?

Schemas help ensure that these files conform to expectations. They can help provide autocomplete and documentation if editors are configured to do so.

We provide and maintain these schemas, we should be using them. This can help to ensure that our own declarations are correct and that the schemas are also correct.

Testing Instructions

If you have an editor configured to show JSON schema information, you can open up one of these files and confirm it works as expected. I believe Visual Studio Code provides this behavior by default.

This change is a developer experience improvement and should not otherwise impact the behavior of Gutenberg or its packages.

Screenshots or screencast

Screenshot 2023-12-19 at 12 50 21

Copy link

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ lib/theme.json
❔ phpunit/data/themedir1/block-theme-child-with-fluid-layout/theme.json
❔ phpunit/data/themedir1/block-theme-child-with-fluid-typography-config/theme.json
❔ phpunit/data/themedir1/block-theme-child-with-fluid-typography/theme.json
❔ phpunit/data/themedir1/block-theme-child/theme.json
❔ phpunit/data/themedir1/block-theme/theme.json
❔ phpunit/data/themedir1/fonts-block-theme/theme.json
❔ phpunit/fixtures/block.json
❔ phpunit/fixtures/hooked-block/block.json

@sirreal
Copy link
Member Author

sirreal commented Dec 19, 2023

I've run JSON schema validation on the project and found that some of the files touched here seem to have violations:

check-jsonschema --schemafile 'https://schemas.wp.org/trunk/block.json' $(find . -name block.json -not -path './schemas/**')

Results

  ./phpunit/fixtures/block.json::$: Additional properties are not allowed ('textDomain' was unexpected)
  ./phpunit/fixtures/hooked-block/block.json::$: 'title' is a required property
  ./packages/edit-widgets/src/blocks/widget-area/block.json::$: 'title' is a required property
  ./packages/widgets/src/blocks/widget-group/block.json::$: 'title' is a required property

check-jsonschema --schemafile 'https://schemas.wp.org/trunk/theme.json' $(find . -name theme.json -not -path './schemas/**')

Results

Schema validation errors were encountered.
  ./lib/theme.json::$.settings.color: Additional properties are not allowed ('caption' was unexpected)
  ./lib/theme.json::$.styles.elements.button.spacing.padding: 'calc(0.667em + 2px) calc(1.333em + 2px)' is not of type 'object'

@sirreal sirreal marked this pull request as ready for review December 19, 2023 11:56
@sirreal sirreal added Developer Experience Ideas about improving block and theme developer experience [Type] Code Quality Issues or PRs that relate to code quality labels Dec 19, 2023
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Nice, that’s helpful 👍

There is an integration test that validates core blocks:

const blockFolders = glob.sync( 'packages/block-library/src/*', {

It looks like the glob could also cover blocks created in the widgets package.

@sirreal
Copy link
Member Author

sirreal commented Dec 21, 2023

I'm glad to see we have automation to check schemas, I'll look at enabling it for more places in another PR since that will require changes to the violating schemas.

@sirreal sirreal merged commit 5f4c7fe into trunk Dec 21, 2023
51 checks passed
@sirreal sirreal deleted the add/missing-json-schemas branch December 21, 2023 15:00
@github-actions github-actions bot added this to the Gutenberg 17.4 milestone Dec 21, 2023
@getdave getdave added the Needs PHP backport Needs PHP backport to Core label Jan 15, 2024
@getdave
Copy link
Contributor

getdave commented Jan 15, 2024

@sirreal Please could you confirm whether you believe this PR requires backport for WP 6.5?

@sirreal
Copy link
Member Author

sirreal commented Jan 15, 2024

The package changes should be handled by other workflows.

For other files I've created https://core.trac.wordpress.org/ticket/60255, I'll handle adding schemas to these JSON files in core. I'll remove the backport label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer Experience Ideas about improving block and theme developer experience [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants