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

Support for PHP 8 with WPCS #37

Closed
1 task done
akshitsethi opened this issue Jan 3, 2023 · 10 comments · Fixed by #49
Closed
1 task done

Support for PHP 8 with WPCS #37

akshitsethi opened this issue Jan 3, 2023 · 10 comments · Fixed by #49

Comments

@akshitsethi
Copy link

Describe the bug

There is an error when running phpcs with the current release of wpcs which is v2.3.0. The error which occurs for PHP 8.0 only is as under:

PHP Fatal error:  Uncaught TypeError: vsprintf(): Argument #2 ($values) must be of type array, string given in /Users/akshitsethi/wp-local-docker-sites/snowsoftware-test/wordpress/wp-content/vendor/squizlabs/php_codesniffer/src/Files/File.php:1056

Related issues:

Steps to Reproduce

  1. Upgrade PHP to v8.0
  2. In the terminal, try running composer lint for any project using phpcs-composer package
  3. Notice the error

Screenshots, screen recording, code snippet

Screenshot 2023-01-03 at 8 32 41 PM

Environment information

  • PHP v8.0.26
  • phpcs-composer dev-master
  • WPCS v2.3.0

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@akshitsethi
Copy link
Author

No release has been made yet but a tagged version in wpcs repo has this issue resolved.

https://github.com/WordPress/WordPress-Coding-Standards/releases/tag/2.3.0-fix-vsprintf

@claytoncollie
Copy link
Contributor

claytoncollie commented Jan 4, 2023

@akshitsethi I am seeing the same thing. Do you have a temporary workaround in your project to get past this?

Long term solution might be to version control the wpcs package in the composer.json file but that would require a release by this repository. I'm hoping there is something more temporary we can do right now.

@akshitsethi
Copy link
Author

@claytoncollie Unfortunately, I'm stuck as well atm. If you want something to be fixed locally for you, then I suggest you make the changes as done in this PR - https://github.com/WordPress/WordPress-Coding-Standards/pull/1935/files

@johnwatkins0
Copy link
Member

johnwatkins0 commented Jan 5, 2023

@akshitsethi @claytoncollie One solution would be to exclude the broken sniff from the 10up ruleset and add the updated version from that PR as a custom sniff in the 10up ruleset.

@claytoncollie
Copy link
Contributor

I tried to create a branch in this repository with the tag created by Gary Jones. But since it is on the develop branch and not published to packagist, I am having a hard time sourcing it with the command composer require wp-coding-standards/wpcs:dev-develop#2.3.0-fix-vsprintf -W and that is after adding a repo reference to the composer.json file seen below.

"repositories": [
  {
    "type": "git",
    "url": "https://github.com/WordPress/WordPress-Coding-Standards"
  }
],

Running the require command produces an error related to the automatic vipcs package.

Problem 1
    - automattic/vipwpcs is locked to version 2.3.3 and an update of this package was not requested.
    - automattic/vipwpcs 2.3.3 requires wp-coding-standards/wpcs ^2.3 -> found wp-coding-standards/wpcs[2.3.0] but it conflicts with your root composer.json require (dev-develop#2.3.0-fix-vsprintf).

I think the easiest fix is what @johnwatkins0 suggested.

@37Rb
Copy link

37Rb commented Jan 19, 2023

@claytoncollie your idea worked great for me after a long struggle trying other solutions. Thanks! Here's my composer.json:

{
    "repositories": [
        {
            "type": "git",
            "url": "https://github.com/WordPress/WordPress-Coding-Standards"
        }
    ],
    "require-dev": {
        "dealerdirect/phpcodesniffer-composer-installer": "^1.0",
        "wp-coding-standards/wpcs": "dev-develop#2.3.0-fix-vsprintf"
    },
    "config": {
        "allow-plugins": {
            "dealerdirect/phpcodesniffer-composer-installer": true
        }
    }
}

@joemcgill
Copy link

The official roadmap for WPCS v3.0, which adds support for PHP 8.0 can be read here:
WordPress/WordPress-Coding-Standards#1877

@PypWalters
Copy link

The workaround I used for this was to upgrade to PHP 8.1 (8.0 is approaching EOL in a couple months anyway) and then add the following to your phpcs.xml file: <ini name="error_reporting" value="E_ALL &#38; ~E_DEPRECATED" />. If you don't add that to your phpcs.xml you will see an error like this "An error occurred during processing; checking has been aborted. The error message was: trim(): Passing null to parameter #1 ($string) of type string is deprecated..."

@claytoncollie
Copy link
Contributor

claytoncollie commented Aug 21, 2023

WPCS 3.0.0 was released on 8/21. You can either wait for this repository to be updated or you can use the composer.json example above to require the latest tag.

https://github.com/WordPress/WordPress-Coding-Standards/releases/tag/3.0.0

@darylldoyle
Copy link
Collaborator

I've just tagged a 3.0.0-RC1 release that updates the ruleset to use PHPCS 3.0.0.

You can try it out by using:

composer require 10up/phpcs-composer:~3@RC

If you have any issues, please log them in #49 or open an issue and reference that PR.

@darylldoyle darylldoyle linked a pull request Sep 14, 2023 that will close this issue
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 a pull request may close this issue.

7 participants