mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
chore: Fix eslint issues
This commit is contained in:
parent
d9b2934a50
commit
1fad9e6eef
@ -16,7 +16,7 @@
|
||||
|
||||
#### Defined in
|
||||
|
||||
[packages/mermaid/src/utils.ts:789](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/utils.ts#L789)
|
||||
[packages/mermaid/src/utils.ts:785](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/utils.ts#L785)
|
||||
|
||||
---
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
|
||||
#### Defined in
|
||||
|
||||
[packages/mermaid/src/utils.ts:787](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/utils.ts#L787)
|
||||
[packages/mermaid/src/utils.ts:783](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/utils.ts#L783)
|
||||
|
||||
---
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
|
||||
#### Defined in
|
||||
|
||||
[packages/mermaid/src/utils.ts:790](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/utils.ts#L790)
|
||||
[packages/mermaid/src/utils.ts:786](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/utils.ts#L786)
|
||||
|
||||
---
|
||||
|
||||
@ -46,4 +46,4 @@
|
||||
|
||||
#### Defined in
|
||||
|
||||
[packages/mermaid/src/utils.ts:785](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/utils.ts#L785)
|
||||
[packages/mermaid/src/utils.ts:781](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/utils.ts#L781)
|
||||
|
@ -44,7 +44,7 @@
|
||||
|
||||
#### Defined in
|
||||
|
||||
[packages/mermaid/src/Diagram.ts:9](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/Diagram.ts#L9)
|
||||
[packages/mermaid/src/Diagram.ts:10](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/Diagram.ts#L10)
|
||||
|
||||
## Variables
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
import type { Mocked } from 'vitest';
|
||||
import type { SVG } from '../diagram-api/types.js';
|
||||
import { addEdgeMarkers } from './edgeMarker.js';
|
||||
|
@ -26,12 +26,16 @@ const Identification = {
|
||||
NON_IDENTIFYING: 'NON_IDENTIFYING',
|
||||
IDENTIFYING: 'IDENTIFYING',
|
||||
};
|
||||
|
||||
/**
|
||||
* Add entity
|
||||
* @param {string} name - The name of the entity
|
||||
* @param {string | undefined} alias - The alias of the entity
|
||||
*/
|
||||
const addEntity = function (name, alias = undefined) {
|
||||
if (!entities.has(name)) {
|
||||
entities.set(name, { attributes: [], alias: alias });
|
||||
entities.set(name, { attributes: [], alias });
|
||||
log.info('Added new entity :', name);
|
||||
} else if (entities.has(name) && !entities.get(name).alias && alias) {
|
||||
} else if (!entities.get(name).alias && alias) {
|
||||
entities.get(name).alias = alias;
|
||||
log.info(`Add alias '${alias}' to entity '${name}'`);
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||
import { addToRender } from './flowChartShapes.js';
|
||||
|
||||
describe('flowchart shapes', function () {
|
||||
|
@ -420,14 +420,13 @@ export const draw = async function (text, id, _version, diagObj) {
|
||||
log.info('Edges', edges);
|
||||
let i = 0;
|
||||
for (i = subGraphs.length - 1; i >= 0; i--) {
|
||||
// for (let i = 0; i < subGraphs.length; i++) {
|
||||
subG = subGraphs[i];
|
||||
|
||||
selectAll('cluster').append('text');
|
||||
|
||||
for (let j = 0; j < subG.nodes.length; j++) {
|
||||
log.info('Setting up subgraphs', subG.nodes[j], subG.id);
|
||||
g.setParent(subG.nodes[j], subG.id);
|
||||
for (const node of subG.nodes) {
|
||||
log.info('Setting up subgraphs', node, subG.id);
|
||||
g.setParent(node, subG.id);
|
||||
}
|
||||
}
|
||||
await addVertices(vert, g, id, root, doc, diagObj);
|
||||
|
@ -339,14 +339,14 @@ export const draw = async function (text, id, _version, diagObj) {
|
||||
|
||||
selectAll('cluster').append('text');
|
||||
|
||||
for (let j = 0; j < subG.nodes.length; j++) {
|
||||
for (const node of subG.nodes) {
|
||||
log.warn(
|
||||
'Setting subgraph',
|
||||
subG.nodes[j],
|
||||
diagObj.db.lookUpDomId(subG.nodes[j]),
|
||||
node,
|
||||
diagObj.db.lookUpDomId(node),
|
||||
diagObj.db.lookUpDomId(subG.id)
|
||||
);
|
||||
g.setParent(diagObj.db.lookUpDomId(subG.nodes[j]), diagObj.db.lookUpDomId(subG.id));
|
||||
g.setParent(diagObj.db.lookUpDomId(node), diagObj.db.lookUpDomId(subG.id));
|
||||
}
|
||||
}
|
||||
await addVertices(vert, g, id, root, doc, diagObj);
|
||||
@ -429,8 +429,8 @@ export const draw = async function (text, id, _version, diagObj) {
|
||||
te.attr('transform', `translate(${xPos + _width / 2}, ${yPos + 14})`);
|
||||
te.attr('id', id + 'Text');
|
||||
|
||||
for (let j = 0; j < subG.classes.length; j++) {
|
||||
clusterEl[0].classList.add(subG.classes[j]);
|
||||
for (const className of subG.classes) {
|
||||
clusterEl[0].classList.add(className);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||
import { addVertices, addEdges } from './flowRenderer.js';
|
||||
import { setConfig } from '../../diagram-api/diagramAPI.js';
|
||||
|
||||
|
@ -119,6 +119,7 @@ export const draw: DrawDefinition = (text, id, _version, diagObj) => {
|
||||
return ((datum.data.value / sum) * 100).toFixed(0) + '%';
|
||||
})
|
||||
.attr('transform', (datum: d3.PieArcDatum<D3Section>): string => {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
||||
return 'translate(' + labelArcGenerator.centroid(datum) + ')';
|
||||
})
|
||||
.style('text-anchor', 'middle')
|
||||
|
@ -1519,7 +1519,7 @@ describe('when checking the bounds in a sequenceDiagram', function () {
|
||||
diagram.renderer.bounds.init();
|
||||
conf = diagram.db.getConfig();
|
||||
});
|
||||
it('should handle a simple bound call', async () => {
|
||||
it('should handle a simple bound call', () => {
|
||||
diagram.renderer.bounds.insert(100, 100, 200, 200);
|
||||
|
||||
const { bounds } = diagram.renderer.bounds.getBounds();
|
||||
@ -1528,7 +1528,7 @@ describe('when checking the bounds in a sequenceDiagram', function () {
|
||||
expect(bounds.stopx).toBe(200);
|
||||
expect(bounds.stopy).toBe(200);
|
||||
});
|
||||
it('should handle an expanding bound', async () => {
|
||||
it('should handle an expanding bound', () => {
|
||||
diagram.renderer.bounds.insert(100, 100, 200, 200);
|
||||
diagram.renderer.bounds.insert(25, 50, 300, 400);
|
||||
|
||||
@ -1538,7 +1538,7 @@ describe('when checking the bounds in a sequenceDiagram', function () {
|
||||
expect(bounds.stopx).toBe(300);
|
||||
expect(bounds.stopy).toBe(400);
|
||||
});
|
||||
it('should handle inserts within the bound without changing the outer bounds', async () => {
|
||||
it('should handle inserts within the bound without changing the outer bounds', () => {
|
||||
diagram.renderer.bounds.insert(100, 100, 200, 200);
|
||||
diagram.renderer.bounds.insert(25, 50, 300, 400);
|
||||
diagram.renderer.bounds.insert(125, 150, 150, 200);
|
||||
@ -1549,7 +1549,7 @@ describe('when checking the bounds in a sequenceDiagram', function () {
|
||||
expect(bounds.stopx).toBe(300);
|
||||
expect(bounds.stopy).toBe(400);
|
||||
});
|
||||
it('should handle a loop without expanding the area', async () => {
|
||||
it('should handle a loop without expanding the area', () => {
|
||||
diagram.renderer.bounds.insert(25, 50, 300, 400);
|
||||
diagram.renderer.bounds.verticalPos = 150;
|
||||
diagram.renderer.bounds.newLoop();
|
||||
@ -1570,7 +1570,7 @@ describe('when checking the bounds in a sequenceDiagram', function () {
|
||||
expect(bounds.stopx).toBe(300);
|
||||
expect(bounds.stopy).toBe(400);
|
||||
});
|
||||
it('should handle multiple loops withtout expanding the bounds', async () => {
|
||||
it('should handle multiple loops withtout expanding the bounds', () => {
|
||||
diagram.renderer.bounds.insert(100, 100, 1000, 1000);
|
||||
diagram.renderer.bounds.verticalPos = 200;
|
||||
diagram.renderer.bounds.newLoop();
|
||||
@ -1601,7 +1601,7 @@ describe('when checking the bounds in a sequenceDiagram', function () {
|
||||
expect(bounds.stopx).toBe(1000);
|
||||
expect(bounds.stopy).toBe(1000);
|
||||
});
|
||||
it('should handle a loop that expands the area', async () => {
|
||||
it('should handle a loop that expands the area', () => {
|
||||
diagram.renderer.bounds.insert(100, 100, 200, 200);
|
||||
diagram.renderer.bounds.verticalPos = 200;
|
||||
diagram.renderer.bounds.newLoop();
|
||||
|
@ -495,7 +495,7 @@ const drawMessage = async function (diagram, msgModel, lineStartY: number, diagO
|
||||
}
|
||||
};
|
||||
|
||||
const addActorRenderingData = async function (
|
||||
const addActorRenderingData = function (
|
||||
diagram,
|
||||
actors,
|
||||
createdActors: Map<string, any>,
|
||||
@ -822,7 +822,7 @@ export const draw = async function (_text: string, id: string, _version: string,
|
||||
actorKeys = actorKeys.filter((actorKey) => newActors.has(actorKey));
|
||||
}
|
||||
|
||||
await addActorRenderingData(diagram, actors, createdActors, actorKeys, 0, messages, false);
|
||||
addActorRenderingData(diagram, actors, createdActors, actorKeys, 0, messages, false);
|
||||
const loopWidths = await calculateLoopBounds(messages, actors, maxMessageWidthPerActor, diagObj);
|
||||
|
||||
// The arrow head definition is attached to the svg once
|
||||
@ -1076,7 +1076,7 @@ export const draw = async function (_text: string, id: string, _version: string,
|
||||
box.stopx = box.startx + box.width;
|
||||
box.stopy = box.starty + box.height;
|
||||
box.stroke = 'rgb(0,0,0, 0.5)';
|
||||
await svgDraw.drawBox(diagram, box, conf);
|
||||
svgDraw.drawBox(diagram, box, conf);
|
||||
}
|
||||
|
||||
if (hasBoxes) {
|
||||
@ -1147,7 +1147,7 @@ async function getMaxMessageWidthPerActor(
|
||||
actors: Map<string, any>,
|
||||
messages: any[],
|
||||
diagObj: Diagram
|
||||
): Promise<{ [id: string]: number }> {
|
||||
): Promise<Record<string, number>> {
|
||||
const maxMessageWidthPerActor = {};
|
||||
|
||||
for (const msg of messages) {
|
||||
@ -1581,7 +1581,7 @@ const calculateLoopBounds = async function (messages, actors, _maxWidthPerActor,
|
||||
const lastActorActivationIdx = bounds.activations
|
||||
.map((a) => a.actor)
|
||||
.lastIndexOf(msg.from);
|
||||
delete bounds.activations.splice(lastActorActivationIdx, 1)[0];
|
||||
bounds.activations.splice(lastActorActivationIdx, 1).splice(0, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -115,6 +115,7 @@ export const drawKatex = async function (elem, textData, msgModel = null) {
|
||||
stopx = temp;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
||||
textElem.attr('x', Math.round(startx + Math.abs(startx - stopx) / 2 - dim.width / 2));
|
||||
if (textData.class === 'loopText') {
|
||||
textElem.attr('y', Math.round(starty));
|
||||
@ -325,7 +326,7 @@ export const fixLifeLineHeights = (diagram, actors, actorKeys, conf) => {
|
||||
* @param {any} conf - DrawText implementation discriminator object
|
||||
* @param {boolean} isFooter - If the actor is the footer one
|
||||
*/
|
||||
const drawActorTypeParticipant = async function (elem, actor, conf, isFooter) {
|
||||
const drawActorTypeParticipant = function (elem, actor, conf, isFooter) {
|
||||
const actorY = isFooter ? actor.stopy : actor.starty;
|
||||
const center = actor.x + actor.width / 2;
|
||||
const centerY = actorY + 5;
|
||||
@ -389,7 +390,7 @@ const drawActorTypeParticipant = async function (elem, actor, conf, isFooter) {
|
||||
}
|
||||
}
|
||||
|
||||
await _drawTextCandidateFunc(conf, hasKatex(actor.description))(
|
||||
_drawTextCandidateFunc(conf, hasKatex(actor.description))(
|
||||
actor.description,
|
||||
g,
|
||||
rect.x,
|
||||
@ -410,7 +411,7 @@ const drawActorTypeParticipant = async function (elem, actor, conf, isFooter) {
|
||||
return height;
|
||||
};
|
||||
|
||||
const drawActorTypeActor = async function (elem, actor, conf, isFooter) {
|
||||
const drawActorTypeActor = function (elem, actor, conf, isFooter) {
|
||||
const actorY = isFooter ? actor.stopy : actor.starty;
|
||||
const center = actor.x + actor.width / 2;
|
||||
const centerY = actorY + 80;
|
||||
@ -491,7 +492,7 @@ const drawActorTypeActor = async function (elem, actor, conf, isFooter) {
|
||||
const bounds = actElem.node().getBBox();
|
||||
actor.height = bounds.height;
|
||||
|
||||
await _drawTextCandidateFunc(conf, hasKatex(actor.description))(
|
||||
_drawTextCandidateFunc(conf, hasKatex(actor.description))(
|
||||
actor.description,
|
||||
actElem,
|
||||
rect.x,
|
||||
@ -514,12 +515,12 @@ export const drawActor = async function (elem, actor, conf, isFooter) {
|
||||
}
|
||||
};
|
||||
|
||||
export const drawBox = async function (elem, box, conf) {
|
||||
export const drawBox = function (elem, box, conf) {
|
||||
const boxplusTextGroup = elem.append('g');
|
||||
const g = boxplusTextGroup;
|
||||
drawBackgroundRect(g, box);
|
||||
if (box.name) {
|
||||
await _drawTextCandidateFunc(conf)(
|
||||
_drawTextCandidateFunc(conf)(
|
||||
box.name,
|
||||
g,
|
||||
box.x,
|
||||
|
@ -362,8 +362,7 @@ const setupDoc = (g, parentParsedItem, doc, diagramStates, diagramDb, altFlag) =
|
||||
const getDir = (parsedItem, defaultDir = DEFAULT_NESTED_DOC_DIR) => {
|
||||
let dir = defaultDir;
|
||||
if (parsedItem.doc) {
|
||||
for (let i = 0; i < parsedItem.doc.length; i++) {
|
||||
const parsedItemDoc = parsedItem.doc[i];
|
||||
for (const parsedItemDoc of parsedItem.doc) {
|
||||
if (parsedItemDoc.stmt === 'dir') {
|
||||
dir = parsedItemDoc.value;
|
||||
}
|
||||
|
@ -115,8 +115,7 @@ export const draw = function (text: string, id: string, version: string, diagObj
|
||||
maxEventCount = Math.max(maxEventCount, task.events.length);
|
||||
//calculate maxEventLineLength
|
||||
let maxEventLineLengthTemp = 0;
|
||||
for (let j = 0; j < task.events.length; j++) {
|
||||
const event = task.events[j];
|
||||
for (const event of task.events) {
|
||||
const eventNode = {
|
||||
descr: event,
|
||||
section: task.section,
|
||||
|
@ -9,9 +9,9 @@ const allMarkdownTransformers: MarkdownOptions = {
|
||||
light: 'github-light',
|
||||
dark: 'github-dark',
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
config: async (md) => {
|
||||
await MermaidExample(md);
|
||||
|
||||
config: (md) => {
|
||||
MermaidExample(md);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import type { MarkdownRenderer } from 'vitepress';
|
||||
|
||||
const MermaidExample = async (md: MarkdownRenderer) => {
|
||||
const MermaidExample = (md: MarkdownRenderer) => {
|
||||
const defaultRenderer = md.renderer.rules.fence;
|
||||
|
||||
if (!defaultRenderer) {
|
||||
|
@ -35,7 +35,7 @@ export default {
|
||||
const url = new URL(window.location.origin + to);
|
||||
const newPath = getRedirect(url);
|
||||
if (newPath) {
|
||||
console.log(`Redirecting to ${newPath} from ${window.location}`);
|
||||
console.log(`Redirecting to ${newPath} from ${window.location.toString()}`);
|
||||
// router.go isn't loading the ID properly.
|
||||
window.location.href = `/${newPath}`;
|
||||
}
|
||||
|
@ -49,12 +49,12 @@ export default defineConfig({
|
||||
// TODO: will be fixed in the next vitepress release.
|
||||
name: 'fix-virtual',
|
||||
|
||||
async resolveId(id: string) {
|
||||
resolveId(id: string) {
|
||||
if (id === virtualModuleId) {
|
||||
return resolvedVirtualModuleId;
|
||||
}
|
||||
},
|
||||
async load(this, id: string) {
|
||||
load(this, id: string) {
|
||||
if (id === resolvedVirtualModuleId) {
|
||||
return `export default ${JSON.stringify({
|
||||
securityLevel: 'loose',
|
||||
|
@ -29,12 +29,11 @@ export const log: Record<keyof typeof LEVELS, typeof console.log> = {
|
||||
*
|
||||
* @param level - The level to set the logging to. Default is `"fatal"`
|
||||
*/
|
||||
export const setLogLevel = function (level: keyof typeof LEVELS | number | string = 'fatal') {
|
||||
export const setLogLevel = function (level: keyof typeof LEVELS | number = 'fatal') {
|
||||
let numericLevel: number = LEVELS.fatal;
|
||||
if (typeof level === 'string') {
|
||||
level = level.toLowerCase();
|
||||
if (level in LEVELS) {
|
||||
numericLevel = LEVELS[level as keyof typeof LEVELS];
|
||||
if (level.toLowerCase() in LEVELS) {
|
||||
numericLevel = LEVELS[level];
|
||||
}
|
||||
} else if (typeof level === 'number') {
|
||||
numericLevel = level;
|
||||
|
@ -31,7 +31,7 @@ import packet from './diagrams/packet/styles.js';
|
||||
import block from './diagrams/block/styles.js';
|
||||
import themes from './themes/index.js';
|
||||
|
||||
async function checkValidStylisCSSStyleSheet(stylisString: string) {
|
||||
function checkValidStylisCSSStyleSheet(stylisString: string) {
|
||||
const cssString = serialize(compile(`#my-svg-id{${stylisString}}`), stringify);
|
||||
const errors = validate(cssString, 'this-file-was-created-by-tests.css') as Error[];
|
||||
|
||||
@ -51,6 +51,7 @@ async function checkValidStylisCSSStyleSheet(stylisString: string) {
|
||||
|
||||
if (unexpectedErrors.length > 0) {
|
||||
throw new Error(
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
`The given CSS string was invalid: ${errors}.\n\n` +
|
||||
'Copy the below CSS into https://jigsaw.w3.org/css-validator/validator to help debug where the invalid CSS is:\n\n' +
|
||||
`Original CSS value was ${cssString}`
|
||||
@ -75,7 +76,7 @@ describe('styles', () => {
|
||||
|
||||
const styles = getStyles(diagramType, '', getConfig().themeVariables);
|
||||
|
||||
await checkValidStylisCSSStyleSheet(styles);
|
||||
checkValidStylisCSSStyleSheet(styles);
|
||||
});
|
||||
|
||||
/**
|
||||
@ -110,7 +111,7 @@ describe('styles', () => {
|
||||
themes[themeId].getThemeVariables()
|
||||
);
|
||||
|
||||
await checkValidStylisCSSStyleSheet(styles);
|
||||
checkValidStylisCSSStyleSheet(styles);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ export class MockedD3 {
|
||||
if (beforeSelector === undefined) {
|
||||
this._children.push(newMock);
|
||||
} else {
|
||||
const idOnly = beforeSelector[0] == '#' ? beforeSelector.substring(1) : beforeSelector;
|
||||
const idOnly = beforeSelector.startsWith('#') ? beforeSelector.substring(1) : beforeSelector;
|
||||
const foundIndex = this._children.findIndex((child) => child.id === idOnly);
|
||||
if (foundIndex < 0) {
|
||||
this._children.push(newMock);
|
||||
|
@ -45,7 +45,12 @@ export const getLineFunctionsWithOffset = (
|
||||
edge: Pick<EdgeData, 'arrowTypeStart' | 'arrowTypeEnd'>
|
||||
) => {
|
||||
return {
|
||||
x: function (d: Point | [number, number], i: number, data: (Point | [number, number])[]) {
|
||||
x: function (
|
||||
this: void,
|
||||
d: Point | [number, number],
|
||||
i: number,
|
||||
data: (Point | [number, number])[]
|
||||
) {
|
||||
let offset = 0;
|
||||
if (i === 0 && Object.hasOwn(markerOffsets, edge.arrowTypeStart)) {
|
||||
// Handle first point
|
||||
@ -70,7 +75,12 @@ export const getLineFunctionsWithOffset = (
|
||||
}
|
||||
return pointTransformer(d).x + offset;
|
||||
},
|
||||
y: function (d: Point | [number, number], i: number, data: (Point | [number, number])[]) {
|
||||
y: function (
|
||||
this: void,
|
||||
d: Point | [number, number],
|
||||
i: number,
|
||||
data: (Point | [number, number])[]
|
||||
) {
|
||||
// Same handling as X above
|
||||
let offset = 0;
|
||||
if (i === 0 && Object.hasOwn(markerOffsets, edge.arrowTypeStart)) {
|
||||
|
@ -20,6 +20,7 @@ export abstract class AbstractMermaidTokenBuilder extends DefaultTokenBuilder {
|
||||
// to restrict users, they mustn't have any non-whitespace characters after the keyword.
|
||||
tokenTypes.forEach((tokenType: TokenType): void => {
|
||||
if (this.keywords.has(tokenType.name) && tokenType.PATTERN !== undefined) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
||||
tokenType.PATTERN = new RegExp(tokenType.PATTERN.toString() + '(?:(?=%%)|(?!\\S))');
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user