Skip to content

[Repo Assist] fix: honour phpcbf.enable=false — store flag and guard format()#128

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/fix-enable-setting-2026-04-03-4eba4d06999cd207
Draft

[Repo Assist] fix: honour phpcbf.enable=false — store flag and guard format()#128
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/fix-enable-setting-2026-04-03-4eba4d06999cd207

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 3, 2026

🤖 This is an automated draft PR from Repo Assist, an AI assistant.

Summary

Fixes a bug where phpcbf.enable = false had no effect: the extension continued to spawn phpcbf even after being explicitly disabled.

Root Cause

loadSettings() used this guard:

if (!config.get("enable") === true) {
    return;
}
```

The operator precedence here is correct (`!true === true` is `false`, `!false === true` is `true`), so the early return did fire when `enable = false`. **However**, it returned *without storing the value*. `this.enable` was never set.

Then `format()` called `this.loadSettings(document.uri)`, which returned early, and immediately proceeded to spawn `phpcbf` using stale cached settings (`this.executablePath`, etc.) from a previous enabled call.

Result: toggling `phpcbf.enable = false` after the extension had already run once was a no-op.

## Fix

1. In `loadSettings()`: always read and store `this.enable = config.get("enable", true)` *before* the early return, so the flag is always current.
2. In `format()`: check `if (!this.enable) return Promise.resolve([]);` immediately after calling `loadSettings()`. This returns an empty edit list without spawning `phpcbf`.

## Test Status

All 7 existing unit tests pass:

```
 findFiles (7 subtests)
 tests 7, pass 7, fail 0

No integration test infrastructure exists in the repo (protected package.json / vscode test harness). The fix is a straightforward guard addition and the logic is clearly correct from code inspection.

Closes

Closes #56 (phpcbf.enable setting does not disable formatting).

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

as a guard in loadSettings() but had a critical side-effect problem:
when enable=false the method returned early WITHOUT storing the value,
leaving this.executablePath and other cached settings from a previous
(enabled) call intact.

As a result, disabling the extension via phpcbf.enable=false had no
effect: format() would call loadSettings(), which returned early, then
proceed to spawn phpcbf using the stale cached executablePath.

Fix:
- Always read and store this.enable before the early return in
  loadSettings(), so format() has a reliable flag to check.
- Add an explicit early return in format() when this.enable is false,
  returning an empty TextEdit array immediately without spawning phpcbf.

Closes #56 (fixes phpcbf.enable setting being a no-op).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants