litellm/ui/litellm-dashboard/tests/fetch-location-rule.test.ts
yuneng-jiang 6162ebab85
build(ui): fail lint on hardcoded English in dashboard JSX (#50593)
* build(ui): fail lint on hardcoded English in dashboard JSX

Adds eslint-plugin-i18next no-literal-string in jsx-only mode with type info for dashboard source files, skipping tests and the two untranslated files, plus a no-restricted-syntax selector that rejects an English literal as the first argument to toast.success, error, warning or info.

* test(ui): lint the fetch rule fixture at a real source path

Type-aware linting needs the file to be in the TypeScript project, so a virtual path under src now fails to parse and no rule runs. The fixture now uses src/app/layout.tsx with the same code and assertions.
2026-11-09 12:40:40 -08:00

30 lines
1,008 B
TypeScript

import { describe, it, expect, beforeAll } from "vitest";
import { ESLint } from "eslint";
const FETCH_CODE = `export const load = async () => {\n const res = await fetch("/api/thing");\n return res.json();\n};\n`;
const RULE_ID = "no-restricted-syntax";
let eslint: ESLint;
const fetchMessages = async (filePath: string) => {
const [result] = await eslint.lintText(FETCH_CODE, { filePath });
return result.messages.filter((m) => m.ruleId === RULE_ID);
};
describe("location-based fetch() rule", () => {
beforeAll(() => {
eslint = new ESLint();
});
it("flags a raw fetch() in a normal source file", async () => {
const messages = await fetchMessages("src/app/layout.tsx");
expect(messages).toHaveLength(1);
expect(messages[0].message).toMatch(/@\/lib\/http\/client/);
});
it("allows fetch() inside src/lib/http/ (the one place it lives)", async () => {
const messages = await fetchMessages("src/lib/http/client.ts");
expect(messages).toHaveLength(0);
});
});