2025-03-09 21:38:16 +02:00
|
|
|
export async function lint(code: string, mimeType: string) {
|
2025-03-08 02:37:29 +02:00
|
|
|
|
|
|
|
const Linter = (await import("eslint-linter-browserify")).Linter;
|
2025-03-08 02:45:40 +02:00
|
|
|
const js = (await import("@eslint/js"));
|
2025-03-09 21:38:16 +02:00
|
|
|
const globalDefinitions = (await import("globals"));
|
|
|
|
|
|
|
|
let globals: Record<string, any> = {
|
|
|
|
...globalDefinitions.browser,
|
2025-03-09 21:41:13 +02:00
|
|
|
api: "readonly",
|
|
|
|
module: "readonly"
|
2025-03-09 21:38:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (mimeType === "application/javascript;env=frontend") {
|
|
|
|
globals = { ...globals, ...globalDefinitions.jquery };
|
|
|
|
} else if (mimeType === "application/javascript;env=backend") {
|
|
|
|
|
|
|
|
}
|
2025-03-08 02:37:29 +02:00
|
|
|
|
2025-03-08 02:45:40 +02:00
|
|
|
return new Linter().verify(code, [
|
|
|
|
js.configs.recommended,
|
|
|
|
{
|
|
|
|
languageOptions: {
|
|
|
|
parserOptions: {
|
|
|
|
ecmaVersion: 2024
|
|
|
|
},
|
2025-03-09 21:38:16 +02:00
|
|
|
globals
|
2025-03-08 02:45:40 +02:00
|
|
|
},
|
2025-03-08 03:02:25 +02:00
|
|
|
rules: {
|
|
|
|
"no-unused-vars": [ "warn", { vars: "local", args: "after-used" }]
|
|
|
|
}
|
2025-03-08 02:45:40 +02:00
|
|
|
}
|
|
|
|
]);
|
2025-03-08 02:37:29 +02:00
|
|
|
|
|
|
|
}
|