Skip to content

fix(format): look up a built-in formatter by its published name - #46869

Closed
devYRPauli wants to merge 1 commit into
anomalyco:devfrom
devYRPauli:formatter-name-lookup
Closed

devYRPauli wants to merge 1 commit into
anomalyco:devfrom
devYRPauli:formatter-name-lookup

Conversation

@devYRPauli

Copy link
Copy Markdown

Issue for this PR

Closes #46868

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

packages/opencode/src/format/index.ts:134 looked up a built-in formatter with Formatter[name as keyof typeof Formatter], where name is the config key. That reads the module's export identifier. Three built-ins publish a different name:

config key, as docs/formatters.mdx publishes it export identifier
clang-format clang
air rlang
uv uvformat

For those three the lookup returned undefined. The entry was then built from builtIn ?? { extensions: [] }, and enabled became async () => info.command ?? false. With no command in the config that check always returns false, and the built-in extensions were replaced by an empty list. So any override other than disabled turned the formatter off, with no error.

The published name is the correct key. formatters is already keyed by item.name one block above, status() reports item.name, and the docs table lists clang-format, air and uv. The docs also say you can configure a built-in with environment or extensions, which is the case that broke.

This keys the built-ins by Info.name and reads that map. The cast is what hid the defect, so it is gone with it.

One behaviour change beyond the fix. Writing the export identifier, for example "clang": {}, no longer resolves to the built-in. That spelling is not in the docs. Before this change it created a second entry alongside clang-format, so the formatter ran twice on the same file. It now behaves like any other unknown key: a custom formatter that needs its own command.

How did you verify your code works?

Two cases added to packages/opencode/test/format/format.test.ts.

The first configures clang-format, air and uv with an empty override and asserts status() still reports each built-in's extensions.

The second is end to end. It points Formatter.clang at a scratch extension and a command that appends C. It restores the formatter afterwards, the way the existing parallel case does, then writes a file and calls Format.file().

bun test test/format/format.test.ts               13 pass, 0 fail
bun test test/format test/tool test/config       287 pass, 3 skip, 0 fail
bun run typecheck                                 30 tasks successful
prettier --check                                  clean
oxlint                                            5 warnings, 0 errors, same as dev

With the source change reverted and both tests kept, exactly those two fail and the other 11 pass:

config: { formatter: { "clang-format": {} } }
file contents after Format.file()    expected "xC"    actual "x"

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The config lookup read Formatter[name] with the config key, which is the
module's export identifier. Three built-ins publish a different name:
clang-format exports as clang, air as rlang and uv as uvformat.

For those three the lookup returned undefined, so the entry lost the
built-in extensions and its enabled check became a command that does not
exist. Any override other than disabled turned the formatter off.

Key the built-ins by Info.name, which is the name the docs publish, the
name status() reports and the key formatters already uses.
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

@devYRPauli

Copy link
Copy Markdown
Author

This still reproduces on dev at 907b3bc. Executing the current formatter initialization with empty overrides for clang-format, air and uv gives each an empty extension list and disables it. This PR's name-based lookup preserves all three definitions. Could you reopen it so I can refresh and retest the branch?

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.

Bug: configuring clang-format, air or uv by name silently disables the formatter

1 participant