Compare commits

...
Author SHA1 Message Date
Kit Langton c71a86a0e8 refactor(core): reuse formatter file extension 2026-08-28 23:48:07 -04:00
2 changed files with 30 additions and 3 deletions
+2 -3
View File
@@ -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)
+28
View File
@@ -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(
{