chore: Resolve eslint errors

This commit is contained in:
Sidharth Vinod 2024-06-29 16:09:50 +05:30
parent 3f2e823330
commit 4a50feb5d9
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD
30 changed files with 92 additions and 57 deletions

View File

@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { packageOptions } from './common.js';
import { execSync } from 'child_process';
@ -5,11 +6,17 @@ const buildType = (packageName: string) => {
console.log(`Building types for ${packageName}`);
try {
const out = execSync(`tsc -p ./packages/${packageName}/tsconfig.json --emitDeclarationOnly`);
out.length > 0 && console.log(out.toString());
if (out.length > 0) {
console.log(out.toString());
}
} catch (e) {
console.error(e);
e.stdout.length > 0 && console.error(e.stdout.toString());
e.stderr.length > 0 && console.error(e.stderr.toString());
if (e.stdout.length > 0) {
console.error(e.stdout.toString());
}
if (e.stderr.length > 0) {
console.error(e.stderr.toString());
}
}
};

View File

@ -138,3 +138,6 @@ yaxis
yfunc
yytext
zenuml
treemap
brotli
subconfig

View File

@ -6,3 +6,4 @@ Nikolay Rozhkov
Peng Xiao
subhash-halder
Vinod Sidharth
Per Brolin

View File

@ -58,6 +58,7 @@ rscratch
sparkline
sphinxcontrib
ssim
shiki
stylis
Swimm
tsbuildinfo

View File

@ -2,7 +2,8 @@ import { build } from 'esbuild';
import { mkdir, writeFile } from 'node:fs/promises';
import { packageOptions } from '../.build/common.js';
import { generateLangium } from '../.build/generateLangium.js';
import { MermaidBuildOptions, defaultOptions, getBuildConfig } from './util.js';
import type { MermaidBuildOptions } from './util.js';
import { defaultOptions, getBuildConfig } from './util.js';
const shouldVisualize = process.argv.includes('--visualize');
@ -35,11 +36,11 @@ const buildPackage = async (entryName: keyof typeof packageOptions) => {
if (shouldVisualize) {
for (const { metafile } of results) {
if (!metafile) {
if (!metafile?.outputs) {
continue;
}
const fileName = Object.keys(metafile.outputs)
.filter((file) => !file.includes('chunks') && file.endsWith('js'))[0]
.find((file) => !file.includes('chunks') && file.endsWith('js'))
.replace('dist/', '');
// Upload metafile into https://esbuild.github.io/analyze/
await writeFile(`stats/${fileName}.meta.json`, JSON.stringify(metafile));
@ -48,6 +49,7 @@ const buildPackage = async (entryName: keyof typeof packageOptions) => {
};
const handler = (e) => {
// eslint-disable-next-line no-console
console.error(e);
process.exit(1);
};

View File

@ -1,6 +1,6 @@
import { readFile } from 'node:fs/promises';
import { transformJison } from '../.build/jisonTransformer.js';
import { Plugin } from 'esbuild';
import type { Plugin } from 'esbuild';
export const jisonPlugin: Plugin = {
name: 'jison',

View File

@ -56,7 +56,7 @@ export const getBuildConfig = (options: MermaidBuildOptions): BuildOptions => {
const external: string[] = ['require', 'fs', 'path'];
const { name, file, packageName } = packageOptions[entryName];
const outFileName = getFileName(name, options);
let output: BuildOptions = buildOptions({
const output: BuildOptions = buildOptions({
absWorkingDir: resolve(__dirname, `../packages/${packageName}`),
entryPoints: {
[outFileName]: `src/${file}`,

View File

@ -1,4 +1,5 @@
import { build, InlineConfig, type PluginOption } from 'vite';
import type { InlineConfig } from 'vite';
import { build, type PluginOption } from 'vite';
import { resolve } from 'path';
import { fileURLToPath } from 'url';
import jisonPlugin from './jisonPlugin.js';
@ -46,9 +47,10 @@ interface BuildOptions {
export const getBuildConfig = ({ minify, core, watch, entryName }: BuildOptions): InlineConfig => {
const external: (string | RegExp)[] = ['require', 'fs', 'path'];
// eslint-disable-next-line no-console
console.log(entryName, packageOptions[entryName]);
const { name, file, packageName } = packageOptions[entryName];
let output: OutputOptions = [
const output: OutputOptions = [
{
name,
format: 'esm',
@ -83,7 +85,6 @@ export const getBuildConfig = ({ minify, core, watch, entryName }: BuildOptions)
plugins: [
jisonPlugin(),
jsonSchemaPlugin(), // handles `.schema.yaml` files
// @ts-expect-error According to the type definitions, rollup plugins are incompatible with vite
typescript({ compilerOptions: { declaration: false } }),
istanbul({
exclude: ['node_modules', 'test/', '__mocks__', 'generated'],
@ -121,10 +122,10 @@ await generateLangium();
if (watch) {
await build(getBuildConfig({ minify: false, watch, core: false, entryName: 'parser' }));
build(getBuildConfig({ minify: false, watch, core: false, entryName: 'mermaid' }));
void build(getBuildConfig({ minify: false, watch, core: false, entryName: 'mermaid' }));
if (!mermaidOnly) {
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-example-diagram' }));
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-zenuml' }));
void build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-example-diagram' }));
void build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-zenuml' }));
}
} else if (visualize) {
await build(getBuildConfig({ minify: false, watch, core: false, entryName: 'parser' }));

View File

@ -1,4 +1,4 @@
import { PluginOption } from 'vite';
import type { PluginOption } from 'vite';
import { getDefaults, getSchema, loadSchema } from '../.build/jsonSchema.js';
/**

View File

@ -1,8 +1,6 @@
// <reference types="Cypress" />
import { imgSnapshotTest, renderGraph } from '../../helpers/util.ts';
context('Sequence diagram', () => {
describe('Sequence diagram', () => {
it('should render a sequence diagram with boxes', () => {
renderGraph(
`
@ -244,7 +242,7 @@ context('Sequence diagram', () => {
`
);
});
context('font settings', () => {
describe('font settings', () => {
it('should render different note fonts when configured', () => {
imgSnapshotTest(
`
@ -341,7 +339,7 @@ context('Sequence diagram', () => {
);
});
});
context('auth width scaling', () => {
describe('auth width scaling', () => {
it('should render long actor descriptions', () => {
imgSnapshotTest(
`
@ -530,7 +528,7 @@ context('Sequence diagram', () => {
);
});
});
context('background rects', () => {
describe('background rects', () => {
it('should render a single and nested rects', () => {
imgSnapshotTest(
`
@ -810,7 +808,7 @@ context('Sequence diagram', () => {
);
});
});
context('directives', () => {
describe('directives', () => {
it('should override config with directive settings', () => {
imgSnapshotTest(
`
@ -842,7 +840,7 @@ context('Sequence diagram', () => {
);
});
});
context('links', () => {
describe('links', () => {
it('should support actor links', () => {
renderGraph(
`
@ -933,7 +931,7 @@ context('Sequence diagram', () => {
);
});
});
context('svg size', () => {
describe('svg size', () => {
it('should render a sequence diagram when useMaxWidth is true (default)', () => {
renderGraph(
`
@ -1012,7 +1010,7 @@ context('Sequence diagram', () => {
});
});
});
context('render after error', () => {
describe('render after error', () => {
it('should render diagram after fixing destroy participant error', () => {
cy.on('uncaught:exception', (err) => {
return false;

View File

@ -19,7 +19,14 @@ export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
ignores: ['**/dist/', '**/node_modules/', '.git/', '**/generated/', '**/coverage/'],
ignores: [
'**/dist/',
'**/node_modules/',
'.git/',
'**/generated/',
'**/coverage/',
'packages/mermaid/src/config.type.ts',
],
},
{
languageOptions: {
@ -38,6 +45,7 @@ export default tseslint.config(
...globals.es2020,
...globals.jest,
cy: 'readonly',
Cypress: 'readonly',
},
},
},

View File

@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import * as configApi from './config.js';
import type { MermaidConfig } from './config.type.js';

View File

@ -1,4 +1,3 @@
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,

View File

@ -24,8 +24,12 @@ export const drawRect = (element: SVG | Group, rectData: RectData): D3RectElemen
if (rectData.name) {
rectElement.attr('name', rectData.name);
}
rectData.rx !== undefined && rectElement.attr('rx', rectData.rx);
rectData.ry !== undefined && rectElement.attr('ry', rectData.ry);
if (rectData.rx) {
rectElement.attr('rx', rectData.rx);
}
if (rectData.ry) {
rectElement.attr('ry', rectData.ry);
}
if (rectData.attrs !== undefined) {
for (const attrKey in rectData.attrs) {
@ -33,7 +37,9 @@ export const drawRect = (element: SVG | Group, rectData: RectData): D3RectElemen
}
}
rectData.class !== undefined && rectElement.attr('class', rectData.class);
if (rectData.class) {
rectElement.attr('class', rectData.class);
}
return rectElement;
};
@ -67,7 +73,9 @@ export const drawText = (element: SVG | Group, textData: TextData): D3TextElemen
textElem.attr('class', 'legend');
textElem.style('text-anchor', textData.anchor);
textData.class !== undefined && textElem.attr('class', textData.class);
if (textData.class) {
textElem.attr('class', textData.class);
}
const tspan: D3TSpanElement = textElem.append('tspan');
tspan.attr('x', textData.x + textData.textMargin * 2);

View File

@ -109,7 +109,7 @@ describe('when using the ganttDb', function () {
ganttDb.addTask(taskName2, taskData2);
const tasks = ganttDb.getTasks();
expect(tasks[1].startTime).toEqual(expStartDate2);
if (!expEndDate2 === undefined) {
if (expEndDate2) {
expect(tasks[1].endTime).toEqual(expEndDate2);
}
expect(tasks[1].id).toEqual(expId2);

View File

@ -35,7 +35,7 @@ function getId() {
// * @param currentCommit
// * @param otherCommit
// */
// eslint-disable-next-line @cspell/spellchecker
// function isFastForwardable(currentCommit, otherCommit) {
// log.debug('Entering isFastForwardable:', currentCommit.id, otherCommit.id);
// let cnt = 0;

View File

@ -5,7 +5,7 @@ import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
import { configureSvgSize } from '../../setupGraphViewbox.js';
import type { PacketDB, PacketWord } from './types.js';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const draw: DrawDefinition = (_text, id, _version, diagram: Diagram) => {
const db = diagram.db as PacketDB;
const config = db.getConfig();

View File

@ -383,9 +383,11 @@ const drawMessage = async function (diagram, msgModel, lineStartY: number, diagO
textObj.textMargin = conf.wrapPadding;
textObj.tspan = false;
hasKatex(textObj.text)
? await drawKatex(diagram, textObj, { startx, stopx, starty: lineStartY })
: drawText(diagram, textObj);
if (hasKatex(textObj.text)) {
await drawKatex(diagram, textObj, { startx, stopx, starty: lineStartY });
} else {
drawText(diagram, textObj);
}
const textWidth = textDims.width;

View File

@ -1,4 +1,5 @@
import { defineConfig, MarkdownOptions } from 'vitepress';
import type { MarkdownOptions } from 'vitepress';
import { defineConfig } from 'vitepress';
import { version } from '../../../package.json';
import MermaidExample from './mermaid-markdown-all.js';
@ -8,6 +9,7 @@ const allMarkdownTransformers: MarkdownOptions = {
light: 'github-light',
dark: 'github-dark',
},
// eslint-disable-next-line @typescript-eslint/no-misused-promises
config: async (md) => {
await MermaidExample(md);
},
@ -228,8 +230,6 @@ function sidebarNews() {
/**
* Return a string that puts together the pagePage, a '#', then the given id
* @param pagePath
* @param id
* @returns the fully formed path
*/
function pathToId(pagePath: string, id = ''): string {

View File

@ -1,5 +1,6 @@
import contributorUsernamesJson from './contributor-names.json';
import { CoreTeam, knut, plainTeamMembers } from './teamMembers.js';
import type { CoreTeam } from './teamMembers.js';
import { knut, plainTeamMembers } from './teamMembers.js';
const contributorUsernames: string[] = contributorUsernamesJson;

View File

@ -32,11 +32,11 @@ async function fetchAvatars() {
});
contributors = JSON.parse(await readFile(pathContributors, { encoding: 'utf-8' }));
let avatars = contributors.map((name) => {
download(`https://github.com/${name}.png?size=100`, getAvatarPath(name));
});
const avatars = contributors.map((name) =>
download(`https://github.com/${name}.png?size=100`, getAvatarPath(name))
);
await Promise.allSettled(avatars);
}
fetchAvatars();
void fetchAvatars();

View File

@ -1,3 +1,4 @@
/* eslint-disable no-console */
// Adapted from https://github.dev/vitest-dev/vitest/blob/991ff33ab717caee85ef6cbe1c16dc514186b4cc/scripts/update-contributors.ts#L6
import { writeFile } from 'node:fs/promises';

View File

@ -1,3 +1,4 @@
/* eslint-disable @cspell/spellchecker */
export interface Contributor {
name: string;
avatar: string;

View File

@ -1,14 +1,16 @@
/* eslint-disable no-console */
import DefaultTheme from 'vitepress/theme';
import './custom.css';
// @ts-ignore
// @ts-ignore Type not available
import Mermaid from './Mermaid.vue';
// @ts-ignore
// @ts-ignore Type not available
import Contributors from '../components/Contributors.vue';
// @ts-ignore
// @ts-ignore Type not available
import HomePage from '../components/HomePage.vue';
// @ts-ignore
// @ts-ignore Type not available
import TopBar from '../components/TopBar.vue';
import { getRedirect } from './redirect.js';
// @ts-ignore Type not available
import { h } from 'vue';
import Theme from 'vitepress/theme';
import '../style/main.css';

View File

@ -116,3 +116,5 @@ export const getRedirect = (url: URL): string | undefined => {
return `${idRedirectMap[path]}.html${id ? `#${id}` : ''}`;
}
};
// cspell:ignore mermaidapi, breakingchanges, classdiagram, entityrelationshipdiagram, mermaidapi, mermaidcli, gettingstarted, syntaxreference, newdiagram, requirementdiagram, sequencediagram

View File

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable no-console */
import dayjs from 'dayjs';

View File

@ -33,9 +33,7 @@ const processDirectives = (code: string) => {
const initDirective = utils.detectInit(code) ?? {};
const wrapDirectives = utils.detectDirective(code, 'wrap');
if (Array.isArray(wrapDirectives)) {
initDirective.wrap = wrapDirectives.some(({ type }) => {
type === 'wrap';
});
initDirective.wrap = wrapDirectives.some(({ type }) => type === 'wrap');
} else if (wrapDirectives?.type === 'wrap') {
initDirective.wrap = true;
}

View File

@ -777,7 +777,7 @@ export const entityDecode = function (html: string): string {
// Escape HTML before decoding for HTML Entities
html = escape(html).replace(/%26/g, '&').replace(/%23/g, '#').replace(/%3B/g, ';');
decoder.innerHTML = html;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return unescape(decoder.textContent!);
};

View File

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-console */
// eslint-disable-next-line @typescript-eslint/no-require-imports
const mermaid = require('mermaid');
import mindmap from '@mermaid-js/mermaid-mindmap';

View File

@ -1,4 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const path = require('path');
module.exports = {