From c597ad7694bc2f6e2be37332729ab89b267301fd Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 28 May 2025 21:15:55 +0300 Subject: [PATCH] chore(client): remove unused linter for now --- .../type_widgets/linters/mermaid.spec.ts | 43 -------------- .../widgets/type_widgets/linters/mermaid.ts | 58 ------------------- 2 files changed, 101 deletions(-) delete mode 100644 apps/client/src/widgets/type_widgets/linters/mermaid.spec.ts delete mode 100644 apps/client/src/widgets/type_widgets/linters/mermaid.ts diff --git a/apps/client/src/widgets/type_widgets/linters/mermaid.spec.ts b/apps/client/src/widgets/type_widgets/linters/mermaid.spec.ts deleted file mode 100644 index 638892d71..000000000 --- a/apps/client/src/widgets/type_widgets/linters/mermaid.spec.ts +++ /dev/null @@ -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 } - }]); - }); -}); diff --git a/apps/client/src/widgets/type_widgets/linters/mermaid.ts b/apps/client/src/widgets/type_widgets/linters/mermaid.ts deleted file mode 100644 index e0773e652..000000000 --- a/apps/client/src/widgets/type_widgets/linters/mermaid.ts +++ /dev/null @@ -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 []; -}