Skip to content

Commit

Permalink
Merge pull request #4763 from mermaid-js/sidv/fixTypeImports
Browse files Browse the repository at this point in the history
chore: Enforce type imports
  • Loading branch information
knsv committed Aug 23, 2023
2 parents bd98da1 + 11b599d commit 2ab393c
Show file tree
Hide file tree
Showing 34 changed files with 50 additions and 43 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = {
'no-prototype-builtins': 'off',
'no-unused-vars': 'off',
'cypress/no-async-tests': 'off',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/ban-ts-comment': [
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagram-api/detectType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MermaidConfig } from '../config.type.js';
import type { MermaidConfig } from '../config.type.js';
import { log } from '../logger.js';
import type {
DetectorRecord,
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagram-api/diagramAPI.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { detectType } from './detectType.js';
import { getDiagram, registerDiagram } from './diagramAPI.js';
import { addDiagrams } from './diagram-orchestration.js';
import { DiagramDetector } from './types.js';
import type { DiagramDetector } from './types.js';
import { getDiagramFromText } from '../Diagram.js';
import { it, describe, expect, beforeAll } from 'vitest';

Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagram-api/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Diagram } from '../Diagram.js';
import type { Diagram } from '../Diagram.js';
import type { BaseDiagramConfig, MermaidConfig } from '../config.type.js';
import type * as d3 from 'd3';

Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/diagrams/c4/c4Diagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import c4Parser from './parser/c4Diagram.jison';
import c4Db from './c4Db.js';
import c4Renderer from './c4Renderer.js';
import c4Styles from './styles.js';
import { MermaidConfig } from '../../config.type.js';
import { DiagramDefinition } from '../../diagram-api/types.js';
import type { MermaidConfig } from '../../config.type.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';

export const diagram: DiagramDefinition = {
parser: c4Parser,
Expand Down
5 changes: 3 additions & 2 deletions packages/mermaid/src/diagrams/class/classDb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-nocheck - don't check until handle it
import { select, Selection } from 'd3';
import type { Selection } from 'd3';
import { select } from 'd3';
import { log } from '../../logger.js';
import * as configApi from '../../config.js';
import common from '../common/common.js';
Expand All @@ -14,7 +15,7 @@ import {
setDiagramTitle,
getDiagramTitle,
} from '../../commonDb.js';
import {
import type {
ClassRelation,
ClassNode,
ClassNote,
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/class/classDiagram-v2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiagramDefinition } from '../../diagram-api/types.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: JISON doesn't support types
import parser from './parser/classDiagram.jison';
import db from './classDb.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/class/classDiagram.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiagramDefinition } from '../../diagram-api/types.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: JISON doesn't support types
import parser from './parser/classDiagram.jison';
import db from './classDb.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/class/classRenderer-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import utils from '../../utils.js';
import { interpolateToCurve, getStylesFromArray } from '../../utils.js';
import { setupGraphViewbox } from '../../setupGraphViewbox.js';
import common from '../common/common.js';
import { ClassRelation, ClassNote, ClassMap, EdgeData, NamespaceMap } from './classTypes.js';
import type { ClassRelation, ClassNote, ClassMap, EdgeData, NamespaceMap } from './classTypes.js';

const sanitizeText = (txt: string) => common.sanitizeText(txt, getConfig());

Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/common/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DOMPurify from 'dompurify';
import { MermaidConfig } from '../../config.type.js';
import type { MermaidConfig } from '../../config.type.js';

// Remove and ignore br:s
export const lineBreakRegex = /<br\s*\/?>/gi;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { findCommonAncestor, TreeData } from './render-utils.js';
import type { TreeData } from './render-utils.js';
import { findCommonAncestor } from './render-utils.js';
describe('when rendering a flowchart using elk ', () => {
let lookupDb: TreeData;
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/flowchart/flowDiagram-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import flowParser from './parser/flow.jison';
import flowDb from './flowDb.js';
import flowRendererV2 from './flowRenderer-v2.js';
import flowStyles from './styles.js';
import { MermaidConfig } from '../../config.type.js';
import type { MermaidConfig } from '../../config.type.js';
import { setConfig } from '../../config.js';

export const diagram = {
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/flowchart/flowDiagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import flowDb from './flowDb.js';
import flowRenderer from './flowRenderer.js';
import flowRendererV2 from './flowRenderer-v2.js';
import flowStyles from './styles.js';
import { MermaidConfig } from '../../config.type.js';
import type { MermaidConfig } from '../../config.type.js';

export const diagram = {
parser: flowParser,
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/gantt/ganttDiagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ganttParser from './parser/gantt.jison';
import ganttDb from './ganttDb.js';
import ganttRenderer from './ganttRenderer.js';
import ganttStyles from './styles.js';
import { DiagramDefinition } from '../../diagram-api/types.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';

export const diagram: DiagramDefinition = {
parser: ganttParser,
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/git/gitGraphDiagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import gitGraphParser from './parser/gitGraph.jison';
import gitGraphDb from './gitGraphAst.js';
import gitGraphRenderer from './gitGraphRenderer.js';
import gitGraphStyles from './styles.js';
import { DiagramDefinition } from '../../diagram-api/types.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';

export const diagram: DiagramDefinition = {
parser: gitGraphParser,
Expand Down
3 changes: 2 additions & 1 deletion packages/mermaid/src/diagrams/pie/pieRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import d3, { scaleOrdinal, pie as d3pie, arc } from 'd3';
import type d3 from 'd3';
import { scaleOrdinal, pie as d3pie, arc } from 'd3';

import { log } from '../../logger.js';
import { configureSvgSize } from '../../setupGraphViewbox.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-ignore: JISON doesn't support types
import { parser } from './quadrant.jison';
import { Mock, vi } from 'vitest';
import type { Mock } from 'vitest';
import { vi } from 'vitest';

const parserFnConstructor = (str: string) => {
return () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiagramDefinition } from '../../diagram-api/types.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: JISON doesn't support types
import parser from './parser/quadrant.jison';
import db from './quadrantDb.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { select } from 'd3';
import * as configApi from '../../config.js';
import { log } from '../../logger.js';
import { configureSvgSize } from '../../setupGraphViewbox.js';
import { Diagram } from '../../Diagram.js';
import {
import type { Diagram } from '../../Diagram.js';
import type {
QuadrantBuildType,
QuadrantLineType,
QuadrantPointType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiagramDefinition } from '../../diagram-api/types.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: JISON doesn't support types
import parser from './parser/requirementDiagram.jison';
import db from './requirementDb.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/sankey/sankeyDiagram.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiagramDefinition } from '../../diagram-api/types.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: jison doesn't export types
import parser from './parser/sankey.jison';
import db from './sankeyDB.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/diagrams/sankey/sankeyRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Diagram } from '../../Diagram.js';
import type { Diagram } from '../../Diagram.js';
import * as configApi from '../../config.js';

import {
Expand All @@ -7,14 +7,14 @@ import {
schemeTableau10 as d3schemeTableau10,
} from 'd3';

import type { SankeyNode as d3SankeyNode } from 'd3-sankey';
import {
sankey as d3Sankey,
sankeyLinkHorizontal as d3SankeyLinkHorizontal,
sankeyLeft as d3SankeyLeft,
sankeyRight as d3SankeyRight,
sankeyCenter as d3SankeyCenter,
sankeyJustify as d3SankeyJustify,
SankeyNode as d3SankeyNode,
} from 'd3-sankey';
import { configureSvgSize } from '../../setupGraphViewbox.js';
import { Uid } from '../../rendering-util/uid.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/sequence/sequenceDiagram.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiagramDefinition } from '../../diagram-api/types.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: JISON doesn't support types
import parser from './parser/sequenceDiagram.jison';
import db from './sequenceDb.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as configApi from '../../config.js';
import assignWithDepth from '../../assignWithDepth.js';
import utils from '../../utils.js';
import { configureSvgSize } from '../../setupGraphViewbox.js';
import { Diagram } from '../../Diagram.js';
import type { Diagram } from '../../Diagram.js';

let conf = {};

Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/state/stateDiagram-v2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiagramDefinition } from '../../diagram-api/types.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: JISON doesn't support types
import parser from './parser/stateDiagram.jison';
import db from './stateDb.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/state/stateDiagram.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiagramDefinition } from '../../diagram-api/types.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: JISON doesn't support types
import parser from './parser/stateDiagram.jison';
import db from './stateDb.js';
Expand Down
7 changes: 4 additions & 3 deletions packages/mermaid/src/diagrams/timeline/timelineRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// @ts-nocheck - don't check until handle it
import { select, Selection } from 'd3';
import type { Selection } from 'd3';
import { select } from 'd3';
import svgDraw from './svgDraw.js';
import { log } from '../../logger.js';
import { getConfig } from '../../config.js';
import { setupGraphViewbox } from '../../setupGraphViewbox.js';
import { Diagram } from '../../Diagram.js';
import { MermaidConfig } from '../../config.type.js';
import type { Diagram } from '../../Diagram.js';
import type { MermaidConfig } from '../../config.type.js';

interface Block<TDesc, TSection> {
number: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiagramDefinition } from '../../diagram-api/types.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: JISON doesn't support types
import parser from './parser/journey.jison';
import db from './journeyDb.js';
Expand Down
9 changes: 5 additions & 4 deletions packages/mermaid/src/mermaid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
* functionality and to render the diagrams to svg code!
*/
import { dedent } from 'ts-dedent';
import { MermaidConfig } from './config.type.js';
import type { MermaidConfig } from './config.type.js';
import { log } from './logger.js';
import utils from './utils.js';
import { mermaidAPI, ParseOptions, RenderResult } from './mermaidAPI.js';
import type { ParseOptions, RenderResult } from './mermaidAPI.js';
import { mermaidAPI } from './mermaidAPI.js';
import { registerLazyLoadedDiagrams, detectType } from './diagram-api/detectType.js';
import { loadRegisteredDiagrams } from './diagram-api/loadDiagram.js';
import type { ParseErrorFunction } from './Diagram.js';
import { isDetailedError } from './utils.js';
import type { DetailedError } from './utils.js';
import { ExternalDiagramDefinition } from './diagram-api/types.js';
import { UnknownDiagramError } from './errors.js';
import type { ExternalDiagramDefinition } from './diagram-api/types.js';
import type { UnknownDiagramError } from './errors.js';

export type {
MermaidConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/mermaidAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ vi.mock('./diagrams/state/stateRenderer-v2.js');
// -------------------------------------

import mermaid from './mermaid.js';
import { MermaidConfig } from './config.type.js';
import type { MermaidConfig } from './config.type.js';

import mermaidAPI, { removeExistingElements } from './mermaidAPI.js';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/mermaidAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import getStyles from './styles.js';
import theme from './themes/index.js';
import utils from './utils.js';
import DOMPurify from 'dompurify';
import { MermaidConfig } from './config.type.js';
import type { MermaidConfig } from './config.type.js';
import { evaluate } from './diagrams/common/common.js';
import isEmpty from 'lodash-es/isEmpty.js';
import { setA11yDiagramInfo, addSVGa11yTitleDescription } from './accessibility.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/rendering-util/createText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { log } from '../logger.js';
import { decodeEntities } from '../mermaidAPI.js';
import { markdownToHTML, markdownToLines } from '../rendering-util/handle-markdown-text.js';
import { splitLineToFitWidth } from './splitText.js';
import { MarkdownLine, MarkdownWord } from './types.js';
import type { MarkdownLine, MarkdownWord } from './types.js';

function applyStyle(dom, styleFn) {
if (styleFn) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Content } from 'mdast';
import { fromMarkdown } from 'mdast-util-from-markdown';
import { dedent } from 'ts-dedent';
import { MarkdownLine, MarkdownWordType } from './types.js';
import type { MarkdownLine, MarkdownWordType } from './types.js';

/**
* @param markdown - markdown to process
Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-nocheck : TODO Fix ts errors
import { sanitizeUrl } from '@braintree/sanitize-url';
import type { CurveFactory } from 'd3';
import {
curveBasis,
curveBasisClosed,
Expand All @@ -13,7 +14,6 @@ import {
curveCatmullRomClosed,
curveCatmullRomOpen,
curveCatmullRom,
CurveFactory,
curveLinear,
curveLinearClosed,
curveMonotoneX,
Expand All @@ -29,7 +29,7 @@ import { configKeys } from './defaultConfig.js';
import { log } from './logger.js';
import { detectType } from './diagram-api/detectType.js';
import assignWithDepth from './assignWithDepth.js';
import { MermaidConfig } from './config.type.js';
import type { MermaidConfig } from './config.type.js';
import memoize from 'lodash-es/memoize.js';
import merge from 'lodash-es/merge.js';
import { directiveRegex } from './diagram-api/regexes.js';
Expand Down

0 comments on commit 2ab393c

Please sign in to comment.