@jpeakai/mermaidjs-lint 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -109
- package/dist/bin.js +691 -578
- package/dist/index.js +691 -578
- package/dist/testing.js +471 -411
- package/dist/types/parse/contrast.d.ts +6 -1
- package/dist/types/parse/graph.d.ts +16 -0
- package/dist/types/rules/shared.d.ts +5 -1
- package/package.json +1 -1
- package/src/check.ts +13 -11
- package/src/cli.ts +153 -90
- package/src/files.ts +23 -18
- package/src/fix/engine.ts +82 -57
- package/src/fix/verify.ts +13 -8
- package/src/model.ts +1 -1
- package/src/parse/color.ts +1 -1
- package/src/parse/contrast.ts +308 -228
- package/src/parse/graph.ts +98 -0
- package/src/parse/metrics.ts +1 -1
- package/src/parse/stats.ts +111 -82
- package/src/plugins/discover.ts +13 -15
- package/src/plugins/index.ts +66 -37
- package/src/plugins/load.ts +94 -61
- package/src/rules/complexity.ts +1 -1
- package/src/rules/contrast-text-below-aa.ts +34 -21
- package/src/rules/parse-diagram-unparseable.ts +1 -1
- package/src/rules/parse-fence-unterminated.ts +5 -7
- package/src/rules/registry.ts +38 -16
- package/src/rules/shared.ts +8 -3
package/README.md
CHANGED
|
@@ -1,132 +1,66 @@
|
|
|
1
|
-
#
|
|
1
|
+
# mermaidjs-lint
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Deterministic checks and verified fixes for Mermaid diagrams in markdown.
|
|
3
|
+
| **[Docs](https://jpeakai.github.io/jpai-mermaidjs-lint/)** | **[Rules](https://jpeakai.github.io/jpai-mermaidjs-lint/reference/rules/)** | **[Changelog](CHANGELOG.md)** | **[npm](https://www.npmjs.com/package/@jpeakai/mermaidjs-lint)** |
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
I hate walls of text. I do _**love**_ a good diagram though. mermaidjs is brilliant for separating the _**semantic structure**_ of a diagram from _**the pixel pushing**_.
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
AI Agents love this separation too. And yet AI Agents kind of suck at diagrams though. So here is a linting and autofixer engine built on top of:
|
|
8
|
+
- [`mermaid`](https://www.npmjs.com/package/mermaid) parsing libraries
|
|
9
|
+
- [`colorjs.io`](https://www.npmjs.com/package/colorjs.io) for official [WCAG 2.1](https://colorjs.io/docs/contrast#wcag-21) colour contrast readability scoring.
|
|
11
10
|
|
|
12
|
-
##
|
|
11
|
+
## Lint your docs with one command
|
|
13
12
|
|
|
14
13
|
```sh
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Pass your own paths: every path you name must exist, or the run stops with a usage error and exit 2.
|
|
20
|
-
A `.mmd` or `.mermaid` file is read as one diagram, and any other file you name is read as markdown.
|
|
21
|
-
A directory is walked for `.mmd`, `.mermaid`, `.md` and `.markdown` files.
|
|
22
|
-
Installed as a dev dependency, the command is `mermaidjs-lint`, and `--help` lists every flag.
|
|
23
|
-
|
|
24
|
-
[Get started](https://jpeakai.github.io/jpai-mermaidjs-lint/get-started/) walks through a first run, a fix, and adding the check to a project.
|
|
25
|
-
|
|
26
|
-
## The four tenets
|
|
27
|
-
|
|
28
|
-
Three tenets are guarantees about every diagram the tool passes, and the fourth is a commitment about the tool.
|
|
29
|
-
|
|
30
|
-
- **Readable in light and dark.** Declared fills, label colours and borders are scored as the host draws them, on nodes, erDiagram rows, edge labels and sequence diagrams, in both themes.
|
|
31
|
-
- **Renders.** Every diagram parses with the mermaid parsers this package ships, and every mermaid fence is closed.
|
|
32
|
-
- **Simple enough to follow.** Node count and visual complexity are scored against a density preset, so an oversized diagram is flagged to be split.
|
|
33
|
-
- **Extensible.** A plugin adds rules of your own, which run through the same config, fix engine and verification as the built-ins.
|
|
34
|
-
|
|
35
|
-
| Tenet | Delivered by |
|
|
36
|
-
|---|---|
|
|
37
|
-
| Readable in light and dark | The contrast rules |
|
|
38
|
-
| Renders | The parse rules |
|
|
39
|
-
| Simple enough to follow | The complexity rules |
|
|
40
|
-
| Extensible | Local rules and plugin packages |
|
|
41
|
-
|
|
42
|
-
The [concepts page](https://jpeakai.github.io/jpai-mermaidjs-lint/concepts/) states the limit of each tenet.
|
|
43
|
-
`bunx @jpeakai/mermaidjs-lint --list-rules` prints every rule.
|
|
44
|
-
The [rules page](https://jpeakai.github.io/jpai-mermaidjs-lint/reference/rules/) draws each one before and after `--fix`, and [RULES.md](RULES.md) holds the same examples as plain markdown.
|
|
45
|
-
|
|
46
|
-
Every finding fails the run, and a rule you do not want is switched off in the config.
|
|
47
|
-
Node, edge and subgraph counts come from mermaid's own parsers.
|
|
48
|
-
Style directives are read line by line, so a style joined to other statements by a semicolon is not seen.
|
|
49
|
-
Every fix is verified by parsing the document again, and a fix that fails the check is refused, so the finding stays for a human.
|
|
50
|
-
The check holds the markdown outside the diagrams unchanged, and each diagram's type, node ids, subgraph names and counts, and whether it parses.
|
|
51
|
-
It does not compare edge endpoints, edge labels or node text, so review the diff a fix writes.
|
|
52
|
-
|
|
53
|
-
## Requirements and compatibility
|
|
54
|
-
|
|
55
|
-
- **Runtime:** Bun, or Node `>=20` as the `engines` field of `package.json` states.
|
|
56
|
-
- **Mermaid:** the parse and contrast rules use the `mermaid` package at exactly `11.17.2`, and `@mermaid-js/parser`, both installed with this package. The pin holds sequence diagram colours, which change between mermaid releases.
|
|
57
|
-
- **Your host's mermaid may differ.** GitHub and other hosts draw diagrams with their own mermaid version. A diagram type newer than the host's may parse here and still fail to draw there.
|
|
14
|
+
# bunx
|
|
15
|
+
bunx @jpeakai/mermaidjs-lint docs/
|
|
16
|
+
bunx @jpeakai/mermaidjs-lint --fix docs/
|
|
58
17
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
## Configure and extend
|
|
63
|
-
|
|
64
|
-
- [Configure the rules](https://jpeakai.github.io/jpai-mermaidjs-lint/guides/configure/): switch a rule off, change the complexity preset, set options.
|
|
65
|
-
- [Lint a MkDocs Material site](https://jpeakai.github.io/jpai-mermaidjs-lint/guides/mkdocs/): score diagrams the way the theme renders them.
|
|
66
|
-
- [Write a local rule](https://jpeakai.github.io/jpai-mermaidjs-lint/guides/local-rule/) or [publish a plugin package](https://jpeakai.github.io/jpai-mermaidjs-lint/guides/plugin-package/): add rules of your own, which load with no config.
|
|
67
|
-
- [Troubleshooting](https://jpeakai.github.io/jpai-mermaidjs-lint/guides/troubleshooting/): a README that fails after adding `mkdocs.yml`, skipping a diagram, and other common questions.
|
|
68
|
-
|
|
69
|
-
## Use it from an AI agent
|
|
70
|
-
|
|
71
|
-
[`skills/mermaidjs-lint/`](skills/mermaidjs-lint/SKILL.md) is an agent skill that runs the linter, applies the safe fixes, then fixes what remains by judgement.
|
|
72
|
-
It is not in the npm package, so copy it from this repository.
|
|
73
|
-
The skill is the one file `SKILL.md`.
|
|
74
|
-
Its `evals/` folder holds deliberately failing fixtures for this repository's own tests, so never copy it.
|
|
75
|
-
For Claude Code, run these in your project:
|
|
76
|
-
|
|
77
|
-
```sh
|
|
78
|
-
mkdir -p .claude/skills/mermaidjs-lint
|
|
79
|
-
curl -fsSL https://raw.githubusercontent.com/jpeakai/jpai-mermaidjs-lint/main/skills/mermaidjs-lint/SKILL.md \
|
|
80
|
-
-o .claude/skills/mermaidjs-lint/SKILL.md
|
|
18
|
+
# npx
|
|
19
|
+
npx -y @jpeakai/mermaidjs-lint docs/
|
|
20
|
+
npx -y @jpeakai/mermaidjs-lint --fix docs/
|
|
81
21
|
```
|
|
82
22
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
import { checkMarkdown, fixSource } from "@jpeakai/mermaidjs-lint";
|
|
91
|
-
|
|
92
|
-
const findings = await checkMarkdown(src, "README.md");
|
|
93
|
-
const fixed = await fixSource(src, "README.md");
|
|
23
|
+
```text
|
|
24
|
+
docs/architecture.md:6 contrast-text-below-aa classDef warn: text 1.43:1 < 4.5 (#ffffff on #ffd400)
|
|
25
|
+
docs/login.md:3-7 parse-diagram-unparseable sequenceDiagram did not parse (parser: mermaid-core) (its line numbers count within the diagram, not the file): Parse error on line 3: Expecting 'TXT', got 'NEWLINE'
|
|
26
|
+
docs/pipeline.md:3-41 complexity-node-count-acceptable-exceeded 37 nodes > 35 acceptable threshold
|
|
27
|
+
3 finding(s) in 3 file(s)
|
|
94
28
|
```
|
|
95
29
|
|
|
96
|
-
|
|
97
|
-
The [Library API](https://jpeakai.github.io/jpai-mermaidjs-lint/reference/library-api/) page lists every export, and shows how to run with the config and plugins as the command does.
|
|
30
|
+
The run exits 1 while any finding remains, so it works as a CI gate.
|
|
98
31
|
|
|
99
|
-
##
|
|
32
|
+
## Fix unreadable label text and unclosed fences
|
|
100
33
|
|
|
101
|
-
|
|
102
|
-
[Versioning](https://jpeakai.github.io/jpai-mermaidjs-lint/reference/#versioning) lists what that surface is.
|
|
103
|
-
[CHANGELOG.md](CHANGELOG.md) lists what changed in each release, and what is on `main` but not yet released.
|
|
34
|
+
Add `--fix` to apply the fixes that pass verification:
|
|
104
35
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
36
|
+
```diff
|
|
37
|
+
- classDef warn fill:#ffd400,color:#ffffff
|
|
38
|
+
+ classDef warn fill:#ffd400,color:#000000
|
|
39
|
+
```
|
|
109
40
|
|
|
110
|
-
|
|
41
|
+
A fix is kept only if the markdown around the diagrams is unchanged and each diagram reparses with the same node ids, subgraphs and counts.
|
|
42
|
+
Edge endpoints, edge labels and node text are not compared, so review the diff.
|
|
111
43
|
|
|
112
|
-
|
|
113
|
-
A bug report needs:
|
|
44
|
+
## Four tenets
|
|
114
45
|
|
|
115
|
-
-
|
|
116
|
-
-
|
|
117
|
-
-
|
|
118
|
-
-
|
|
46
|
+
- **Always readable in light mode or dark mode.** Declared fills, label colours and borders are scored as the host draws them, on nodes, erDiagram rows, edge labels and sequence diagrams, in both themes.
|
|
47
|
+
- **It actually renders a valid diagram.** Every diagram parses with the mermaid parsers this package ships, and every mermaid fence is closed.
|
|
48
|
+
- **Visual Complexity stays readable.** Node count and visual complexity are scored against a density preset, so an oversized diagram is flagged to be split.
|
|
49
|
+
- **Make your own rules.** A plugin adds rules of your own, which run through the same config, fix engine and verification as the built-ins.
|
|
119
50
|
|
|
120
|
-
##
|
|
51
|
+
## Go further in the docs site
|
|
121
52
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
53
|
+
- [Get started](https://jpeakai.github.io/jpai-mermaidjs-lint/get-started/): run it, fix a diagram, and add the gate to your project.
|
|
54
|
+
- [Use it in CI](https://jpeakai.github.io/jpai-mermaidjs-lint/guides/ci/) or [before each commit](https://jpeakai.github.io/jpai-mermaidjs-lint/guides/pre-commit/).
|
|
55
|
+
- [Configure the rules](https://jpeakai.github.io/jpai-mermaidjs-lint/guides/configure/)
|
|
56
|
+
- [Write a project local rule](https://jpeakai.github.io/jpai-mermaidjs-lint/guides/local-rule/).
|
|
125
57
|
|
|
126
|
-
##
|
|
58
|
+
## Runs on Bun or Node
|
|
127
59
|
|
|
128
|
-
|
|
60
|
+
It needs Bun, or Node `>=20`.
|
|
61
|
+
The package installs mermaid `11.17.2` to parse diagrams, and your host may draw with another version.
|
|
129
62
|
|
|
130
|
-
##
|
|
63
|
+
## Contribute
|
|
131
64
|
|
|
132
|
-
|
|
65
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) covers setup.
|
|
66
|
+
Licensed under [MIT](LICENSE).
|