mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 03:29:02 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import type { Linter } from "eslint-linter-browserify";
 | |
| 
 | |
| export async function lint(mimeType: string) {
 | |
| 
 | |
|     const Linter = (await import("eslint-linter-browserify")).Linter;
 | |
|     const js = (await import("@eslint/js"));
 | |
|     const globalDefinitions = (await import("globals"));
 | |
| 
 | |
|     let globals: Record<string, any> = {
 | |
|         ...globalDefinitions.browser,
 | |
|         api: "readonly",
 | |
|         module: "readonly"
 | |
|     };
 | |
| 
 | |
|     // Unsupported languages
 | |
|     if (mimeType.startsWith("text/typescript")) {
 | |
|         return [];
 | |
|     }
 | |
| 
 | |
|     // Custom globals
 | |
|     if (mimeType === "application/javascript;env=frontend") {
 | |
|         globals = { ...globals, ...globalDefinitions.jquery };
 | |
|     } else if (mimeType === "application/javascript;env=backend") {
 | |
| 
 | |
|     }
 | |
| 
 | |
|     const config: (Linter.LegacyConfig | Linter.Config | Linter.Config[]) = [
 | |
|         js.configs.recommended,
 | |
|         {
 | |
|             languageOptions: {
 | |
|                 parserOptions: {
 | |
|                     ecmaVersion: 2024
 | |
|                 },
 | |
|                 globals
 | |
|             },
 | |
|             rules: {
 | |
|                 "no-unused-vars": [ "warn", { vars: "local", args: "after-used" }]
 | |
|             }
 | |
|         }
 | |
|     ];
 | |
| 
 | |
|     return {
 | |
|         linter: new Linter(),
 | |
|         config
 | |
|     }
 | |
| }
 | 
