plugin-check icon indicating copy to clipboard operation
plugin-check copied to clipboard

Do not flag `localhost` usage in comments

Open nielslange opened this issue 2 years ago • 5 comments

Description of the Change

In #267, @leoloso reported that the error "Do not use Localhost in your code" also gets triggered when the string "localhost" is used within a comment. This PR updates the corresponding regex to ignore the string "localhost" within comments.

Closes #267

How to test the Change

  1. Download and activate this helper-plugin.zip
  2. Go to /wp-admin/tools.php?page=plugin-check and check the helper plugin before applying this fix.
  3. Verify that the error "Do not use Localhost/127.0.0.1 in your code." appears.
  4. Apply this PR and check the helper plugin again.
  5. Verify that the error "Do not use Localhost/127.0.0.1 in your code." no longer appears.

Changelog Entry

Fixed - “localhost” in comments no longer raises error.

Credits

Props @nielslange

Checklist:

  • [x] I agree to follow this project's Code of Conduct.
  • [ ] I have updated the documentation accordingly.
  • [x] I have added tests to cover my change.
  • [x] All new and existing tests pass.

nielslange avatar Sep 24 '23 11:09 nielslange

Thank you @nielslange, the code you are creating your Pull Request against is the new Codebase, and it wont be released on the plugin for a little bit so we cannot close the #267 using this PR unless the code you base your PR is from the legacy-plugin branch of this repository.

Sorry for the confusion there.

Now talking about the code, I wonder how much of a performance difference this particular approach has compared to the existing one? We need to consider that, since checks will run on plugins that are 10MB big.

bordoni avatar Sep 24 '23 16:09 bordoni

I used time command to find the time taken for completion of the command. But it seems time gives different output for same command run consecutively. So, I ran commands 3 times and calculate the average time. This does not seem to be reliable test but I did not find much significant drops in performance when trying with three big WordPress plugins.

Before PR:

  • WooCommerce - 7.54s
  • Yoast SEO - 2.67s
  • EDD - 4.99s

After PR:

  • WooCommerce - 6.45s
  • Yoast SEO - 3.12s
  • EDD - 3.76s

ernilambar avatar Dec 28 '23 06:12 ernilambar

While checking this PR, I found another issue. https://github.com/WordPress/plugin-check/issues/362

ernilambar avatar Dec 28 '23 06:12 ernilambar

I previously suggested using a dedicated PHPCS sniff for this, and I think https://github.com/WPTT/WPThemeReview/blob/15684d0852fe90d807c2ae7746dea1302b74b4bd/WPThemeReview/Sniffs/Privacy/ShortenedURLsSniff.php could be a great inspiration here.

swissspidy avatar Aug 19 '24 09:08 swissspidy

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: nielslange <[email protected]>
Co-authored-by: swissspidy <[email protected]>
Co-authored-by: mukeshpanchal27 <[email protected]>
Co-authored-by: ernilambar <[email protected]>
Co-authored-by: bordoni <[email protected]>
Co-authored-by: davidperezgar <[email protected]>
Co-authored-by: leoloso <[email protected]>

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

github-actions[bot] avatar Aug 19 '24 09:08 github-actions[bot]

Since we are now adding custom sniff in PCP itself, I would also recommend to create custom sniff for this issue. Check will be more robust with sniff I believe.

ernilambar avatar Oct 20 '24 08:10 ernilambar

Yes, I'm agree with @ernilambar

davidperezgar avatar Oct 20 '24 11:10 davidperezgar

@nielslange Thanks for the PR and contribution. Closing this now as sniff approach looked more appropriate now.

Closing in favor of https://github.com/WordPress/plugin-check/pull/743

ernilambar avatar Oct 24 '24 09:10 ernilambar