refactor(diffs): drop unused language hint filter

This commit is contained in:
Vincent Koc
2026-06-19 12:17:45 +08:00
parent 8888bca752
commit a25c64a4e4
2 changed files with 18 additions and 20 deletions

View File

@@ -2,13 +2,17 @@
import type { FileDiffMetadata } from "@pierre/diffs";
import { describe, expect, it } from "vitest";
import {
filterSupportedLanguageHints,
normalizeDiffViewerPayloadLanguages,
normalizeSupportedLanguageHint,
} from "./language-hints.js";
describe("filterSupportedLanguageHints", () => {
async function normalizeHints(values: readonly string[], options = {}) {
return await Promise.all(values.map((value) => normalizeSupportedLanguageHint(value, options)));
}
describe("normalizeSupportedLanguageHint", () => {
it("keeps supported languages", async () => {
await expect(filterSupportedLanguageHints(["typescript", "cpp", "text"])).resolves.toEqual([
await expect(normalizeHints(["typescript", "cpp", "text"])).resolves.toEqual([
"typescript",
"cpp",
"text",
@@ -17,7 +21,7 @@ describe("filterSupportedLanguageHints", () => {
it("normalizes common aliases to base viewer languages", async () => {
await expect(
filterSupportedLanguageHints(["ts", "c++", "c#", "bash", "dockerfile", "rb", "kt", "ps1"]),
normalizeHints(["ts", "c++", "c#", "bash", "dockerfile", "rb", "kt", "ps1"]),
).resolves.toEqual([
"typescript",
"cpp",
@@ -32,7 +36,7 @@ describe("filterSupportedLanguageHints", () => {
it("keeps mainstream languages in the base viewer without the language pack", async () => {
await expect(
filterSupportedLanguageHints([
normalizeHints([
"ruby",
"swift",
"kotlin",
@@ -57,23 +61,24 @@ describe("filterSupportedLanguageHints", () => {
});
it("drops uncommon languages without the language pack", async () => {
await expect(filterSupportedLanguageHints(["abap"])).resolves.toEqual(["text"]);
await expect(normalizeSupportedLanguageHint("abap")).resolves.toBeUndefined();
});
it("keeps uncommon languages when the language pack is available", async () => {
await expect(
filterSupportedLanguageHints(["abap"], { languagePackAvailable: true }),
).resolves.toEqual(["abap"]);
normalizeSupportedLanguageHint("abap", { languagePackAvailable: true }),
).resolves.toBe("abap");
});
it("drops invalid languages and falls back to text", async () => {
await expect(filterSupportedLanguageHints(["not-a-real-language"])).resolves.toEqual(["text"]);
it("drops invalid languages", async () => {
await expect(normalizeSupportedLanguageHint("not-a-real-language")).resolves.toBeUndefined();
});
it("keeps valid languages when invalid hints are mixed in", async () => {
await expect(
filterSupportedLanguageHints(["typescript", "not-a-real-language"]),
).resolves.toEqual(["typescript"]);
await expect(normalizeHints(["typescript", "not-a-real-language"])).resolves.toEqual([
"typescript",
undefined,
]);
});
});

View File

@@ -57,13 +57,6 @@ export async function normalizeSupportedLanguageHint(
}
}
export async function filterSupportedLanguageHints(
values: Iterable<string>,
options: { languagePackAvailable?: boolean } = {},
): Promise<SupportedLanguages[]> {
return normalizeSupportedLanguageHints(values, { fallbackToText: true, ...options });
}
async function normalizeSupportedLanguageHints(
values: Iterable<string>,
options: { fallbackToText: boolean; languagePackAvailable?: boolean },