mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 21:19:01 +01:00 
			
		
		
		
	chore(client): remove unused linter for now
This commit is contained in:
		
							parent
							
								
									395bc372ce
								
							
						
					
					
						commit
						c597ad7694
					
				@ -1,43 +0,0 @@
 | 
				
			|||||||
import { describe, expect, it } from "vitest";
 | 
					 | 
				
			||||||
import { trimIndentation } from "@triliumnext/commons";
 | 
					 | 
				
			||||||
import { validateMermaid } from "./mermaid.js";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
describe("Mermaid linter", () => {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    (global as any).CodeMirror = {
 | 
					 | 
				
			||||||
        Pos(line: number, col: number) {
 | 
					 | 
				
			||||||
            return { line, col };
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    it("reports correctly bad diagram type", async () => {
 | 
					 | 
				
			||||||
        const input = trimIndentation`\
 | 
					 | 
				
			||||||
            stateDiagram-v23
 | 
					 | 
				
			||||||
            [*] -> Still
 | 
					 | 
				
			||||||
        `;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const result = await validateMermaid(input);
 | 
					 | 
				
			||||||
        expect(result).toMatchObject([{
 | 
					 | 
				
			||||||
            message: "Expecting 'SPACE', 'NL', 'SD', got 'ID'",
 | 
					 | 
				
			||||||
            from: { line: 0, col: 0 },
 | 
					 | 
				
			||||||
            to: { line: 0, col: 1 }
 | 
					 | 
				
			||||||
        }]);
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    it("reports correctly basic arrow missing in diagram", async () => {
 | 
					 | 
				
			||||||
        const input = trimIndentation`\
 | 
					 | 
				
			||||||
            xychart-beta horizontal
 | 
					 | 
				
			||||||
            title "Percentage usge"
 | 
					 | 
				
			||||||
            x-axis [data, sys, usr, var]
 | 
					 | 
				
			||||||
            y-axis 0--->100
 | 
					 | 
				
			||||||
            bar [20, 70, 0, 0]
 | 
					 | 
				
			||||||
        `;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const result = await validateMermaid(input);
 | 
					 | 
				
			||||||
        expect(result).toMatchObject([{
 | 
					 | 
				
			||||||
            message: "Expecting 'ARROW_DELIMITER', got 'MINUS'",
 | 
					 | 
				
			||||||
            from: { line: 3, col: 8 },
 | 
					 | 
				
			||||||
            to: { line: 3, col: 9 }
 | 
					 | 
				
			||||||
        }]);
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
@ -1,58 +0,0 @@
 | 
				
			|||||||
import mermaid from "mermaid";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
interface MermaidParseError extends Error {
 | 
					 | 
				
			||||||
    hash: {
 | 
					 | 
				
			||||||
        text: string;
 | 
					 | 
				
			||||||
        token: string;
 | 
					 | 
				
			||||||
        line: number;
 | 
					 | 
				
			||||||
        loc: {
 | 
					 | 
				
			||||||
            first_line: number;
 | 
					 | 
				
			||||||
            first_column: number;
 | 
					 | 
				
			||||||
            last_line: number;
 | 
					 | 
				
			||||||
            last_column: number;
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
        expected: string[]
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export default function registerErrorReporter() {
 | 
					 | 
				
			||||||
    CodeMirror.registerHelper("lint", null, validateMermaid);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export async function validateMermaid(text: string) {
 | 
					 | 
				
			||||||
    if (!text.trim()) {
 | 
					 | 
				
			||||||
        return [];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    try {
 | 
					 | 
				
			||||||
        await mermaid.parse(text);
 | 
					 | 
				
			||||||
    } catch (e: unknown) {
 | 
					 | 
				
			||||||
        console.warn("Got validation error", JSON.stringify(e));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const mermaidError = (e as MermaidParseError);
 | 
					 | 
				
			||||||
        const loc = mermaidError.hash.loc;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        let firstCol = loc.first_column + 1;
 | 
					 | 
				
			||||||
        let lastCol = loc.last_column + 1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (firstCol === 1 && lastCol === 1) {
 | 
					 | 
				
			||||||
            firstCol = 0;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        let messageLines = mermaidError.message.split("\n");
 | 
					 | 
				
			||||||
        if (messageLines.length >= 4) {
 | 
					 | 
				
			||||||
            messageLines = messageLines.slice(3);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return [
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                message: messageLines.join("\n"),
 | 
					 | 
				
			||||||
                severity: "error",
 | 
					 | 
				
			||||||
                from: CodeMirror.Pos(loc.first_line - 1, firstCol),
 | 
					 | 
				
			||||||
                to: CodeMirror.Pos(loc.last_line - 1, lastCol)
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        ];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return [];
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user