Skip to content

Conversation

@westonruter
Copy link
Member

@westonruter westonruter commented May 15, 2023

  • Add static keyword to eligible closures via composer run-script format -- --sniffs=SlevomatCodingStandard.Functions.StaticClosure
  • Undo changes to Gutenberg-upstream files.

Trac ticket: https://core.trac.wordpress.org/ticket/58323


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

composer.json Outdated
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"squizlabs/php_codesniffer": "3.6.0",
"squizlabs/php_codesniffer": "^3.7.1",
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm curious why PHPCS was pinned back on 3.6.0. The current version is 3.7.2. @jrfnl I'm sure you know!

Copy link
Member

@jrfnl jrfnl May 16, 2023

Choose a reason for hiding this comment

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

I'd definitely recommend an update, but until WPCS 3.0.0 is released the point is moot.

PHPCS 3.6.1 - 3.7.2 do contain some useful bugfixes, but the majority of updates are related to supporting new PHP syntaxes, which WP Core cannot use anyway since the minimum PHP version is 5.6, so for WP the benefit of updating would be minimal.

Also see the changelogs: https://github.com/squizlabs/PHP_CodeSniffer/releases

PHPCS does need to be pinned to a specific version as there is no committed composer.lock file and having PHPCS be a moving target which can fail builds at random whenever a new version is tagged is not desirable, so using ^ in the version constraint is out of the question.

Aside from that, I'd recommend an update to PHPCS to be done in a separate PR as it may throw new warnings/errors/allow for ignore annotations to be removed, which should not be mixed in with this PR.

composer.json Outdated
"phpcompatibility/phpcompatibility-wp": "~2.1.3",
"yoast/phpunit-polyfills": "^1.0.1"
"yoast/phpunit-polyfills": "^1.0.1",
"slevomat/coding-standard": "^8.0"
Copy link
Member Author

@westonruter westonruter May 15, 2023

Choose a reason for hiding this comment

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

Ah, this sniff requires PHP 7.2+. Per GHA log:

Error: Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - slevomat/coding-standard[8.0.0, ..., 8.12.0] require php ^7.2 || ^8.0 -> your php version (5.6.40) does not satisfy that requirement.
    - Root composer.json requires slevomat/coding-standard ^8.0 -> satisfiable by slevomat/coding-standard[8.0.0, ..., 8.12.0].

Copy link
Member

Choose a reason for hiding this comment

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

... which is why it is not a dependency of WPCS (aside from a wide variety of bugs and other PHPCS non-standard behaviour, including adding additional external dependencies, which would need to be fixed first anyway).

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

See my inline comments.

While it is fine to use external sniffs to improve the WP codebase, adding those to the ruleset is a big no-no.

composer.json Outdated
"phpcompatibility/phpcompatibility-wp": "~2.1.3",
"yoast/phpunit-polyfills": "^1.0.1"
"yoast/phpunit-polyfills": "^1.0.1",
"slevomat/coding-standard": "^8.0"
Copy link
Member

Choose a reason for hiding this comment

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

... which is why it is not a dependency of WPCS (aside from a wide variety of bugs and other PHPCS non-standard behaviour, including adding additional external dependencies, which would need to be fixed first anyway).

composer.json Outdated
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"squizlabs/php_codesniffer": "3.6.0",
"squizlabs/php_codesniffer": "^3.7.1",
Copy link
Member

@jrfnl jrfnl May 16, 2023

Choose a reason for hiding this comment

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

I'd definitely recommend an update, but until WPCS 3.0.0 is released the point is moot.

PHPCS 3.6.1 - 3.7.2 do contain some useful bugfixes, but the majority of updates are related to supporting new PHP syntaxes, which WP Core cannot use anyway since the minimum PHP version is 5.6, so for WP the benefit of updating would be minimal.

Also see the changelogs: https://github.com/squizlabs/PHP_CodeSniffer/releases

PHPCS does need to be pinned to a specific version as there is no committed composer.lock file and having PHPCS be a moving target which can fail builds at random whenever a new version is tagged is not desirable, so using ^ in the version constraint is out of the question.

Aside from that, I'd recommend an update to PHPCS to be done in a separate PR as it may throw new warnings/errors/allow for ignore annotations to be removed, which should not be mixed in with this PR.

phpcs.xml.dist Outdated
<exclude-pattern>/src/wp-content/themes/twentyfourteen/inc/featured-content\.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.Functions.StaticClosure" />
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be removed.

It is not a rule in the official coding standards, so, while I agree, it is a good "best practice", we cannot demand for it to be enforced.


// The likes of block element styles from theme.json do not have $metadata['name'] set.
if ( ! isset( $metadata['name'] ) && ! empty( $metadata['path'] ) ) {
$result = array_values(
Copy link
Member

Choose a reason for hiding this comment

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

This is a file controlled by gutenberg. This change will need to made in the gutenberg repo and ported across.

Copy link
Member Author

Choose a reason for hiding this comment

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

* Check for allowed pseudo classes (e.g. ":hover") from the $selector ("a:hover").
* This also resets the array keys.
*/
$pseudo_matches = array_values(
Copy link
Member

Choose a reason for hiding this comment

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

This is a file controlled by gutenberg. This change will need to made in the gutenberg repo and ported across.

Copy link
Member Author

Choose a reason for hiding this comment

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

I suppose that should be indicated in the file DocBlock.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@spacedmonkey spacedmonkey left a comment

Choose a reason for hiding this comment

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

+1 to remove all the coding standard changes. Let's just keep this today code changes. Also, please remove all gutenberg related changes.

@westonruter
Copy link
Member Author

westonruter commented May 16, 2023

While it is fine to use external sniffs to improve the WP codebase, adding those to the ruleset is a big no-no.

@jrfnl Just curious why adding these to the ruleset is not OK. I thought the ruleset here was exclusively for wordpress-develop, as it's not located in the WPCS repo.

…into trac-58323

* 'trunk' of https://github.com/WordPress/wordpress-develop:
  Media: Increase default for `wp_omit_loading_attr_threshold` to 3.
  Media: Prevent CSRF setting attachment thumbnails.
  Embeds: Add protocol validation for WordPress Embed code.
  Editor: Ensure block comments are of a valid form.
  Editor: Remove shortcode support from block templates.
  I18N: Introduce sanitization function for locale.
  Taxonomy: Do not prime term meta in `wp_get_object_terms`.
  Docs: Clarify `@param` types on `get_sample_permalink_html` filter.
@westonruter westonruter requested review from jrfnl and spacedmonkey May 16, 2023 21:49
@jrfnl
Copy link
Member

jrfnl commented May 16, 2023

While it is fine to use external sniffs to improve the WP codebase, adding those to the ruleset is a big no-no.

@jrfnl Just curious why adding these to the ruleset is not OK. I thought the ruleset here was exclusively for wordpress-develop, as it's not located in the WPCS repo.

True, but if we want to enforce something for WP Core, I keep being told that it has to go through a) a Make post, b) a change to the formal coding standards docs, c) only after that the standard can be changed. I don't see why it would be any different for you. 🤷🏻‍♀️

Aside from that, adding the Slevomat standard would be prohibitive for running a composer install on PHP < 7.2, which is, of course, a no-no.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Current state of this PR is all okay.

While looking through the PR, I do see some other things which should probably be addressed (long closures which should be named functions, unnecessary use of references and closure use), but that's definitely outside the scope of this PR and for another time ;-).

* @return string Returns the block content.
*/
$settings['render_callback'] = function( $attributes, $content, $block ) use ( $template_path ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$settings['render_callback'] = static function( $attributes, $content, $block ) use ( $template_path ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
Copy link
Member

Choose a reason for hiding this comment

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

Outside of the scope of this PR, but we may as well remove the // phpcs:ignore comment as the VariableAnalysis standard is not being used by Core, nor WPCS.

Isn't this also a Gutenberg file though ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't this also a Gutenberg file though ?

Based on the filename it would seem so, but it seems to fundamentally be a different file from https://github.com/WordPress/gutenberg/blob/trunk/lib/blocks.php

Copy link
Member

Choose a reason for hiding this comment

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

I agree we should look into // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable, but not in this ticket.

Copy link
Member

@spacedmonkey spacedmonkey left a comment

Choose a reason for hiding this comment

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

Looking good.

@westonruter
Copy link
Member Author

Committed to trunk in d5792c7

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.

3 participants