Description
According to Slack Conversation, opening issue to update this guideline.
Instead of a ready to copy paste text I will simply share here each and every step I needed to take and the findings I had, please pick what you think is useful to update the guide.
This setup assumes global usage, not project limited, and uses the first suggested package of the DOC (https://github.com/WordPress/WordPress-Coding-Standards/wiki/Setting-up-WPCS-to-work-in-Sublime-Text#sublime-phpcs-package)
- Follow this to install WPCS and PHPCS since you likely will have Composer 2 and not the outdated Composer 1 on your machine. Thus, start with this command:
composer global require dealerdirect/phpcodesniffer-composer-installer --update-no-dev
composer global require wp-coding-standards/wpcs --update-no-dev
- Put the bin in your path, with following command:
nano ~/.zshrc
, addexport PATH="$HOME/.composer/vendor/bin:$PATH"
to the file and write it out, close the file, thensource ~/.zshrc
and confirm it worked withwhere phpcs
(you should see something like/Users/your_user_name/.composer/vendor/bin/phpcs
) - Point PHPCS to WPCS config:
phpcs --config-set installed_paths /Users/your_user_name/.composer/vendor/wp-coding-standards/wpcs
- In Sublime, open Preferences > Package Control and choose Install Package, then select
Phpcs
package (https://benmatselby.dev/sublime-phpcs/) - In Sublime, open Preferences > Package Settings > PHP Code Sniffer > Settings Default and copy the entire content, then open Preferences > Package Settings > PHP Code Sniffer > Settings User and paste the entire content. Now alter these points:
- item
phpcs_executable_path
should be (full line statement):
"phpcs_executable_path": "/Users/your_user_name/.composer/vendor/bin/phpcs",
- item
phpcs_additional_args
should be (full line statement):
"phpcs_additional_args": {
"--standard": "WordPress",
"-n": ""
},
- item
phpcbf_executable_path
should be (full line statement):
"phpcbf_executable_path": "/Users/your_user_name/.composer/vendor/bin/phpcbf",
- item
phpcbf_additional_args
should be (full line statement):
"phpcbf_additional_args": {
"--standard": "WordPress",
"-n": ""
},
That should be it, you have now a context menu item "PHP Code Sniffer" in Sublime text where you can sniff, change default, and Beautify.
Note, Sublime package additionally adds "php cs fixer" as well, which will not work with WPCS. Ignore and do not use it.
Note 2, The SublimeLinter-phpcs
(second method described on above doc) did not work for me at all. While it is available in the package control for install, it will fail with ImportError: No module named 'SublimeLinter'
on install.
Why, not sure, and did not dig, and removed it again.