Format PHP (php-cs-fixer, phpcbf) and Python (black) files in VS Code.
Features
- PHP Formatting: Support for
php-cs-fixer and phpcbf
- Python Formatting: Support for
black
- Configurable: Choose your preferred PHP formatter backend
Installation
Install from the VS Code Marketplace or search for "VSCode Formatter" in VS Code Extensions.
Configuration
{
"VSCodeFormatter.phpToolFormatter": "phpcbf", // or "php-cs-fixer"
"VSCodeFormatter.blackPath": "black"
}
Development
Prerequisites
- Node.js 18+
- Yarn package manager
Building
# Install dependencies
yarn install
# Build the extension
npm run build
This compiles TypeScript source files from src/ into bundled outputs in out/:
out/extension.mjs (ESM format)
out/extension.cjs (CommonJS format)
Testing
npm test
Publishing
1. Create Publisher Account
- Go to Visual Studio Marketplace
- Sign in with your Microsoft account
- Navigate to your publisher page:
https://marketplace.visualstudio.com/manage/publishers/<your-publisher-name>
- Click "New Extension" to begin creating your publisher account if you don't have one yet
2. Build the Extension
# Install dependencies
yarn install
# Build TypeScript sources
npm run build
3. Package the Extension
npm run package
This generates a .vsix file (e.g., vscode-formatter-1.0.0.vsix).
4. Upload to Marketplace
- Go to your publisher page:
https://marketplace.visualstudio.com/manage/publishers/dimaslanjaka
- Click "New Extension" → select "Visual Studio Code"
- Click "Upload" and select your
.vsix file
- Fill in the extension details:
- Name: Must match your
package.json name
- Category: Select appropriate category
- Tags: Add relevant tags for discoverability
- Click "Save" then "Publish"
Your extension will be available on the Marketplace after a few minutes.
Version Updates
When updating the extension:
- Update the
version field in package.json (e.g., 1.0.0 → 1.0.1)
- Rebuild and re-upload:
npm run build
npm run package
Then upload the new .vsix file from your publisher page.
Install Locally
To test the packaged extension locally:
code --install-extension vscode-formatter-1.0.0.vsix
References
php-cs-fixer usage
php-cs-fixer fix [--path-mode PATH-MODE] [--allow-risky ALLOW-RISKY] [--config CONFIG] [--dry-run] [--rules RULES] [--using-cache USING-CACHE] [--allow-unsupported-php-version ALLOW-UNSUPPORTED-PHP-VERSION] [--cache-file CACHE-FILE] [--diff] [--format FORMAT] [--stop-on-violation] [--show-progress SHOW-PROGRESS] [--sequential] [--] [<path>...]