Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,50 @@ per default by adding this to your settings:
}
```

## Docker support

You can run php-cs-fixer inside Docker instead of installing PHP/CS Fixer on the host. Enable it and choose either starting a short-lived container (run) or executing inside an existing container (exec).

Settings (choose one):

Example: exec (default)

```json
{
"php-cs-fixer.docker.enable": true,
"php-cs-fixer.docker.mode": "exec",
"php-cs-fixer.docker.command": "docker",
"php-cs-fixer.docker.container": "php-app",
"php-cs-fixer.docker.workspaceFolder": "/app",
"php-cs-fixer.docker.execExtraArgs": []
}
```

Example: run

```json
{
"php-cs-fixer.docker.enable": true,
"php-cs-fixer.docker.mode": "run",
"php-cs-fixer.docker.command": "docker",
"php-cs-fixer.docker.image": "composer:latest",
"php-cs-fixer.docker.workspaceFolder": "/app",
"php-cs-fixer.docker.runExtraArgs": []
}
```

Notes:

- If `docker.workspaceFolder` is set, the extension mounts your workspace root to that path when using `docker run`. For partial/unsaved content:
- docker run: the host temporary directory is mounted to `/tmp` in the container so PHP CS Fixer can read the temp file.
- docker exec: partial/unsaved formatting is not supported out-of-the-box because new mounts cannot be added with `docker exec`. Workarounds: save the file first or use `docker run` mode for such cases.
If `docker.workspaceFolder` is not set, no mount or workdir is applied; your Dockerfile/image defaults are used.
- The binary used inside the container comes from `php-cs-fixer.executablePath`. If you're using a `.phar` in the container, set `php-cs-fixer.executablePath` accordingly (e.g., `php /path/in/container/php-cs-fixer.phar`).
- Config files provided by `php-cs-fixer.config` are automatically mapped to the container path.
- Mode requirements:
exec: set `php-cs-fixer.docker.container` (existing running container name/id).
run: set `php-cs-fixer.docker.image` (image name/tag to start the container).

## Auto fix

```text
Expand Down
42 changes: 42 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,48 @@
"type": "integer",
"default": 1,
"description": "last automatically download php-cs-fixer time, if you want to disable auto download for latest php-cs-fixer.phar set to 0. just for automatically installed user."
},
"php-cs-fixer.docker.enable": {
"type": "boolean",
"default": false,
"description": "Run php-cs-fixer inside Docker. When enabled, the extension will call php-cs-fixer through Docker instead of the host runtime."
},
"php-cs-fixer.docker.mode": {
"type": "string",
"enum": ["run", "exec"],
"default": "exec",
"description": "Choose how to invoke Docker: 'exec' (default) to run inside an existing container, or 'run' to start a new container for each run."
},
"php-cs-fixer.docker.command": {
"type": "string",
"default": "docker",
"description": "Docker CLI binary, e.g., 'docker' or 'podman'."
},
"php-cs-fixer.docker.image": {
"type": "string",
"default": "",
"description": "Docker image to use when mode is 'run'. For example: 'ghcr.io/junstyle/php-cs-fixer:latest' or 'composer:latest'."
},
"php-cs-fixer.docker.container": {
"type": "string",
"default": "",
"description": "Existing container name or ID when mode is 'exec'."
},
"php-cs-fixer.docker.workspaceFolder": {
"type": "string",
"description": "Optional. Workspace mount path inside container when using 'run'. If not set, the extension won't mount or change workdir; image defaults are used."
},
"php-cs-fixer.docker.runExtraArgs": {
"type": "array",
"items": { "type": "string" },
"default": [],
"description": "Extra arguments for 'docker run', e.g., ['--network=host']."
},
"php-cs-fixer.docker.execExtraArgs": {
"type": "array",
"items": { "type": "string" },
"default": [],
"description": "Extra arguments for 'docker exec', e.g., ['-u', '1000:1000']."
}
}
},
Expand Down
9 changes: 9 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ export class PHPCSFixerConfig {
// fileAutoSave: boolean
// fileAutoSaveDelay: number
tmpDir: string
// Docker options
dockerEnable?: boolean
dockerMode?: 'run' | 'exec'
dockerCommand?: string
dockerImage?: string
dockerContainer?: string
dockerWorkspaceFolder?: string
dockerRunExtraArgs?: string[]
dockerExecExtraArgs?: string[]
}
Loading