Skip to content

Add PHPCS ruleset from Plugin Check and fix issues #2048

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

Merged
merged 12 commits into from
Jun 13, 2025
Merged

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Jun 10, 2025

Fixes #2043
Fixes #2049

@westonruter westonruter added [Type] Bug An existing feature is broken no milestone PRs that do not have a defined milestone for release skip changelog PRs that should not be mentioned in changelogs labels Jun 10, 2025
Copy link

codecov bot commented Jun 10, 2025

Codecov Report

Attention: Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Project coverage is 68.03%. Comparing base (77d137f) to head (4c06a40).
Report is 18 commits behind head on trunk.

Files with missing lines Patch % Lines
plugins/performance-lab/includes/admin/load.php 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #2048      +/-   ##
==========================================
+ Coverage   68.02%   68.03%   +0.01%     
==========================================
  Files          92       92              
  Lines        7627     7631       +4     
==========================================
+ Hits         5188     5192       +4     
  Misses       2439     2439              
Flag Coverage Δ
multisite 68.03% <77.77%> (+0.01%) ⬆️
single 37.02% <77.77%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -305,7 +305,7 @@ function perflab_install_activate_plugin_callback(): void {
wp_die( esc_html__( 'Missing required parameter.', 'performance-lab' ) );
}

$plugin_slug = perflab_sanitize_plugin_slug( wp_unslash( $_GET['slug'] ) );
$plugin_slug = perflab_sanitize_plugin_slug( wp_unslash( $_GET['slug'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- perflab_sanitize_plugin_slug() is a sanitizing function.
Copy link
Member Author

Choose a reason for hiding this comment

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

As an alternative to this, the function could be added to customUnslashingSanitizingFunctions, but then Plugin Check wouldn't know about it.

Copy link
Member

Choose a reason for hiding this comment

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

On the other hand, I don't think Plugin Check handles phpcs:ignore comments, so it won't have an effect there.

Related: WordPress/plugin-check#901

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 guess then it's still better to have these comments because if a plugin reviewer looks at the line they can at least see the explanatory comment.

Copy link

github-actions bot commented Jun 10, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <[email protected]>
Co-authored-by: swissspidy <[email protected]>
Co-authored-by: ShyamGadde <[email protected]>
Co-authored-by: pmbaldha <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@westonruter westonruter added this to the performance-lab n.e.x.t milestone Jun 10, 2025
@westonruter westonruter removed the no milestone PRs that do not have a defined milestone for release label Jun 10, 2025
<!-- For more information: https://make.wordpress.org/plugins/handbook/review/ -->
<description>Standards any plugin to be published on wordpress.org should comply with.</description>

<!-- The following rules have been copied from https://github.com/WordPress/plugin-check/blob/95c426228a23a3b290de7758a1708e95fd3c5345/phpcs-rulesets/plugin-review.xml#L33-L174 -->
Copy link
Member

Choose a reason for hiding this comment

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

Instead of copying the file, can we just reference it in phpcs.ruleset.xml from vendor/[...]/plugin-check/phpcs-rulesets/plugin-review.xml?

Copy link
Member Author

@westonruter westonruter Jun 10, 2025

Choose a reason for hiding this comment

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

Good question. I thought about this but I didn't try it because that ruleset includes other rules which we don't want, namely:

https://github.com/WordPress/plugin-check/blob/95c426228a23a3b290de7758a1708e95fd3c5345/phpcs-rulesets/plugin-review.xml#L7-L31

The config <config name="testVersion" value="5.2-"/> is causing a lot of failures in PHPCompatibility. I just tried.

It would be nice if there was a base ruleset in PCP which plugin-review.xml included that we could also include.

Copy link
Member

Choose a reason for hiding this comment

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

I see, makes sense.

Yeah there might be ways to make that easier. Can't hurt to open an issue there with this suggestion 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. Opened: WordPress/plugin-check#966

@swissspidy
Copy link
Member

The changes here are nice for local development. For CI, it might be easier to just use https://github.com/WordPress/plugin-check-action

@westonruter
Copy link
Member Author

For CI, it might be easier to just use https://github.com/WordPress/plugin-check-action

I thought about that, but the only concern there would be duplication in the failures, right? Also, if PCP ignores phpcs:ignore comments then this would be problematic, right?

@swissspidy
Copy link
Member

I thought about that, but the only concern there would be duplication in the failures, right?

Yes there would be duplication. So probably have to pick one or the other.

Also, if PCP ignores phpcs:ignore comments then this would be problematic, right?

It depends. PCP Is the source of truth after all, as that's what's being run on dotorg for plugin submissions (and eventually updates)

@westonruter westonruter requested a review from ShyamGadde June 13, 2025 00:24
Copy link
Contributor

@ShyamGadde ShyamGadde left a comment

Choose a reason for hiding this comment

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

LGTM - went through the diff and everything looks good to me, nothing further from my side. 👍

@westonruter westonruter merged commit b4b2eca into trunk Jun 13, 2025
20 of 21 checks passed
@westonruter westonruter deleted the fix/phpcs branch June 13, 2025 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip changelog PRs that should not be mentioned in changelogs [Type] Bug An existing feature is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comply the Optimization Detective Plugin with the Plugin Check (PCP) Plugin Address errors reported by Plugin Check
3 participants