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

Add Enqueued Resources check #331

Merged
merged 5 commits into from
Jul 3, 2024

Conversation

ernilambar
Copy link
Member

@ernilambar ernilambar commented Dec 8, 2023

Fixes #25

Note:

  • I have added tests to cover my change.
  • All new and existing tests pass.
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

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

Thank you for addressing the checks. I have provided some feedback for your consideration.

Regarding this matter, we are currently in the process of evaluating the acceptance criteria for this check. I don't believe it's fully prepared for engineering work yet. @felixarntz, could you please share your thoughts on this?

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@ernilambar @mukeshpanchal27 I think it might be okay to merge this as it's a simple check using WPCS and it's certainly a best practice. I would however prefer to check with the plugin review team whether they're okay with it.

I think in any case it could be merged as a warning, but right now it is an error and I would like to validate whether that's okay with the review team.

The other thing is that the category of this check should IMO be a different one.

includes/Checker/Checks/Enqueued_Resources_Check.php Outdated Show resolved Hide resolved
@mukeshpanchal27
Copy link
Member

I think in any case it could be merged as a warning, but right now it is an error and I would like to validate whether that's okay with the review team.

The WPCS itself return error https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php#L65 so we should return error for this check. Please correct me if i miss anything. Thanks!

@ernilambar
Copy link
Member Author

In the Acceptance Criteria in #25 it is mentioned that warnings should be displayed.

@mukeshpanchal27
Copy link
Member

It seems the AC are not currently up to date and haven't been approved by any team member. Perhaps this was mistakenly labeled as a notice when, in fact, the sniff itself returns an error, indicating that we should display an error message.

@ernilambar ernilambar force-pushed the enqueued-resources-check branch 2 times, most recently from a26cde8 to dddb163 Compare January 5, 2024 15:13
@ernilambar
Copy link
Member Author

PR has been rebased. GENERAL category is assigned for this check. Message is kept as Error.

@davidperezgar davidperezgar added the [Team] Plugin Review Issues owned by Plugin Review Team label Jun 22, 2024
@davidperezgar
Copy link
Member

Hello,
This check is part of Plugins Team, so the category should be Plugin repo. In our reviews, we actually enforce users to enqueue all assets, so it should be an error.

@ernilambar
Copy link
Member Author

PR has been updated and ready for review.

@davidperezgar
Copy link
Member

davidperezgar commented Jun 26, 2024

Hello, I have compared Internal Scanner and this check and is not giving same results.

For example is not detecting this code:

// Add the inline footer JS into an external JS file
function inline_footer_js() {
    // Create a nonce
    $nonce = wp_create_nonce('currency_converter_nonce');
    ?>
    <script type="text/javascript">
       var ajaxurl = '<?php echo esc_url(admin_url('admin-ajax.php')); ?>';
       var currencyConverterNonce = '<?php echo esc_js($nonce); ?>';
    </script>
    <?php
}
add_action('wp_footer', 'inline_footer_js');

What we are doing in our scanner is using regex. @frantorres could help as well on this. I give you the regex that we are using:
script_src: /<script\s[^>]*?src\s*=\s*["|\']?([^>"\']*)["|\']?[^>]*?>/i

script_type: /<script\s[^>]*?type\s*=\s*["|\']?([^>"\']*(script)[^>"\']*)["|\']?[^>]*?>/i

script_only: /<script\s*>/i

link: /<link\s[^>]*?rel\s*=\s*["|\']?([^>"\']*(stylesheet)[^>"\']*)["|\']?[^>]*?>/i

link-type: /<link\s[^>]*?type\s*=\s*["|\']?([^>"\']*(text\\/css)[^>"\']*)["|\']?[^>]*?>/i

style: /<style(\s*|\s[^>]*)>/i

They were tested and working correctly. I don't know the best approach, but WPCS seems not to be the only one.

@davidperezgar
Copy link
Member

I've reviewed with Fran, and We could suggest to WPCS to have better detection of enqueues.

@swissspidy
Copy link
Member

Yes, contributing to WPCS would be best here 👍

Right now it only has 2 regexes for external scripts/styles, none for inline scripts etc.

Code in question: https://github.com/WordPress/WordPress-Coding-Standards/blob/d77b0204f49e4b4a2bbac791e3bbfbfe603edf06/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php#L51-L81

@swissspidy swissspidy added the [Team] Performance Issues owned by Performance Team label Jul 1, 2024
@swissspidy swissspidy dismissed stale reviews from felixarntz and mukeshpanchal27 July 3, 2024 07:39

Feedback is old and has been addressed

Copy link
Member

@davidperezgar davidperezgar left a comment

Choose a reason for hiding this comment

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

All seems ok. We're going to make an issue to WPCS in order to have better detection of enqueues.

@davidperezgar davidperezgar merged commit 214dc75 into WordPress:trunk Jul 3, 2024
18 of 19 checks passed
@ernilambar ernilambar deleted the enqueued-resources-check branch July 12, 2024 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Team] Performance Issues owned by Performance Team [Team] Plugin Review Issues owned by Plugin Review Team
5 participants