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

phpcs: Fix unintentional exclusions #37122

Merged
merged 5 commits into from
Apr 30, 2024
Merged

Conversation

anomiex
Copy link
Contributor

@anomiex anomiex commented Apr 29, 2024

Proposed changes:

Turns out that if you do like

<rule ref="Standard.Category.Sniff.Message">
  <severity>0</severity>
</rule>

then phpcs may implicitly set severity to 0 for all the rest of Standard.Category.Sniff too since it interprets the <rule> as wanting only that one message from the sniff.

What you really want if you want to exclude only one message from a sniff is

<rule ref="Standard.Category.Sniff">
  <exclude name="Standard.Category.Sniff.Message"/>
</rule>

So let's add a CI linting check to tell people to do the latter when they try to do the former, and clean up all the places where people have done the former in phpcs-required files.

The cleanup takes three forms:

  • Fix anything auto-fixable, because there's little point in ignoring them when they can be fixed with no effort.
  • Manually fix things that are easily enough fixable and that really shouldn't be ignored.
  • Add additional message exclusions for messages that it seems like they really wanted to exclude.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

None. I was looking at a plugin Phan has to flag when a doc comment is using /* instead of /**, then I thought that phpcs would probably be better for that than Phan, and then came across this when looking into why phpcs hadn't already caught these.

Does this pull request change what data or activity we track or use?

No

Testing instructions:

  • CI happy?
  • You could try copying just the .github/files/lint-project-structure.sh from this PR into trunk and seeing if it flags all the .phpcs.dir.xml files I'm changing here.

Turns out that if you do like
```
<rule ref="Standard.Category.Sniff.Message">
  <severity>0</severity>
</rule>
```
then phpcs may implicitly set severity to 0 for all the rest of
`Standard.Category.Sniff` too since it interprets the `<rule>` as
wanting only that one message from the sniff.

What you really want if you want to exclude only one message from a
sniff is
```
<rule ref="Standard.Category.Sniff">
  <exclude name="Standard.Category.Sniff.Message"/>
</rule>
```

So let's add a CI linting check to tell people to do the latter when
they try to do the former, and clean up all the places where people have
done the former in phpcs-required files.

The cleanup takes three forms:

* Fix anything auto-fixable, because there's little point in ignoring
  them when they can be fixed with no effort.
* Manually fix things that are easily enough fixable and that really
  shouldn't be ignored.
* Add additional message exclusions for messages that it seems like they
  really wanted to exclude.
@anomiex anomiex added [Type] Bug When a feature is broken and / or not performing as intended [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Type] Janitorial [Pri] Normal labels Apr 29, 2024
@anomiex anomiex requested a review from a team April 29, 2024 19:17
@anomiex anomiex self-assigned this Apr 29, 2024
@anomiex anomiex enabled auto-merge (squash) April 29, 2024 19:17
Copy link
Contributor

github-actions bot commented Apr 29, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the fix/unexpected-phpcs-exclusions branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack fix/unexpected-phpcs-exclusions
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Boost Feature] Setup Prompt [Boost Feature] Image Size Analysis [Boost Feature] Page Cache [Boost Feature] Image CDN aka Photon [Focus] Compatibility Ensuring our products play well with third-parties [Package] Phpcs Filter [Package] WAF [Package] WP JS Data Sync [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] CRM Issues about the Jetpack CRM plugin [Plugin] Inspect [Plugin] Super Cache A fast caching plugin for WordPress. [Tests] Includes Tests Actions GitHub actions used to automate some of the work around releases and repository management Docs labels Apr 29, 2024
Copy link
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Boost plugin:

  • Next scheduled release: May 7, 2024.
  • Scheduled code freeze: April 29, 2024.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Super Cache plugin:

  • Next scheduled release: May 7, 2024.
  • Scheduled code freeze: April 29, 2024.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Inspect plugin:

  • Next scheduled release: May 7, 2024.
  • Scheduled code freeze: April 29, 2024.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

<rule ref="Squiz.Commenting.FunctionComment.MissingParamTag">
<severity>0</severity>
<rule ref="Squiz.Commenting.FunctionComment">
<exclude name="Squiz.Commenting.FunctionComment.Missing"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be nested in the above group (line 34).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤷 Phpcs doesn't seem to mind, and the original seemed to intentionally have all the "Missing" sniffs listed as a group.

@anomiex anomiex merged commit df039de into trunk Apr 30, 2024
64 checks passed
@anomiex anomiex deleted the fix/unexpected-phpcs-exclusions branch April 30, 2024 16:25
@github-actions github-actions bot removed the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Actions GitHub actions used to automate some of the work around releases and repository management [Boost Feature] Image CDN aka Photon [Boost Feature] Image Size Analysis [Boost Feature] Page Cache [Boost Feature] Setup Prompt Docs [Focus] Compatibility Ensuring our products play well with third-parties [Package] Phpcs Filter [Package] WAF [Package] WP JS Data Sync [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] CRM Issues about the Jetpack CRM plugin [Plugin] Inspect [Plugin] Super Cache A fast caching plugin for WordPress. [Pri] Normal [Tests] Includes Tests [Type] Bug When a feature is broken and / or not performing as intended [Type] Janitorial
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants