@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 CHANGED
@@ -1,132 +1,66 @@
1
- # jpai-mermaidjs-lint
1
+ # mermaidjs-lint
2
2
 
3
- Diagrams in documentation should be readable.
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
- **[Docs](https://jpeakai.github.io/jpai-mermaidjs-lint/)** | **[Rules](https://jpeakai.github.io/jpai-mermaidjs-lint/reference/rules/)** | **[Changelog](CHANGELOG.md)** | **[GitHub](https://github.com/jpeakai/jpai-mermaidjs-lint)** | **[npm](https://www.npmjs.com/package/@jpeakai/mermaidjs-lint)**
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
- The docs site describes the latest release on npm.
9
- This README, read on GitHub, describes the `main` branch.
10
- A change on `main` that is not yet released is listed under `Unreleased` in the [changelog](CHANGELOG.md).
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
- ## Usage
11
+ ## Lint your docs with one command
13
12
 
14
13
  ```sh
15
- bunx @jpeakai/mermaidjs-lint README.md docs/ # report findings, exit 1 if any
16
- npx -y @jpeakai/mermaidjs-lint --fix docs/ # apply every fix proven safe, report the rest
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
- `npm ls mermaid` in your project prints the mermaid version a run uses.
60
- [Reference](https://jpeakai.github.io/jpai-mermaidjs-lint/reference/#requirements-and-compatibility) lists which parser reads each diagram type.
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
- Use `~/.claude/skills/mermaidjs-lint` instead to use it in every project.
84
- Another agent can follow `SKILL.md` as plain instructions.
85
- [Agent evals](https://jpeakai.github.io/jpai-mermaidjs-lint/gallery/agent-evals/) shows how well agents fixed the failing fixtures it lists, and which skill revision they used.
86
-
87
- ## Library use
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
- These calls run the built-in rules only, and read no config file and no plugin.
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
- ## Versioning
32
+ ## Fix unreadable label text and unclosed fences
100
33
 
101
- The package follows semantic versioning, and while it is at `0.x` a minor release may break the public surface.
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
- ## Security
106
-
107
- A plugin is code that runs on your machine, and plugins load on their own once a project depends on them.
108
- [SECURITY.md](SECURITY.md) covers the supported versions, the trust model and how to report a vulnerability privately.
36
+ ```diff
37
+ - classDef warn fill:#ffd400,color:#ffffff
38
+ + classDef warn fill:#ffd400,color:#000000
39
+ ```
109
40
 
110
- ## Support
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
- Report a bug or ask a question in [GitHub issues](https://github.com/jpeakai/jpai-mermaidjs-lint/issues).
113
- A bug report needs:
44
+ ## Four tenets
114
45
 
115
- - The version, from `mermaidjs-lint --version`, or from `npm ls @jpeakai/mermaidjs-lint` on 0.1.1 and earlier.
116
- - The command you ran.
117
- - The diagram, or the smallest file that shows the problem.
118
- - The output of the same command with `--json`.
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
- ## Origin
51
+ ## Go further in the docs site
121
52
 
122
- The checks port an earlier set of diagram-checking scripts, which measured complexity and contrast for Mermaid diagrams.
123
- The package shape, the plugin mechanism and the fix verification follow [jpai-prose-gates](https://github.com/jpeakai/jpai-prose-gates).
124
- The reasoning behind each choice is recorded in [`adrs/`](adrs/index.md).
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
- ## Contributing
58
+ ## Runs on Bun or Node
127
59
 
128
- [CONTRIBUTING.md](CONTRIBUTING.md) covers setup and how a change is accepted.
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
- ## Licence
63
+ ## Contribute
131
64
 
132
- MIT, as stated in [LICENSE](LICENSE).
65
+ [CONTRIBUTING.md](CONTRIBUTING.md) covers setup.
66
+ Licensed under [MIT](LICENSE).