Skip to content

[Repo Assist] fix: respect phpcbf.enable setting — operator precedence bug made it a no-op#114

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

[Repo Assist] fix: respect phpcbf.enable setting — operator precedence bug made it a no-op#114
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/fix-enable-setting-2026-03-29-c9d172106275a612

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 Repo Assist here — I'm an automated AI assistant for this repository.

Problem

The phpcbf.enable setting has been documented in package.json since the early versions of this extension, but it never actually worked. Setting "phpcbf.enable": false had no effect — the formatter always ran.

Root cause — operator precedence bug in loadSettings():

// Before (always false — early-return never fires)
if (!config.get("enable") === true) {
    return;
}

JavaScript evaluates left-to-right: !config.get("enable") produces false (when enable is true), and false === true is always false. So the guard is effectively dead code.

Fix

Two minimal changes:

  1. loadSettings() — store the enabled state correctly and keep the early-return:

    this.enabled = config.get("enable", true);
    if (!this.enabled) {
        return;
    }
  2. format() — add an early-return guard so formatting is actually skipped when disabled:

    if (!this.enabled) {
        return Promise.reject();
    }

    The format() guard is necessary because loadSettings() returning early only skips refreshing settings — without the guard in format(), the formatter would still run with whatever settings were loaded previously.

Behaviour

  • "phpcbf.enable": true (default) — no change, formatter runs as before.
  • "phpcbf.enable": false — formatter skips silently. VS Code may show a "Formatter failed" notice if editor.formatOnSave is also enabled (this is pre-existing behaviour for any formatter error; PR [Repo Assist] fix: consolidate critical bug fixes (pre-v0.0.10) #106 eliminates it by changing the catch to resolve([])).

The setting is resource-scoped, so disabling phpcbf for a specific workspace folder works correctly.

Compatibility note

This PR touches the same file as the in-progress PR #106 (consolidation bug fixes), but the changes are in non-overlapping lines. If #106 is merged first, this two-line fix can be applied cleanly as a follow-up patch.

Test Status

✅ All 7 existing unit tests pass (npm run test:unit)

No new tests added — the enable check is in the VSCode extension activation path which requires the VSCode test harness to exercise.

Closes #(no dedicated issue — discovered during code review)

Generated by Repo Assist ·

To install this agentic workflow, run

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

…a no-op

`false` due to JavaScript operator precedence:
  false === true           →  false  (always)

So the early-return was never reached and disabling phpcbf via
`phpcbf.enable: false` had no effect — the formatter always ran.

Fix:
- Store the enabled state in `this.enabled` in `loadSettings()`
- Guard `format()` with an early `Promise.reject()` when disabled

This applies per-resource (the config is scoped), so users can disable
phpcbf for specific workspace folders without affecting others.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Apr 2, 2026
Summarises all bug fixes that are ready to ship, drawn from the
open Repo Assist PRs (primarily #106, #114, #117, #120, #124 and
the earlier consolidated fixes).

The version number in package.json is intentionally not changed here
(that file requires maintainer action due to protected-file
restrictions). This PR exists so the maintainer can review the
intended release notes and bump the version when ready.

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