From bbe19274eed936878b99f920b0411001d2fa6d02 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 3 Apr 2026 19:01:09 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20honour=20phpcbf.enable=3Dfalse=20?= =?UTF-8?q?=E2=80=94=20store=20flag=20and=20guard=20format()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- extension.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/extension.js b/extension.js index 6457e71..d2c36bc 100644 --- a/extension.js +++ b/extension.js @@ -27,7 +27,12 @@ class PHPCBF { (window.activeTextEditor ? window.activeTextEditor.document.uri : null); let config = workspace.getConfiguration("phpcbf", configUri); - if (!config.get("enable") === true) { + // Always read the enable flag first so format() can check it even when + // disabled. The original `!config.get("enable") === true` check returned + // early without storing the value, leaving stale settings in place and + // allowing phpcbf to run despite being disabled. + this.enable = config.get("enable", true); + if (!this.enable) { return; } this.onsave = config.get("onsave", false); @@ -132,6 +137,11 @@ class PHPCBF { // per-folder settings are respected on every format call. this.loadSettings(document.uri); + // Respect phpcbf.enable = false: return an empty edit list immediately. + if (!this.enable) { + return Promise.resolve([]); + } + if (this.debug) { console.time("phpcbf"); }