@jpeakai/mermaidjs-lint 0.1.1 → 0.3.0

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.
Files changed (78) hide show
  1. package/README.md +84 -53
  2. package/dist/bin.js +369 -92
  3. package/dist/index.js +376 -93
  4. package/dist/testing.js +145 -46
  5. package/dist/types/bin.d.ts +2 -0
  6. package/dist/types/check.d.ts +10 -0
  7. package/dist/types/cli.d.ts +9 -0
  8. package/dist/types/config.d.ts +20 -0
  9. package/dist/types/errors.d.ts +88 -0
  10. package/dist/types/files.d.ts +8 -0
  11. package/dist/types/fix/engine.d.ts +10 -0
  12. package/dist/types/fix/verify.d.ts +12 -0
  13. package/dist/types/index.d.ts +18 -0
  14. package/dist/types/model.d.ts +27 -0
  15. package/dist/types/parse/color.d.ts +28 -0
  16. package/dist/types/parse/contrast.d.ts +35 -0
  17. package/dist/types/parse/metrics.d.ts +48 -0
  18. package/dist/types/parse/stats.d.ts +24 -0
  19. package/dist/types/plugins/contract.d.ts +24 -0
  20. package/dist/types/plugins/discover.d.ts +20 -0
  21. package/dist/types/plugins/index.d.ts +19 -0
  22. package/dist/types/plugins/load.d.ts +14 -0
  23. package/dist/types/plugins/runtime.d.ts +6 -0
  24. package/dist/types/project.d.ts +18 -0
  25. package/dist/types/rules/complexity-node-count-acceptable-exceeded.d.ts +1 -0
  26. package/dist/types/rules/complexity-node-count-cognitive-limit.d.ts +1 -0
  27. package/dist/types/rules/complexity-node-count-hard-limit.d.ts +1 -0
  28. package/dist/types/rules/complexity-subgraph-nesting-too-deep.d.ts +2 -0
  29. package/dist/types/rules/complexity-visual-score-acceptable-exceeded.d.ts +1 -0
  30. package/dist/types/rules/complexity-visual-score-critical.d.ts +1 -0
  31. package/dist/types/rules/complexity.d.ts +12 -0
  32. package/dist/types/rules/contrast-border-below-ui-minimum.d.ts +2 -0
  33. package/dist/types/rules/contrast-directive-unauditable.d.ts +2 -0
  34. package/dist/types/rules/contrast-text-below-aa.d.ts +2 -0
  35. package/dist/types/rules/index.d.ts +3 -0
  36. package/dist/types/rules/parse-diagram-unparseable.d.ts +2 -0
  37. package/dist/types/rules/parse-fence-unterminated.d.ts +2 -0
  38. package/dist/types/rules/registry.d.ts +29 -0
  39. package/dist/types/rules/shared.d.ts +18 -0
  40. package/dist/types/rules/types.d.ts +67 -0
  41. package/dist/types/testing.d.ts +15 -0
  42. package/examples/architecture_beta_iconify_logos.mmd +27 -0
  43. package/examples/flowchart_fontawesome_icons.mmd +31 -0
  44. package/examples/layout_cosebilkent_mindmap.mmd +19 -0
  45. package/examples/layout_dagre_classic.mmd +22 -0
  46. package/examples/layout_dagre_handdrawn.mmd +23 -0
  47. package/examples/layout_dagre_neo.mmd +26 -0
  48. package/examples/layout_elk_default.mmd +22 -0
  49. package/examples/layout_elk_tuned.mmd +25 -0
  50. package/examples/layout_tidytree_mindmap.mmd +19 -0
  51. package/package.json +6 -5
  52. package/src/check.ts +2 -3
  53. package/src/cli.ts +88 -34
  54. package/src/config.ts +3 -2
  55. package/src/errors.ts +64 -3
  56. package/src/files.ts +24 -3
  57. package/src/fix/engine.ts +26 -14
  58. package/src/fix/verify.ts +8 -3
  59. package/src/index.ts +6 -4
  60. package/src/model.ts +10 -0
  61. package/src/parse/color.ts +2 -2
  62. package/src/parse/contrast.ts +59 -5
  63. package/src/parse/metrics.ts +16 -8
  64. package/src/parse/stats.ts +84 -30
  65. package/src/plugins/contract.ts +5 -3
  66. package/src/plugins/discover.ts +40 -17
  67. package/src/plugins/index.ts +5 -3
  68. package/src/plugins/load.ts +37 -4
  69. package/src/project.ts +14 -5
  70. package/src/rules/complexity-node-count-hard-limit.ts +1 -1
  71. package/src/rules/complexity-visual-score-critical.ts +2 -2
  72. package/src/rules/contrast-text-below-aa.ts +6 -2
  73. package/src/rules/index.ts +2 -1
  74. package/src/rules/parse-diagram-unparseable.ts +29 -14
  75. package/src/rules/registry.ts +7 -4
  76. package/src/rules/shared.ts +1 -1
  77. package/src/rules/types.ts +2 -2
  78. package/src/testing.ts +4 -3
package/README.md CHANGED
@@ -3,7 +3,10 @@
3
3
  Diagrams in documentation should be readable.
4
4
  Deterministic checks and verified fixes for Mermaid diagrams in markdown.
5
5
 
6
- **[Rules](RULES.md)** | **[GitHub](https://github.com/jpeakai/jpai-mermaidjs-lint)** | **[npm](https://www.npmjs.com/package/@jpeakai/mermaidjs-lint)**
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)**
7
+
8
+ This README and the docs site describe the `main` branch.
9
+ A feature on `main` but not yet on npm is listed under `Unreleased` in the [changelog](CHANGELOG.md).
7
10
 
8
11
  ## Usage
9
12
 
@@ -12,73 +15,74 @@ bunx @jpeakai/mermaidjs-lint README.md docs/ # report findings, exit 1 if an
12
15
  npx -y @jpeakai/mermaidjs-lint --fix docs/ # apply every fix proven safe, report the rest
13
16
  ```
14
17
 
15
- A path is a `.mmd` file, a markdown file whose mermaid fences are checked, or a directory.
16
- A directory is walked for both, and it skips `node_modules`, `dist`, `tmp` and dot-directories.
18
+ Pass your own paths: every path you name must exist, or the run stops with a usage error and exit 2.
19
+ A `.mmd` or `.mermaid` file is read as one diagram, and any other file you name is read as markdown.
20
+ A directory is walked for `.mmd`, `.mermaid`, `.md` and `.markdown` files.
21
+ The walk skips dot-folders and any folder named `node_modules`, `vendor`, `dist`, `build`, `tmp` or `__pycache__`, at any depth.
22
+ Installed as a dev dependency, the command is `mermaidjs-lint`, and `--help` lists every flag.
17
23
 
18
- Installed as a dev dependency, the command is `mermaidjs-lint`, and `--json` gives machine-readable output with a remediation for each finding.
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.
19
25
 
20
- `--preset NAME` sets the density for every complexity rule, as `low`, `medium` or `high`.
21
- `--profile NAME` sets how contrast is read, as `auto`, `github` or `mkdocs-material`.
22
- `--config FILE` reads a config other than the one at the project root.
23
- `--no-plugins` runs the built-in rules only, and `--lenient-plugins` skips a plugin that fails to load and says so.
24
- `--validate-plugins` loads and checks every plugin, reports every failure, and runs no check or fix.
25
- `--list-rules` prints every active rule by category, including plugin rules.
26
- Exit codes are 0 for clean, 1 for findings, and 2 for a usage error.
26
+ ## The four tenets
27
27
 
28
- ## The rules
28
+ Three tenets are guarantees about every diagram the tool passes, and the fourth is a commitment about the tool.
29
29
 
30
- Eleven rules in three categories.
31
- [RULES.md](RULES.md) shows a failing example for each one, and the fix where there is one.
32
- There is no warning level, so every finding fails the run.
33
- A rule you do not want is switched off in the config.
30
+ - **Readable in light and dark.** Declared fills, label colours and borders are scored as the host draws them, on nodes, erDiagram rows and edge labels, 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
34
 
35
- | Category | Rules | What it guards |
36
- |---|---|---|
37
- | Parse | parse-diagram-unparseable, parse-fence-unterminated | Whether mermaid can read the diagram, and whether its fence is whole |
38
- | Complexity | complexity-node-count-hard-limit, complexity-node-count-cognitive-limit, complexity-node-count-acceptable-exceeded, complexity-visual-score-critical, complexity-visual-score-acceptable-exceeded, complexity-subgraph-nesting-too-deep | How much a reader must hold in mind at once |
39
- | Contrast | contrast-text-below-aa, contrast-border-below-ui-minimum, contrast-directive-unauditable | Whether labels and borders can be read against their fills |
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 |
40
41
 
41
- Structure comes from mermaid's own parsers, never from patterns over the text.
42
- Every fix is verified by parsing the document again.
43
- A fix that would change the markdown or the structure of a diagram is refused, so the finding stays for a human.
44
- The reasoning behind each choice is recorded in [`adrs/`](adrs/index.md).
42
+ The [concepts page](https://jpeakai.github.io/jpai-mermaidjs-lint/concepts/) states the limit of each tenet.
43
+ `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
45
 
46
- ## Density presets
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.
51
+ It does not compare edge endpoints, edge labels or node text, so review the diff a fix writes.
47
52
 
48
- Complexity rules measure the nodes and a visual complexity score, and compare them with a preset.
53
+ ## Requirements and compatibility
49
54
 
50
- | Preset | Acceptable nodes | Cognitive limit | Hard limit |
51
- |---|---|---|---|
52
- | low-density | 12 | 20 | 35 |
53
- | medium-density | 20 | 35 | 60 |
54
- | high-density | 35 | 50 | 100 |
55
+ - **Runtime:** Bun, or Node `>=20` as the `engines` field of `package.json` states.
56
+ - **Mermaid:** the parse rules use the `mermaid` package, at `^11.14.0`, and `@mermaid-js/parser`, both installed with this package.
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.
55
58
 
56
- The default is `high-density`, which follows the research that 50 nodes is where a diagram becomes hard to read.
57
- Each threshold is also a rule option, such as `nodeAcceptable` or `vcsCritical`.
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.
58
61
 
59
- ## Plugins and local rules
62
+ ## Configure and extend
60
63
 
61
- A project adds its own rules without forking this package.
62
- Both sources load on their own, with no config, and every run prints a line saying what it loaded.
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.
63
68
 
64
- - **Local rules.** A `.js`, `.mjs`, `.ts` or `.mts` file in `.mermaidjs-lint/rules/` exports one rule, and its id is `local/` followed by the file name.
65
- - **Plugin packages.** A dependency named `mermaidjs-lint-plugin-name` or `@scope/mermaidjs-lint-plugin-name` loads under the namespace its own `meta.namespace` declares.
66
- - **New categories.** A plugin declares a category of its own, and its rules use it.
67
- - **Same treatment.** A plugin rule is switched off, given options and listed exactly like a built-in, and its fixer is verified like a built-in fixer.
69
+ ## Use it from an AI agent
68
70
 
69
- A config at the project root switches rules off and sets options.
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:
70
76
 
71
- ```json
72
- {
73
- "rules": {
74
- "complexity-subgraph-nesting-too-deep": "off",
75
- "complexity-node-count-acceptable-exceeded": ["error", { "preset": "medium" }],
76
- "contrast-text-below-aa": ["error", { "profile": "mkdocs-material" }]
77
- }
78
- }
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
79
81
  ```
80
82
 
81
- [docs/plugins.md](docs/plugins.md) is the guide to writing a rule.
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.
82
86
 
83
87
  ## Library use
84
88
 
@@ -89,13 +93,40 @@ const findings = await checkMarkdown(src, "README.md");
89
93
  const fixed = await fixSource(src, "README.md");
90
94
  ```
91
95
 
92
- A plugin author tests a rule with `@jpeakai/mermaidjs-lint/testing`, which runs the same loader checks and verified fixer as a real run.
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.
98
+
99
+ ## Versioning
100
+
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.
104
+
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.
109
+
110
+ ## Support
111
+
112
+ Report a bug or ask a question in [GitHub issues](https://github.com/jpeakai/jpai-mermaidjs-lint/issues).
113
+ A bug report needs:
114
+
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`.
93
119
 
94
120
  ## Origin
95
121
 
96
- The checks port the logic of the `mermaidjs-diagrams` skill scripts, which measured complexity and contrast for Mermaid diagrams.
122
+ The checks port an earlier set of diagram-checking scripts, which measured complexity and contrast for Mermaid diagrams.
97
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).
98
125
 
99
126
  ## Contributing
100
127
 
101
128
  [CONTRIBUTING.md](CONTRIBUTING.md) covers setup and how a change is accepted.
129
+
130
+ ## Licence
131
+
132
+ MIT, as stated in [LICENSE](LICENSE).