feat(linter/mermaid): improve parsing of messages

This commit is contained in:
Elian Doran 2025-03-22 01:30:57 +02:00
parent 8b08e67fdc
commit d4cd550b7a
No known key found for this signature in database
2 changed files with 12 additions and 9 deletions

View File

@ -17,12 +17,11 @@ describe("Mermaid linter", () => {
`; `;
const result = await validateMermaid(input); const result = await validateMermaid(input);
expect(result.length).toBe(1); expect(result).toMatchObject([{
expect(result[0].message).toSatisfy((v: string) => v.includes("Expecting 'SPACE'")); message: "Expecting 'SPACE', 'NL', 'SD', got 'ID'",
expect(result[0]).toMatchObject({
from: { line: 0, col: 0 }, from: { line: 0, col: 0 },
to: { line: 0, col: 1 } to: { line: 0, col: 1 }
}); }]);
}); });
it("reports correctly basic arrow missing in diagram", async () => { it("reports correctly basic arrow missing in diagram", async () => {
@ -35,11 +34,10 @@ describe("Mermaid linter", () => {
`; `;
const result = await validateMermaid(input); const result = await validateMermaid(input);
expect(result.length).toBe(1); expect(result).toMatchObject([{
expect(result[0].message).toSatisfy((v: string) => v.includes("Expecting 'ARROW_DELIMITER'")); message: "Expecting 'ARROW_DELIMITER', got 'MINUS'",
expect(result[0]).toMatchObject({
from: { line: 3, col: 8 }, from: { line: 3, col: 8 },
to: { line: 3, col: 9 } to: { line: 3, col: 9 }
}); }]);
}); });
}); });

View File

@ -39,9 +39,14 @@ export async function validateMermaid(text: string) {
firstCol = 0; firstCol = 0;
} }
let messageLines = mermaidError.message.split("\n");
if (messageLines.length >= 4) {
messageLines = messageLines.slice(3);
}
return [ return [
{ {
message: mermaidError.message, message: messageLines.join("\n"),
severity: "error", severity: "error",
from: CodeMirror.Pos(loc.first_line - 1, firstCol), from: CodeMirror.Pos(loc.first_line - 1, firstCol),
to: CodeMirror.Pos(loc.last_line - 1, lastCol) to: CodeMirror.Pos(loc.last_line - 1, lastCol)