mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01: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 [];
 | 
					            return [];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const errors = await glob.linter(text);
 | 
					        const errors = await glob.linter(text, glob.getActiveContextNote().mime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        console.log(errors);
 | 
					        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 Linter = (await import("eslint-linter-browserify")).Linter;
 | 
				
			||||||
    const js = (await import("@eslint/js"));
 | 
					    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, [
 | 
					    return new Linter().verify(code, [
 | 
				
			||||||
        js.configs.recommended,
 | 
					        js.configs.recommended,
 | 
				
			||||||
@ -11,10 +22,7 @@ export async function lint(code: string) {
 | 
				
			|||||||
                parserOptions: {
 | 
					                parserOptions: {
 | 
				
			||||||
                    ecmaVersion: 2024
 | 
					                    ecmaVersion: 2024
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                globals: {
 | 
					                globals
 | 
				
			||||||
                    ...globals.browser,
 | 
					 | 
				
			||||||
                    api: "readonly"
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            rules: {
 | 
					            rules: {
 | 
				
			||||||
                "no-unused-vars": [ "warn", { vars: "local", args: "after-used" }]
 | 
					                "no-unused-vars": [ "warn", { vars: "local", args: "after-used" }]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user