Add block plugin validator classes and form - #1
Conversation
I'm sure there's a neater way to do this with history and everything but this'll do.
Add parsing and validation for block.json files
Previous regex assumed no leading path.
Produces a form that validates a plugin, given its repo URL, and will output the results. It's pretty scruffy but a useful starting point.
…k.json validator.
dd32
left a comment
There was a problem hiding this comment.
Mostly looks good to me, the only thing I really noticed was not excluding svn:externals by default.
| protected function find_readme_file( $directory ) { | ||
| $files = Filesystem::list_files( $directory, false /* non-recursive */, '!^readme\.(txt|md)$!i' ); | ||
| static function find_readme_file( $directory ) { | ||
| $files = Filesystem::list_files( $directory, false /* non-recursive */, '!(?:^|/)readme\.(txt|md)$!i' ); |
There was a problem hiding this comment.
Given this is a non-recursive search, is /readme.. ever going to be hit?
There was a problem hiding this comment.
I now figure that this change was probably mostly for consistency with the recursive searches added elsewhere.
There was a problem hiding this comment.
list_files() seemed to be matching against the full path, including the $directory prefix. With the ^ assertion only, it doesn't match any files. There might be something contextual here that's causing different behaviour, as otherwise find_readme_file() wouldn't work at all.
There was a problem hiding this comment.
Odd, it must be working at present though..
| sprintf( | ||
| __( 'At least one of the following properties must be present: %s', 'wporg-plugins' ), | ||
| // translators: used between list items, there is a space after the comma. | ||
| '<code>script</code>' . __( ', ', 'wporg-plugins' ) . '<code>editorScript</code>' |
There was a problem hiding this comment.
It hardly seems worth translating a comma.. unless it's used elsewhere.
I was going to suggest wp_sprintf_l( '%l' ) could be used here, but that would generate X and Y not X or Y.
There was a problem hiding this comment.
Today I Learned about the existence of wp_sprintf_l()...
There was a problem hiding this comment.
The translated comma and translator hint is lifted directly from one of the default themes, so I think it's a pretty common pattern. Though it doesn't look like it's used elsewhere in the wporg-plugins textdomain...
Co-authored-by: Corey McKrill <916023+coreymckrill@users.noreply.github.com>
This is a crude check to make sure the plugin has at least one call to registerBlockType from JavaScript. Which is a requirement for it to work in the Gutenberg inserter.
Thanks @dd32.
This adds a [block-validator] shortcode, based on the readme-validator, which runs a bunch of validation checks on block plugins. It incorporates @coreymckrill's
block.jsonvalidator.Also included is a CLI script,
bin/check-block.php. If you run it without arguments, it will output validation results for all plugins currently in the block directory. Or usephp bin/check-block.php --slug wavesto run it on a single plugin.