mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 07:28:59 +01:00
feat(linter/mermaid): better handling of zero position
This commit is contained in:
parent
5d8ac3b9f7
commit
8b08e67fdc
@ -21,22 +21,25 @@ describe("Mermaid linter", () => {
|
|||||||
expect(result[0].message).toSatisfy((v: string) => v.includes("Expecting 'SPACE'"));
|
expect(result[0].message).toSatisfy((v: string) => v.includes("Expecting 'SPACE'"));
|
||||||
expect(result[0]).toMatchObject({
|
expect(result[0]).toMatchObject({
|
||||||
from: { line: 0, col: 0 },
|
from: { line: 0, col: 0 },
|
||||||
to: { line: 0, col: 0 }
|
to: { line: 0, col: 1 }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports correctly basic arrow missing in diagram", async () => {
|
it("reports correctly basic arrow missing in diagram", async () => {
|
||||||
const input = trimIndentation`\
|
const input = trimIndentation`\
|
||||||
stateDiagram-v2
|
xychart-beta horizontal
|
||||||
[*] -> Still
|
title "Percentage usge"
|
||||||
|
x-axis [data, sys, usr, var]
|
||||||
|
y-axis 0--->100
|
||||||
|
bar [20, 70, 0, 0]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const result = await validateMermaid(input);
|
const result = await validateMermaid(input);
|
||||||
expect(result.length).toBe(1);
|
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({
|
expect(result[0]).toMatchObject({
|
||||||
from: { line: 1, col: 0 },
|
from: { line: 3, col: 8 },
|
||||||
to: { line: 1, col: 3 }
|
to: { line: 3, col: 9 }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -31,12 +31,12 @@ export async function validateMermaid(text: string) {
|
|||||||
|
|
||||||
const mermaidError = (e as MermaidParseError);
|
const mermaidError = (e as MermaidParseError);
|
||||||
const loc = mermaidError.hash.loc;
|
const loc = mermaidError.hash.loc;
|
||||||
let firstCol = loc.first_column;
|
|
||||||
let lastCol = loc.last_column;
|
|
||||||
|
|
||||||
if (firstCol !== 0 && lastCol !== 0) {
|
let firstCol = loc.first_column + 1;
|
||||||
firstCol = lastCol + 1;
|
let lastCol = loc.last_column + 1;
|
||||||
lastCol = firstCol + 1;
|
|
||||||
|
if (firstCol === 1 && lastCol === 1) {
|
||||||
|
firstCol = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user