Integrates PHP_CodeSniffer's phpcbf auto-fixer as an external formatter in Zed.
- Lua (
luamust be on your$PATH) - Composer with
squizlabs/php_codesnifferinstalled in your project (vendor/bin/phpcbf) - A
phpcs.xmlconfig file in your project root
git clone https://github.com/AHaldner/zed-phpcbf-setup.git
cd zed-phpcbf-setupThis adds a setup-phpcbf shell function to your ~/.zshrc:
./install.sh
source ~/.zshrcNavigate to the root of the PHP project you want to configure and run:
cd /path/to/your/php-project
setup-phpcbfThis will:
- Create a
tools/directory with thephpcbfwrapper script - Add
.tmp/to your.gitignore
Add the following to your Zed settings.json (open it via Zed > Settings > Open Settings):
"PHP": {
"formatter": {
"external": {
"command": "tools/phpcbf",
"arguments": ["{buffer_path}"]
}
}
}Note: The
commandpath is relative to your project root. Make sure you have runsetup-phpcbfin that project first so thetools/phpcbfscript exists.
When Zed formats a PHP file, it pipes the buffer contents to tools/phpcbf, which:
- Writes the buffer to a temporary file inside
.tmp/zed-phpcbf/ - Runs
vendor/bin/phpcbfagainst it using yourphpcs.xmlruleset - Outputs the fixed content back to Zed
Exit codes are handled correctly, phpcbf returns 1 when it makes fixes (success) and 2+ on actual errors.
zed-phpcbf-setup/
βββ install.sh # Adds setup-phpcbf to ~/.zshrc
βββ setup.lua # Creates tools/phpcbf in your project
βββ scripts/
βββ phpcbf # The wrapper script copied into your project