Do not flag `localhost` usage in 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
- Download and activate this helper-plugin.zip
- Go to
/wp-admin/tools.php?page=plugin-checkand check the helper plugin before applying this fix. - Verify that the error "Do not use Localhost/127.0.0.1 in your code." appears.
- Apply this PR and check the helper plugin again.
- 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.
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.
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
While checking this PR, I found another issue. https://github.com/WordPress/plugin-check/issues/362
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.
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.
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.
Yes, I'm agree with @ernilambar
@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