You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This extension integrates PHP_CodeSniffer with Zed Editor to provide real-time code style checking. It highlights violations as you code and supports various PHP coding standards including PSR-12, custom rulesets, and project-specific configurations.
10
+
This extension integrates PHP_CodeSniffer with Zed Editor to provide real-time code style checking and automatic formatting. It highlights violations as you code, auto-fixes them on save via PHPCBF, and supports various PHP coding standards including PSR-12, custom rulesets, and project-specific configurations.
11
11
12
12
## Features
13
13
14
14
-**Real-time diagnostics** - See code style violations as you type
15
-
-**Code formatting** - Format files with phpcbf via `Cmd+Shift+I` or format-on-save
15
+
-**Auto-fix on save** - Automatically fix all PHPCS issues on save via `source.fixAll.phpcs`
16
16
-**Zero configuration** - Works out of the box using PHPCS native defaults
17
17
-**Live configuration** - Settings changes apply immediately without restart
18
18
-**Auto-recovery** - Automatically handles deleted or invalid config files
@@ -69,6 +69,24 @@ if ($x === 1) {
69
69
}
70
70
```
71
71
72
+
4.**Enable auto-fix on save** (optional) to fix all PHPCS issues when you save:
73
+
74
+
```json
75
+
{
76
+
"languages": {
77
+
"PHP": {
78
+
"code_actions_on_format": {
79
+
"source.fixAll.phpcs": true
80
+
},
81
+
"formatter": [],
82
+
"format_on_save": "on"
83
+
}
84
+
}
85
+
}
86
+
```
87
+
88
+
> **Note:** This runs PHPCBF on every save, automatically fixing all fixable code style issues. The `"formatter": []` is required to prevent Zed's default formatter from interfering. See the [Auto-Fix on Save](#auto-fix-on-save) section for more configuration options.
89
+
72
90
## Configuration
73
91
74
92
> **Note:** The extension works without any configuration, using PHPCS's natural defaults and bundled binaries.
4.**System PATH** - Global phpcs installation (respects your `phpcs --config-set` settings)
197
+
5.**Bundled PHAR** - Modern PHPCS v3.13.2+ (fallback, included with extension)
178
198
179
199
> **💡 Global Config Support:** The extension now respects your system PHPCS configuration. Set global defaults with `phpcs --config-set default_standard PSR12` or `phpcs --config-set installed_paths /path/to/sniffs` and they'll work automatically without any Zed configuration.
180
200
@@ -264,22 +284,59 @@ If a config file becomes corrupted or references missing standards:
264
284
-**Workspace changes** - Config re-discovered when switching projects
265
285
-**File system changes** - Config errors trigger automatic re-discovery
266
286
267
-
## Formatting
287
+
## Auto-Fix on Save
288
+
289
+
The extension supports automatic fixing of code style issues via PHPCBF (PHP Code Beautifier and Fixer), using the `source.fixAll.phpcs` code action. This follows the same convention used by ESLint, Biome, and Ruff.
290
+
291
+
### PHPCS Fixes Only
292
+
293
+
```json
294
+
{
295
+
"languages": {
296
+
"PHP": {
297
+
"code_actions_on_format": {
298
+
"source.fixAll.phpcs": true
299
+
},
300
+
"formatter": [],
301
+
"format_on_save": "on"
302
+
}
303
+
}
304
+
}
305
+
```
306
+
307
+
### All Linter Fixes
308
+
309
+
Fix issues from PHPCS and any other linters that support `source.fixAll`:
268
310
269
-
The extension supports code formatting via PHPCBF (PHP Code Beautifier and Fixer). When triggered, it runs `phpcbf` on the current file content and applies all fixable changes.
311
+
```json
312
+
{
313
+
"languages": {
314
+
"PHP": {
315
+
"code_actions_on_format": {
316
+
"source.fixAll": true
317
+
},
318
+
"formatter": [],
319
+
"format_on_save": "on"
320
+
}
321
+
}
322
+
}
323
+
```
270
324
271
-
### Enabling Format-on-Save
325
+
### Combine with a Separate Formatter
272
326
273
-
Add the following to your Zed `settings.json` (`Cmd+,` or `Ctrl+,`):
327
+
Use PHPCS fixing alongside a separate formatter (e.g., Prettier for embedded HTML/JS):
@@ -288,15 +345,14 @@ Add the following to your Zed `settings.json` (`Cmd+,` or `Ctrl+,`):
288
345
}
289
346
```
290
347
291
-
> **Note:** Using `"name": "phpcs"` ensures Zed routes formatting to this extension rather than another language server like intelephense.
292
-
293
-
You can also format manually with `Cmd+Shift+I` (macOS) or `Ctrl+Shift+I` (Linux/Windows).
348
+
> **Important:** When using `code_actions_on_format` without a separate formatter, you must set `"formatter": []` to prevent Zed's default `"auto"` formatter from interfering. See [zed-industries/zed#51490](https://github.com/zed-industries/zed/issues/51490) for details.
294
349
295
350
### How It Works
296
351
297
-
-Formatting uses the same coding standard as linting (phpcs.xml discovery, Zed settings, etc.)
352
+
-Auto-fixing uses the same coding standard as linting (phpcs.xml discovery, Zed settings, etc.)
298
353
- PHPCBF is discovered automatically using the same priority as PHPCS: project `vendor/bin` → user-configured path → `PHPCBF_PATH` env var → system PATH → bundled PHAR
299
-
- Formatting and linting run from the same LSP process — no extra configuration needed
354
+
- Auto-fixing and linting run from the same LSP process — no extra configuration needed
355
+
- The `source.fixAll.phpcs` code action is also available in the lightbulb menu for manual use
0 commit comments