@jpeakai/mermaidjs-lint 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +100 -2
- package/dist/bin.js +2521 -0
- package/dist/index.js +2556 -0
- package/dist/testing.js +1832 -0
- package/package.json +68 -4
- package/src/bin.ts +10 -0
- package/src/check.ts +48 -0
- package/src/cli.ts +275 -0
- package/src/config.ts +119 -0
- package/src/errors.ts +191 -0
- package/src/files.ts +66 -0
- package/src/fix/engine.ts +110 -0
- package/src/fix/verify.ts +65 -0
- package/src/index.ts +41 -0
- package/src/model.ts +146 -0
- package/src/parse/color.ts +155 -0
- package/src/parse/contrast.ts +280 -0
- package/src/parse/metrics.ts +180 -0
- package/src/parse/stats.ts +718 -0
- package/src/plugins/contract.ts +41 -0
- package/src/plugins/discover.ts +140 -0
- package/src/plugins/index.ts +103 -0
- package/src/plugins/load.ts +248 -0
- package/src/plugins/runtime.ts +15 -0
- package/src/project.ts +81 -0
- package/src/rules/complexity-node-count-acceptable-exceeded.ts +15 -0
- package/src/rules/complexity-node-count-cognitive-limit.ts +15 -0
- package/src/rules/complexity-node-count-hard-limit.ts +17 -0
- package/src/rules/complexity-subgraph-nesting-too-deep.ts +17 -0
- package/src/rules/complexity-visual-score-acceptable-exceeded.ts +15 -0
- package/src/rules/complexity-visual-score-critical.ts +17 -0
- package/src/rules/complexity.ts +35 -0
- package/src/rules/contrast-border-below-ui-minimum.ts +36 -0
- package/src/rules/contrast-directive-unauditable.ts +32 -0
- package/src/rules/contrast-text-below-aa.ts +75 -0
- package/src/rules/index.ts +33 -0
- package/src/rules/parse-diagram-unparseable.ts +30 -0
- package/src/rules/parse-fence-unterminated.ts +47 -0
- package/src/rules/registry.ts +122 -0
- package/src/rules/shared.ts +97 -0
- package/src/rules/types.ts +104 -0
- package/src/testing.ts +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Josh Peak
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,101 @@
|
|
|
1
|
-
#
|
|
1
|
+
# jpai-mermaidjs-lint
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Diagrams in documentation should be readable.
|
|
4
|
+
Deterministic checks and verified fixes for Mermaid diagrams in markdown.
|
|
5
|
+
|
|
6
|
+
**[Rules](RULES.md)** | **[GitHub](https://github.com/jpeakai/jpai-mermaidjs-lint)** | **[npm](https://www.npmjs.com/package/@jpeakai/mermaidjs-lint)**
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
bunx @jpeakai/mermaidjs-lint README.md docs/ # report findings, exit 1 if any
|
|
12
|
+
npx -y @jpeakai/mermaidjs-lint --fix docs/ # apply every fix proven safe, report the rest
|
|
13
|
+
```
|
|
14
|
+
|
|
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.
|
|
17
|
+
|
|
18
|
+
Installed as a dev dependency, the command is `mermaidjs-lint`, and `--json` gives machine-readable output with a remediation for each finding.
|
|
19
|
+
|
|
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.
|
|
27
|
+
|
|
28
|
+
## The rules
|
|
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.
|
|
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 |
|
|
40
|
+
|
|
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).
|
|
45
|
+
|
|
46
|
+
## Density presets
|
|
47
|
+
|
|
48
|
+
Complexity rules measure the nodes and a visual complexity score, and compare them with a preset.
|
|
49
|
+
|
|
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
|
+
|
|
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`.
|
|
58
|
+
|
|
59
|
+
## Plugins and local rules
|
|
60
|
+
|
|
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.
|
|
63
|
+
|
|
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.
|
|
68
|
+
|
|
69
|
+
A config at the project root switches rules off and sets options.
|
|
70
|
+
|
|
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
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
[docs/plugins.md](docs/plugins.md) is the guide to writing a rule.
|
|
82
|
+
|
|
83
|
+
## Library use
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { checkMarkdown, fixSource } from "@jpeakai/mermaidjs-lint";
|
|
87
|
+
|
|
88
|
+
const findings = await checkMarkdown(src, "README.md");
|
|
89
|
+
const fixed = await fixSource(src, "README.md");
|
|
90
|
+
```
|
|
91
|
+
|
|
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.
|
|
93
|
+
|
|
94
|
+
## Origin
|
|
95
|
+
|
|
96
|
+
The checks port the logic of the `mermaidjs-diagrams` skill scripts, which measured complexity and contrast for Mermaid diagrams.
|
|
97
|
+
The package shape, the plugin mechanism and the fix verification follow [jpai-prose-gates](https://github.com/jpeakai/jpai-prose-gates).
|
|
98
|
+
|
|
99
|
+
## Contributing
|
|
100
|
+
|
|
101
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) covers setup and how a change is accepted.
|