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);
expect(result.length).toBe(1);
expect(result[0].message).toSatisfy((v: string) => v.includes("Expecting 'SPACE'"));
expect(result[0]).toMatchObject({
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 () => {
@ -35,11 +34,10 @@ describe("Mermaid linter", () => {
`;
const result = await validateMermaid(input);
expect(result.length).toBe(1);
expect(result[0].message).toSatisfy((v: string) => v.includes("Expecting 'ARROW_DELIMITER'"));
expect(result[0]).toMatchObject({
expect(result).toMatchObject([{
message: "Expecting 'ARROW_DELIMITER', got 'MINUS'",
from: { line: 3, col: 8 },
to: { line: 3, col: 9 }
});
}]);
});
});

View File

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