fix(format): handle custom formatter command property with enabled() interface

The formatter Info interface uses enabled(): Promise<string[] | false> but
user configs provide a command property. Added explicit return type to the
arrow function that transforms command into the enabled() return value.

Also added test to verify custom formatters with command property work.
This commit is contained in:
Dax Raad
2026-03-19 23:19:36 -04:00
parent 205affa0eb
commit 7a28d0520a
2 changed files with 22 additions and 1 deletions

View File

@@ -62,7 +62,7 @@ export namespace Format {
formatters[name] = {
...info,
name,
enabled: async () => info.command,
enabled: async (): Promise<string[] | false> => info.command,
}
}
} else {

View File

@@ -55,6 +55,27 @@ describe("Format", () => {
})
})
test("status() includes custom formatters with command from config", async () => {
await using tmp = await tmpdir({
config: {
formatter: {
customtool: {
command: ["echo", "formatted", "$FILE"],
extensions: [".custom"],
},
},
},
})
await withServices(tmp.path, Format.layer, async (rt) => {
const statuses = await rt.runPromise(Format.Service.use((s) => s.status()))
const custom = statuses.find((s) => s.name === "customtool")
expect(custom).toBeDefined()
expect(custom!.extensions).toContain(".custom")
expect(custom!.enabled).toBe(true)
})
})
test("service initializes without error", async () => {
await using tmp = await tmpdir()