Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/3697 eslint curly #3698

Merged
merged 4 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
],
"plugins": ["@typescript-eslint", "no-only-tests", "html", "jest", "jsdoc", "json", "@cspell"],
"rules": {
"curly": "error",
"no-console": "error",
"no-prototype-builtins": "off",
"no-unused-vars": "off",
Expand Down
8 changes: 6 additions & 2 deletions cypress/helpers/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export const imgSnapshotTest = (graphStr, _options, api = false, validation) =>
const url = mermaidUrl(graphStr, options, api);

cy.visit(url);
if (validation) cy.get('svg').should(validation);
if (validation) {
cy.get('svg').should(validation);
}
cy.get('svg');
// Default name to test title

Expand Down Expand Up @@ -106,7 +108,9 @@ export const urlSnapshotTest = (url, _options, api = false, validation) => {
}

cy.visit(url);
if (validation) cy.get('svg').should(validation);
if (validation) {
cy.get('svg').should(validation);
}
cy.get('body');
// Default name to test title

Expand Down
4 changes: 3 additions & 1 deletion cypress/platform/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ const contentLoadedApi = function () {
(svgCode, bindFunctions) => {
div.innerHTML = svgCode;

if (bindFunctions) bindFunctions(div);
if (bindFunctions) {
bindFunctions(div);
}
},
div
);
Expand Down
4 changes: 3 additions & 1 deletion packages/mermaid/src/dagre-wrapper/createLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ function addHtmlLabel(node) {

const createLabel = (_vertexText, style, isTitle, isNode) => {
let vertexText = _vertexText || '';
if (typeof vertexText === 'object') vertexText = vertexText[0];
if (typeof vertexText === 'object') {
vertexText = vertexText[0];
}
if (evaluate(getConfig().flowchart.htmlLabels)) {
// TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that?
vertexText = vertexText.replace(/\\n|\n/g, '<br />');
Expand Down
4 changes: 3 additions & 1 deletion packages/mermaid/src/dagre-wrapper/edges.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ const cutPathAtIntersect = (_points, boundryNode) => {
log.warn('abc88 outside', point, lastPointOutside);
lastPointOutside = point;
// points.push(point);
if (!isInside) points.push(point);
if (!isInside) {
points.push(point);
}
}
});
log.warn('abc88 returning points', points);
Expand Down
36 changes: 24 additions & 12 deletions packages/mermaid/src/dagre-wrapper/mermaid-graphlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const isDecendant = (id, ancenstorId) => {
' = ',
decendants[ancenstorId].indexOf(id) >= 0
);
if (decendants[ancenstorId].indexOf(id) >= 0) return true;
if (decendants[ancenstorId].indexOf(id) >= 0) {
return true;
}

return false;
};
Expand All @@ -32,19 +34,23 @@ const edgeInCluster = (edge, clusterId) => {
log.info('Decendants of ', clusterId, ' is ', decendants[clusterId]);
log.info('Edge is ', edge);
// Edges to/from the cluster is not in the cluster, they are in the parent
if (edge.v === clusterId) return false;
if (edge.w === clusterId) return false;
if (edge.v === clusterId) {
return false;
}
if (edge.w === clusterId) {
return false;
}

if (!decendants[clusterId]) {
log.debug('Tilt, ', clusterId, ',not in decendants');
return false;
}
if (decendants[clusterId].indexOf(edge.v) >= 0) return true;
if (isDecendant(edge.v, clusterId)) return true;
if (isDecendant(edge.w, clusterId)) return true;
if (decendants[clusterId].indexOf(edge.w) >= 0) return true;

return false;
return (
decendants[clusterId].indexOf(edge.v) >= 0 ||
isDecendant(edge.v, clusterId) ||
isDecendant(edge.w, clusterId) ||
decendants[clusterId].indexOf(edge.w) >= 0
);
};

const copy = (clusterId, graph, newGraph, rootId) => {
Expand Down Expand Up @@ -306,8 +312,12 @@ export const adjustClustersAndEdges = (graph, depth) => {
v = getAnchorId(e.v);
w = getAnchorId(e.w);
graph.removeEdge(e.v, e.w, e.name);
if (v !== e.v) edge.fromCluster = e.v;
if (w !== e.w) edge.toCluster = e.w;
if (v !== e.v) {
edge.fromCluster = e.v;
}
if (w !== e.w) {
edge.toCluster = e.w;
}
log.warn('Fix Replacing with XXX', v, w, e.name);
graph.setEdge(v, w, edge, e.name);
}
Expand Down Expand Up @@ -446,7 +456,9 @@ export const extractor = (graph, depth) => {
};

const sorter = (graph, nodes) => {
if (nodes.length === 0) return [];
if (nodes.length === 0) {
return [];
}
let result = Object.assign(nodes);
nodes.forEach((node) => {
const children = graph.children(node);
Expand Down
8 changes: 6 additions & 2 deletions packages/mermaid/src/dagre-wrapper/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,13 @@ const cylinder = (parent, node) => {
// ellipsis equation: x*x / a*a + y*y / b*b = 1
// solve for y to get adjusted value for pos.y
let y = ry * ry * (1 - (x * x) / (rx * rx));
if (y != 0) y = Math.sqrt(y);
if (y != 0) {
y = Math.sqrt(y);
}
y = ry - y;
if (point.y - node.y > 0) y = -y;
if (point.y - node.y > 0) {
y = -y;
}

pos.y += y;
}
Expand Down
8 changes: 6 additions & 2 deletions packages/mermaid/src/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1833,8 +1833,12 @@ const config: Partial<MermaidConfig> = {
fontSize: 16,
};

if (config.class) config.class.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
if (config.gitGraph) config.gitGraph.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
if (config.class) {
config.class.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
}
if (config.gitGraph) {
config.gitGraph.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
}

const keyify = (obj: any, prefix = ''): string[] =>
Object.keys(obj).reduce((res: string[], el): string[] => {
Expand Down
48 changes: 35 additions & 13 deletions packages/mermaid/src/diagrams/c4/c4Db.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export const addRel = function (type, from, to, label, techn, descr, sprite, tag
to === null ||
label === undefined ||
label === null
)
) {
return;
}

let rel = {};
const old = rels.find((rel) => rel.from === from && rel.to === to);
Expand Down Expand Up @@ -111,7 +112,9 @@ export const addRel = function (type, from, to, label, techn, descr, sprite, tag
//type, alias, label, ?descr, ?sprite, ?tags, $link
export const addPersonOrSystem = function (typeC4Shape, alias, label, descr, sprite, tags, link) {
// Don't allow label nulling
if (alias === null || label === null) return;
if (alias === null || label === null) {
return;
}

let personOrSystem = {};
const old = c4ShapeArray.find((personOrSystem) => personOrSystem.alias === alias);
Expand Down Expand Up @@ -166,7 +169,9 @@ export const addPersonOrSystem = function (typeC4Shape, alias, label, descr, spr
//type, alias, label, ?techn, ?descr ?sprite, ?tags, $link
export const addContainer = function (typeC4Shape, alias, label, techn, descr, sprite, tags, link) {
// Don't allow label nulling
if (alias === null || label === null) return;
if (alias === null || label === null) {
return;
}

let container = {};
const old = c4ShapeArray.find((container) => container.alias === alias);
Expand Down Expand Up @@ -232,7 +237,9 @@ export const addContainer = function (typeC4Shape, alias, label, techn, descr, s
//type, alias, label, ?techn, ?descr ?sprite, ?tags, $link
export const addComponent = function (typeC4Shape, alias, label, techn, descr, sprite, tags, link) {
// Don't allow label nulling
if (alias === null || label === null) return;
if (alias === null || label === null) {
return;
}

let component = {};
const old = c4ShapeArray.find((component) => component.alias === alias);
Expand Down Expand Up @@ -300,7 +307,9 @@ export const addPersonOrSystemBoundary = function (alias, label, type, tags, lin
// if (parentBoundary === null) return;

// Don't allow label nulling
if (alias === null || label === null) return;
if (alias === null || label === null) {
return;
}

let boundary = {};
const old = boundarys.find((boundary) => boundary.alias === alias);
Expand Down Expand Up @@ -354,7 +363,9 @@ export const addContainerBoundary = function (alias, label, type, tags, link) {
// if (parentBoundary === null) return;

// Don't allow label nulling
if (alias === null || label === null) return;
if (alias === null || label === null) {
return;
}

let boundary = {};
const old = boundarys.find((boundary) => boundary.alias === alias);
Expand Down Expand Up @@ -417,7 +428,9 @@ export const addDeploymentNode = function (
// if (parentBoundary === null) return;

// Don't allow label nulling
if (alias === null || label === null) return;
if (alias === null || label === null) {
return;
}

let boundary = {};
const old = boundarys.find((boundary) => boundary.alias === alias);
Expand Down Expand Up @@ -646,8 +659,12 @@ export const updateLayoutConfig = function (typeC4Shape, c4ShapeInRowParam, c4Bo
c4BoundaryInRowValue = parseInt(c4BoundaryInRowParam);
}

if (c4ShapeInRowValue >= 1) c4ShapeInRow = c4ShapeInRowValue;
if (c4BoundaryInRowValue >= 1) c4BoundaryInRow = c4BoundaryInRowValue;
if (c4ShapeInRowValue >= 1) {
c4ShapeInRow = c4ShapeInRowValue;
}
if (c4BoundaryInRowValue >= 1) {
c4BoundaryInRow = c4BoundaryInRowValue;
}
};

export const getC4ShapeInRow = function () {
Expand All @@ -665,11 +682,13 @@ export const getParentBoundaryParse = function () {
};

export const getC4ShapeArray = function (parentBoundary) {
if (parentBoundary === undefined || parentBoundary === null) return c4ShapeArray;
else
if (parentBoundary === undefined || parentBoundary === null) {
return c4ShapeArray;
} else {
return c4ShapeArray.filter((personOrSystem) => {
return personOrSystem.parentBoundary === parentBoundary;
});
}
};
export const getC4Shape = function (alias) {
return c4ShapeArray.find((personOrSystem) => personOrSystem.alias === alias);
Expand All @@ -679,8 +698,11 @@ export const getC4ShapeKeys = function (parentBoundary) {
};

export const getBoundarys = function (parentBoundary) {
if (parentBoundary === undefined || parentBoundary === null) return boundarys;
else return boundarys.filter((boundary) => boundary.parentBoundary === parentBoundary);
if (parentBoundary === undefined || parentBoundary === null) {
return boundarys;
} else {
return boundarys.filter((boundary) => boundary.parentBoundary === parentBoundary);
}
};

export const getRels = function () {
Expand Down
8 changes: 6 additions & 2 deletions packages/mermaid/src/diagrams/c4/c4Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,9 @@ export const drawRels = function (diagram, rels, getC4ShapeObj, diagObj) {
let relTextWrap = rel.wrap && conf.wrap;
let relConf = messageFont(conf);
let diagramType = diagObj.db.getC4Type();
if (diagramType === 'C4Dynamic') rel.label.text = i + ': ' + rel.label.text;
if (diagramType === 'C4Dynamic') {
rel.label.text = i + ': ' + rel.label.text;
}
let textLimitWidth = calculateTextWidth(rel.label.text, relConf);
calcC4ShapeTextWH('label', rel, relTextWrap, relConf, textLimitWidth);

Expand Down Expand Up @@ -555,7 +557,9 @@ function drawInsideBoundary(
);
}
// draw boundary
if (currentBoundary.alias !== 'global') drawBoundary(diagram, currentBoundary, currentBounds);
if (currentBoundary.alias !== 'global') {
drawBoundary(diagram, currentBoundary, currentBounds);
}
parentBounds.data.stopy = Math.max(
currentBounds.data.stopy + conf.c4ShapeMargin,
parentBounds.data.stopy
Expand Down
22 changes: 16 additions & 6 deletions packages/mermaid/src/diagrams/c4/svgDraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const drawRect = function (elem, rectData) {
rectElem.attr('ry', rectData.ry);

if (rectData.attrs !== 'undefined' && rectData.attrs !== null) {
for (let attrKey in rectData.attrs) rectElem.attr(attrKey, rectData.attrs[attrKey]);
for (let attrKey in rectData.attrs) {
rectElem.attr(attrKey, rectData.attrs[attrKey]);
}
}

if (rectData.class !== 'undefined') {
Expand Down Expand Up @@ -231,9 +233,12 @@ export const drawRels = (elem, rels, conf) => {
line.attr('stroke-width', '1');
line.attr('stroke', strokeColor);
line.style('fill', 'none');
if (rel.type !== 'rel_b') line.attr('marker-end', 'url(' + url + '#arrowhead)');
if (rel.type === 'birel' || rel.type === 'rel_b')
if (rel.type !== 'rel_b') {
line.attr('marker-end', 'url(' + url + '#arrowhead)');
}
if (rel.type === 'birel' || rel.type === 'rel_b') {
line.attr('marker-start', 'url(' + url + '#arrowend)');
}
i = -1;
} else {
let line = relsElem.append('path');
Expand All @@ -256,9 +261,12 @@ export const drawRels = (elem, rels, conf) => {
.replaceAll('stopx', rel.endPoint.x)
.replaceAll('stopy', rel.endPoint.y)
);
if (rel.type !== 'rel_b') line.attr('marker-end', 'url(' + url + '#arrowhead)');
if (rel.type === 'birel' || rel.type === 'rel_b')
if (rel.type !== 'rel_b') {
line.attr('marker-end', 'url(' + url + '#arrowhead)');
}
if (rel.type === 'birel' || rel.type === 'rel_b') {
line.attr('marker-start', 'url(' + url + '#arrowend)');
}
}

let messageConf = conf.messageFont();
Expand Down Expand Up @@ -314,7 +322,9 @@ const drawBoundary = function (elem, boundary, conf) {
let fontColor = boundary.fontColor ? boundary.fontColor : 'black';

let attrsValue = { 'stroke-width': 1.0, 'stroke-dasharray': '7.0,7.0' };
if (boundary.nodeType) attrsValue = { 'stroke-width': 1.0 };
if (boundary.nodeType) {
attrsValue = { 'stroke-width': 1.0 };
}
let rectData = {
x: boundary.x,
y: boundary.y,
Expand Down
12 changes: 9 additions & 3 deletions packages/mermaid/src/diagrams/class/classDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ const splitClassNameAndType = function (id) {
export const addClass = function (id) {
let classId = splitClassNameAndType(id);
// Only add class if not exists
if (typeof classes[classId.className] !== 'undefined') return;
if (typeof classes[classId.className] !== 'undefined') {
return;
}

classes[classId.className] = {
id: classId.className,
Expand Down Expand Up @@ -185,7 +187,9 @@ export const cleanupLabel = function (label) {
export const setCssClass = function (ids, className) {
ids.split(',').forEach(function (_id) {
let id = _id;
if (_id[0].match(/\d/)) id = MERMAID_DOM_ID_PREFIX + id;
if (_id[0].match(/\d/)) {
id = MERMAID_DOM_ID_PREFIX + id;
}
if (typeof classes[id] !== 'undefined') {
classes[id].cssClasses.push(className);
}
Expand Down Expand Up @@ -220,7 +224,9 @@ export const setLink = function (ids, linkStr, target) {
const config = configApi.getConfig();
ids.split(',').forEach(function (_id) {
let id = _id;
if (_id[0].match(/\d/)) id = MERMAID_DOM_ID_PREFIX + id;
if (_id[0].match(/\d/)) {
id = MERMAID_DOM_ID_PREFIX + id;
}
if (typeof classes[id] !== 'undefined') {
classes[id].link = utils.formatUrl(linkStr, config);
if (config.securityLevel === 'sandbox') {
Expand Down
Loading