Skip to content

AHaldner/zed-phpcbf-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Zed PHP_CodeSniffer Auto-Fixer Setup

Integrates PHP_CodeSniffer's phpcbf auto-fixer as an external formatter in Zed.

Requirements

  • Lua (lua must be on your $PATH)
  • Composer with squizlabs/php_codesniffer installed in your project (vendor/bin/phpcbf)
  • A phpcs.xml config file in your project root

Installation

1. Clone this repo

git clone https://github.com/AHaldner/zed-phpcbf-setup.git
cd zed-phpcbf-setup

2. Run the installer

This adds a setup-phpcbf shell function to your ~/.zshrc:

./install.sh
source ~/.zshrc

3. Run the setup in your project

Navigate to the root of the PHP project you want to configure and run:

cd /path/to/your/php-project
setup-phpcbf

This will:

  • Create a tools/ directory with the phpcbf wrapper script
  • Add .tmp/ to your .gitignore

4. Configure Zed

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 command path is relative to your project root. Make sure you have run setup-phpcbf in that project first so the tools/phpcbf script exists.

How it works

When Zed formats a PHP file, it pipes the buffer contents to tools/phpcbf, which:

  1. Writes the buffer to a temporary file inside .tmp/zed-phpcbf/
  2. Runs vendor/bin/phpcbf against it using your phpcs.xml ruleset
  3. 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.

Project structure

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

About

πŸ› οΈ Automatic phpcbf setup for Zed

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors