mirror of
https://github.com/zadam/trilium.git
synced 2025-10-26 07:46:30 +01:00
feat(linter/mermaid): better handling of zero position
This commit is contained in:
@@ -21,22 +21,25 @@ describe("Mermaid linter", () => {
|
||||
expect(result[0].message).toSatisfy((v: string) => v.includes("Expecting 'SPACE'"));
|
||||
expect(result[0]).toMatchObject({
|
||||
from: { line: 0, col: 0 },
|
||||
to: { line: 0, col: 0 }
|
||||
to: { line: 0, col: 1 }
|
||||
});
|
||||
});
|
||||
|
||||
it("reports correctly basic arrow missing in diagram", async () => {
|
||||
const input = trimIndentation`\
|
||||
stateDiagram-v2
|
||||
[*] -> Still
|
||||
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.length).toBe(1);
|
||||
expect(result[0].message).toSatisfy((v: string) => v.includes("Expecting 'SPACE'"));
|
||||
expect(result[0].message).toSatisfy((v: string) => v.includes("Expecting 'ARROW_DELIMITER'"));
|
||||
expect(result[0]).toMatchObject({
|
||||
from: { line: 1, col: 0 },
|
||||
to: { line: 1, col: 3 }
|
||||
from: { line: 3, col: 8 },
|
||||
to: { line: 3, col: 9 }
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,12 +31,12 @@ export async function validateMermaid(text: string) {
|
||||
|
||||
const mermaidError = (e as MermaidParseError);
|
||||
const loc = mermaidError.hash.loc;
|
||||
let firstCol = loc.first_column;
|
||||
let lastCol = loc.last_column;
|
||||
|
||||
if (firstCol !== 0 && lastCol !== 0) {
|
||||
firstCol = lastCol + 1;
|
||||
lastCol = firstCol + 1;
|
||||
let firstCol = loc.first_column + 1;
|
||||
let lastCol = loc.last_column + 1;
|
||||
|
||||
if (firstCol === 1 && lastCol === 1) {
|
||||
firstCol = 0;
|
||||
}
|
||||
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user