Automattic / VIP-Coding-Standards

PHP_CodeSniffer ruleset to enforce WordPress VIP coding standards.
https://wpvip.com/documentation/how-to-install-php-code-sniffer-for-wordpress-com-vip/
Other
236 stars 40 forks source link

phpcbf throwing a fatal error #749

Closed fclaussen closed 1 year ago

fclaussen commented 1 year ago

Bug Description

When running phpcbf on a file it throws the following fatal error

Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /Users/trewknowledge002/test-wp-prettier copy/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/WP/I18nSniff.php on line 194 in /Users/trewknowledge002/test-wp-prettier copy/vendor/squizlabs/php_codesniffer/src/Runner.php:608

This seems to be a known bug over on the wpcs repository that was already fixed. I'm wondering if maybe the version that ships with vipcs needs updating? There were several tickets open about the same issue over there: https://github.com/WordPress/WordPress-Coding-Standards/issues?q=phpcbf

Minimal Code Snippet

I'm tweaking with my configs to have the WordPress-Core and WordPress-VIP-Go standards at the same time. Here's a simple function with missing spaces around the argument. PHPCS captured the error correctly, the problem is really just with phpcbf.

function snake_case($foo) {
    echo 'test';
}

Environment

Use php -v and composer show to get versions.

Question Answer
PHP version 8.1.3
PHP_CodeSniffer version 3.7.2
VIPCS version 2.3.0

Tested Against master branch?

Not sure how I would test that using composer. I really just ran the commands on the installation section of the readme.

GaryJones commented 1 year ago

Once WPCS 3.0 is released, then the next major version of VIPCS will use it as a dependency, meaning the issue you found will be resolved.

In the meantime, you can run PHPCS with PHP 7.4 (even if checking code that needs to run under PHP 8.x) and the issue won't appear.

fclaussen commented 1 year ago

Hi @GaryJones I appreciate the response.

Is there a timeline for when this will be the case?

GaryJones commented 1 year ago

WPCS should be out in a couple of months. VIPCS will be out after that.