2025-05-11 15:33:46 +03:00
|
|
|
import type { Linter } from "eslint-linter-browserify";
|
|
|
|
|
2025-05-11 15:18:42 +03:00
|
|
|
export async function lint(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
|
|
|
};
|
|
|
|
|
2025-03-24 19:17:45 +02:00
|
|
|
// Unsupported languages
|
|
|
|
if (mimeType.startsWith("text/typescript")) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Custom globals
|
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-05-11 15:33:46 +03:00
|
|
|
const config: (Linter.LegacyConfig | Linter.Config | Linter.Config[]) = [
|
2025-03-08 02:45:40 +02:00
|
|
|
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-05-11 15:33:46 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
return {
|
|
|
|
linter: new Linter(),
|
|
|
|
config
|
2025-05-11 15:18:42 +03:00
|
|
|
}
|
2025-03-08 02:37:29 +02:00
|
|
|
}
|