mirror of
https://github.com/anomalyco/opencode.git
synced 2026-09-01 07:04:28 +00:00
refactor(core): reuse formatter file extension (#46080)
This commit is contained in:
parent
e9f7331516
commit
327dc809c5
2 changed files with 30 additions and 3 deletions
|
|
@ -54,9 +54,8 @@ const layer = Layer.effect(
|
|||
})
|
||||
|
||||
const file = Effect.fn("Formatter.file")(function* (filepath: string) {
|
||||
const matching = state
|
||||
.get()
|
||||
.formatters.filter((formatter) => formatter.extensions.includes(path.extname(filepath)))
|
||||
const extension = path.extname(filepath)
|
||||
const matching = state.get().formatters.filter((formatter) => formatter.extensions.includes(extension))
|
||||
|
||||
for (const formatter of matching) {
|
||||
const enabled = yield* command(formatter)
|
||||
|
|
|
|||
|
|
@ -58,6 +58,34 @@ function withFormatter<A, E, R>(
|
|||
}
|
||||
|
||||
describe("Formatter", () => {
|
||||
;[
|
||||
{ file: "test.match", extension: ".match", matches: true },
|
||||
{ file: "test.other", extension: ".match", matches: false },
|
||||
{ file: "test.MATCH", extension: ".match", matches: false },
|
||||
{ file: "test.MATCH", extension: ".MATCH", matches: true },
|
||||
{ file: ".match", extension: ".match", matches: false },
|
||||
{ file: ".match", extension: "", matches: true },
|
||||
{ file: "README", extension: ".match", matches: false },
|
||||
{ file: "README", extension: "", matches: true },
|
||||
{ file: "test.part.match", extension: ".match", matches: true },
|
||||
{ file: "test.part.match", extension: ".part.match", matches: false },
|
||||
].forEach((entry) =>
|
||||
it.live(`matches ${entry.file} against ${JSON.stringify(entry.extension)}: ${entry.matches}`, () =>
|
||||
withFormatter(
|
||||
{
|
||||
matching: {
|
||||
command: [process.execPath, "-e", "process.exit(0)", "$FILE"],
|
||||
extensions: [entry.extension],
|
||||
},
|
||||
},
|
||||
(formatter, directory) =>
|
||||
Effect.gen(function* () {
|
||||
expect(yield* formatter.file(path.join(directory, entry.file))).toBe(entry.matches)
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
it.live("does not run formatters marked as disabled in config", () =>
|
||||
withFormatter(
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue