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 rule changes to account for VIP functions #14

Merged
merged 4 commits into from
Mar 10, 2025

Conversation

ryanwelcher
Copy link
Contributor

@ryanwelcher ryanwelcher commented Mar 10, 2025

This PR is meant to address some VIP PHPCS sniffs that recommend functions not available on the Newspack platform.

The approach taken is to change the messaging to inform the user that the code in question should be used with caution and it may be slow or uncached and to reduce the sniff to a warning so that it appears in the IDE.

I have also updated the linting command to bypass warnings so only actual errors will be triggered when the lint command is run either manually, by Husky or via an Action.

There are a number of other sniffs from the VIP ruleset that will fire errors that I left alone as I think they are probably good to follow.

Closes: #9

Testing Instructions

// Should fire warnings
$query_args = array(
	'post_type'      => 'post',
	'posts_per_page' => 10,
	'orderby'         => 'rand',
);
$new_query = new \WP_Query( $query_args );

get_adjacent_post(true, '', true );
get_previous_post(true );
get_previous_post_link('%link', '%title', true );
get_next_post( true );
get_next_post_link('%link', '%title', true );
role_add_role( 'test_role', 'Test Role', array( 'read' => true ) );
wp_old_slug_redirect( 'test-slug' );
file_get_contents( 'https://www.google.com' );
count_user_posts( 1, 'post' );
attachment_url_to_postid( 'https://www.google.com' );
url_to_postid( 'https://www.google.com' );

// Should not fire errors
wp_remote_get( 'https://www.google.com' );
  1. Add the snippet above to the plugin.php
  2. Confirm that warnings are showing in the IDE
  3. Confirm that none of the messages mention using VIP functions
  4. Confirm that wp_remote_get fires no errors or warning
  5. Run npm run lint and confirm that none of the warnings are flagged

…ill show the warnings in the IDE but allow them to pass the automated linting.
…ivalents

Remove the wp_remote_get sniff as it's not a caching warning.
Copy link

@claudiulodro claudiulodro left a comment

Choose a reason for hiding this comment

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

Works as advertised. Thanks!

@ryanwelcher ryanwelcher merged commit 75d2fcd into trunk Mar 10, 2025
3 checks passed
@ryanwelcher ryanwelcher deleted the feature/phpcs-vip-changes branch March 10, 2025 19:13
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.

Remove PHPCS errors that want to use VIP only functions
2 participants