|
|
|
|
@ -1,8 +1,19 @@
|
|
|
|
|
export async function lint(code: string) {
|
|
|
|
|
export async function lint(code: string, mimeType: string) {
|
|
|
|
|
|
|
|
|
|
const Linter = (await import("eslint-linter-browserify")).Linter;
|
|
|
|
|
const js = (await import("@eslint/js"));
|
|
|
|
|
const globals = (await import("globals"));
|
|
|
|
|
const globalDefinitions = (await import("globals"));
|
|
|
|
|
|
|
|
|
|
let globals: Record<string, any> = {
|
|
|
|
|
...globalDefinitions.browser,
|
|
|
|
|
api: "readonly"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (mimeType === "application/javascript;env=frontend") {
|
|
|
|
|
globals = { ...globals, ...globalDefinitions.jquery };
|
|
|
|
|
} else if (mimeType === "application/javascript;env=backend") {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Linter().verify(code, [
|
|
|
|
|
js.configs.recommended,
|
|
|
|
|
@ -11,10 +22,7 @@ export async function lint(code: string) {
|
|
|
|
|
parserOptions: {
|
|
|
|
|
ecmaVersion: 2024
|
|
|
|
|
},
|
|
|
|
|
globals: {
|
|
|
|
|
...globals.browser,
|
|
|
|
|
api: "readonly"
|
|
|
|
|
},
|
|
|
|
|
globals
|
|
|
|
|
},
|
|
|
|
|
rules: {
|
|
|
|
|
"no-unused-vars": [ "warn", { vars: "local", args: "after-used" }]
|
|
|
|
|
|