mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
feat(eslint): add globals for jQuery
This commit is contained in:
parent
064799e8cb
commit
1fb4634b7b
2
libraries/codemirror/eslint.js
vendored
2
libraries/codemirror/eslint.js
vendored
@ -41,7 +41,7 @@
|
||||
return [];
|
||||
}
|
||||
|
||||
const errors = await glob.linter(text);
|
||||
const errors = await glob.linter(text, glob.getActiveContextNote().mime);
|
||||
|
||||
console.log(errors);
|
||||
|
||||
|
@ -45,4 +45,9 @@ describe("Linter", () => {
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("supports JQuery global", async () => {
|
||||
expect(await lint(`$("<div>");`, "application/javascript;env=backend")).toMatchObject([{ "ruleId": "no-undef" }]);
|
||||
expect(await lint(`console.log($("<div>"));`, "application/javascript;env=frontend")).toStrictEqual([]);
|
||||
});
|
||||
});
|
||||
|
@ -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" }]
|
||||
|
Loading…
x
Reference in New Issue
Block a user