mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 23:09:49 +02:00
Linting
This commit is contained in:
@@ -1,21 +1,21 @@
|
|||||||
import type { ValidationAcceptor, ValidationChecks } from 'langium';
|
import type { ValidationAcceptor, ValidationChecks } from 'langium';
|
||||||
import type { MermaidAstType, MindmapDoc } from '../generated/ast.js';
|
import type { MermaidAstType, MindmapDoc, MindmapRow } from '../generated/ast.js';
|
||||||
import type { MindmapServices } from './module.js';
|
import type { MindmapServices } from './module.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register custom validation checks.
|
* Register custom validation checks.
|
||||||
*/
|
*/
|
||||||
export function registerValidationChecks(services: MindmapServices) {
|
export function registerValidationChecks(services: MindmapServices) {
|
||||||
console.debug('MindmapValidator registerValidationChecks');
|
|
||||||
const validator = services.validation.MindmapValidator;
|
const validator = services.validation.MindmapValidator;
|
||||||
const registry = services.validation.ValidationRegistry;
|
const registry = services.validation.ValidationRegistry;
|
||||||
if (registry) {
|
if (registry) {
|
||||||
console.debug('MindmapValidator registerValidationChecks registry');
|
|
||||||
// Use any to bypass type checking since we know MindmapDoc is part of the AST
|
// Use any to bypass type checking since we know MindmapDoc is part of the AST
|
||||||
// but the type system is having trouble with it
|
// but the type system is having trouble with it
|
||||||
const checks: ValidationChecks<MermaidAstType> = {
|
const checks: ValidationChecks<MermaidAstType> = {
|
||||||
MindmapDoc: validator.checkSingleRoot,
|
MindmapDoc: validator.checkSingleRoot.bind(validator),
|
||||||
MindmapRow: validator.checkSingleRootRow,
|
MindmapRow: (node: MindmapRow, accept: ValidationAcceptor) => {
|
||||||
|
validator.checkSingleRootRow(node, accept);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
registry.register(checks, validator);
|
registry.register(checks, validator);
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ export class MindmapValidator {
|
|||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.debug('MindmapValidator constructor');
|
console.debug('MindmapValidator constructor');
|
||||||
}
|
}
|
||||||
checkSingleRootRow(_doc: MindmapDoc, _accept: ValidationAcceptor): void {
|
checkSingleRootRow(_node: MindmapRow, _accept: ValidationAcceptor): void {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.debug('CHECKING SINGLE ROOT Row');
|
console.debug('CHECKING SINGLE ROOT Row');
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,6 @@ export class MindmapValidator {
|
|||||||
let rootNodeIndentation;
|
let rootNodeIndentation;
|
||||||
|
|
||||||
for (const row of doc.MindmapRows) {
|
for (const row of doc.MindmapRows) {
|
||||||
console.debug('ROW BY ROW', row.indent);
|
|
||||||
// Skip non-node items (e.g., class decorations, icon decorations)
|
// Skip non-node items (e.g., class decorations, icon decorations)
|
||||||
if (
|
if (
|
||||||
!row.item ||
|
!row.item ||
|
||||||
@@ -59,14 +58,15 @@ export class MindmapValidator {
|
|||||||
) {
|
) {
|
||||||
rootNodeIndentation = 0;
|
rootNodeIndentation = 0;
|
||||||
} else if (row.indent === undefined) {
|
} else if (row.indent === undefined) {
|
||||||
// console.debug('FAIL 1', rootNodeIndentation, row.indent);
|
|
||||||
// If we've already found a root node, report an error
|
// If we've already found a root node, report an error
|
||||||
accept('error', 'Multiple root nodes are not allowed in a mindmap.', {
|
accept('error', 'Multiple root nodes are not allowed in a mindmap.', {
|
||||||
node: row,
|
node: row,
|
||||||
property: 'item',
|
property: 'item',
|
||||||
});
|
});
|
||||||
} else if (rootNodeIndentation >= row.indent) {
|
} else if (
|
||||||
// console.debug('FAIL 2', rootNodeIndentation, row.indent, row.item);
|
rootNodeIndentation !== undefined &&
|
||||||
|
rootNodeIndentation >= parseInt(row.indent, 10)
|
||||||
|
) {
|
||||||
accept('error', 'Multiple root nodes are not allowed in a mindmap.', {
|
accept('error', 'Multiple root nodes are not allowed in a mindmap.', {
|
||||||
node: row,
|
node: row,
|
||||||
property: 'item',
|
property: 'item',
|
||||||
|
Reference in New Issue
Block a user