Skip to content

fix(biome-plugin): format the biome.json it patches, and leave unchanged JSON byte-identical - #284

Merged
rqbazan merged 3 commits into
mainfrom
fix/biome-plugin-patch-format
Oct 18, 2026
Merged

rqbazan merged 3 commits into
mainfrom
fix/biome-plugin-patch-format

Conversation

@rqbazan

@rqbazan rqbazan commented Oct 18, 2026

Copy link
Copy Markdown
Member

Summary

When the project already has a biome.json, rr plugins add biome patches it with edit-json. The kernel's engine re-stringifies the whole file: 2-space indent and one array item per line. Biome's formatter rejects that, so rr jsc / rr check failed right after the add. dx#276 fixed the create path; this fixes the patch path.

 install(ctx)  // @rrlab/biome-plugin, patch path
   edit-json biome.json   set /$schema (if-missing), include /extends @rrlab/biome-config
+  edit-text biome.json   format with the installed Biome (cwd = project, so the patched config applies)
+                         on any error → leave the text as it is (the add never fails)

 applyJsonEdits(source, edits)  // @rrlab/cli
+  if the edits changed nothing → return source verbatim (no reflow, reported "unchanged")
   return cjson.stringify(root, null, 2)
  • The format step runs Biome synchronously (execFileSync), because edit-text is (source) => string. Widening it to accept a Promise would be a contract change, and an older kernel would write the Promise to disk. No other plugin spawns in install() today; ADR 017 records the choice.
  • decisions/017-plugin-owned-format-of-patched-config.md (arch-critic): the plugin that owns a config file's tool formats what it patches. ADR 004 gets a pointer to it. The wider question, whether the kernel should format everything rr plugins add writes, is still open, and this doesn't close it.

Evidence

Non-TTY e2e with the worktree's packed @rrlab/cli + @rrlab/biome-plugin. Each project starts as a green Biome project (biome check exits 0), then runs rr plugins add biome </dev/null and rr plugins add ts </dev/null:

existing biome.json before: rr jsc after
2-space, no arrays ✖ biome.json (extends spread over 3 lines) ✔ rr check passes
2-space, inline files.includes ✖ biome.json (untouched array spread) ✔ rr check passes
fresh, then add biome --force ✖ biome.json rewritten by a no-op ✔ byte-identical, "No changes"
tabs (biome init) ✖ biome.json + run-run.config.mts biome.json ✔ (tabs kept); run-run.config.mts and tsconfig.json still flagged
4-space, inline extends ✖ biome.json + run-run.config.mts biome.json ✔; same two other files flagged

The tab and 4-space rows still fail on files this PR doesn't own: run-run.config.mts is written by the kernel's config-ast with 2 spaces, and tsconfig.json by ts-plugin's edit-json. Both are tracked separately; an ADR amending 004 is coming.

Regression guard: reverting only json-edit.ts fails 5 tests (json-edit, file-ops, 2× plugins integration). Reverting only the biome-plugin step fails its new unit and integration tests.

Merge Danger

Door: two-way

Blast Radius: small

  • The cli change only skips writes that would have changed nothing.
  • The biome step only runs on the patch path, and it falls back to the unformatted text.
  • Known wart: the add log prints "Edited biome.json" twice, once per op.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EZVC7xzzsEmByszmfff4u2

@changeset-bot

changeset-bot Bot commented Oct 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c4ac242

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@rrlab/biome-plugin Patch
@rrlab/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vland-bot

vland-bot Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Preview release

Latest commit: c4ac242

Some packages have been released:

Package Version Install
@rrlab/biome-plugin 1.2.2-git-c4ac242.0 @rrlab/biome-plugin@1.2.2-git-c4ac242.0
@rrlab/cli 1.5.2-git-c4ac242.0 @rrlab/cli@1.5.2-git-c4ac242.0

Note

Use the PR number as tag to install any package. For instance:

pnpm add @rrlab/biome-plugin@pr-284

@rqbazan
rqbazan merged commit a3ee007 into main Oct 18, 2026
10 checks passed
@rqbazan
rqbazan deleted the fix/biome-plugin-patch-format branch October 18, 2026 18:01
@vland-bot vland-bot Bot mentioned this pull request Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant