@jpeakai/mermaidjs-lint 0.1.0 → 0.2.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.
- package/README.md +82 -53
- package/dist/bin.js +202 -44
- package/dist/index.js +206 -45
- package/dist/testing.js +86 -23
- package/examples/architecture_beta_iconify_logos.mmd +27 -0
- package/examples/flowchart_fontawesome_icons.mmd +31 -0
- package/examples/layout_cosebilkent_mindmap.mmd +19 -0
- package/examples/layout_dagre_classic.mmd +22 -0
- package/examples/layout_dagre_handdrawn.mmd +23 -0
- package/examples/layout_dagre_neo.mmd +26 -0
- package/examples/layout_elk_default.mmd +22 -0
- package/examples/layout_elk_tuned.mmd +25 -0
- package/examples/layout_tidytree_mindmap.mmd +19 -0
- package/package.json +2 -2
- package/src/check.ts +2 -3
- package/src/cli.ts +45 -23
- package/src/config.ts +3 -2
- package/src/errors.ts +18 -3
- package/src/files.ts +3 -1
- package/src/fix/engine.ts +4 -4
- package/src/fix/verify.ts +2 -2
- package/src/index.ts +1 -1
- package/src/model.ts +10 -0
- package/src/parse/color.ts +2 -2
- package/src/parse/contrast.ts +59 -5
- package/src/parse/metrics.ts +16 -8
- package/src/parse/stats.ts +45 -19
- package/src/plugins/contract.ts +1 -1
- package/src/plugins/discover.ts +5 -5
- package/src/plugins/load.ts +5 -3
- package/src/project.ts +11 -4
- package/src/rules/complexity-node-count-hard-limit.ts +1 -1
- package/src/rules/complexity-visual-score-critical.ts +2 -2
- package/src/rules/contrast-text-below-aa.ts +6 -2
- package/src/rules/index.ts +2 -1
- package/src/rules/parse-diagram-unparseable.ts +29 -14
- package/src/rules/registry.ts +7 -4
- package/src/rules/shared.ts +1 -1
- package/src/rules/types.ts +2 -2
- package/src/testing.ts +4 -3
package/src/rules/registry.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// The registry: the rules a run actually uses. It starts from the built-in
|
|
2
2
|
// catalogue, adds whatever plugins loaded, then applies the config, so a rule
|
|
3
|
-
// that is off loses its check and its fixer together.
|
|
4
|
-
//
|
|
3
|
+
// that is off loses its check and its fixer together. Every check and fix reads
|
|
4
|
+
// the registry, which is what lets a plugin rule behave as a built-in. The CLI
|
|
5
|
+
// help reads the built-in catalogue directly.
|
|
5
6
|
|
|
6
7
|
import type { Config } from "../config.ts";
|
|
7
8
|
import { RuleOptionError, UnknownRuleError } from "../errors.ts";
|
|
@@ -45,7 +46,8 @@ export interface RegistryInput {
|
|
|
45
46
|
categories: ReadonlyMap<string, string>;
|
|
46
47
|
sources?: LoadedSource[];
|
|
47
48
|
config?: Config;
|
|
48
|
-
// A lenient run drops a setting for an
|
|
49
|
+
// A lenient or collect (validating) run drops a setting for an unloaded
|
|
50
|
+
// plugin rule instead of failing. A built-in id always fails.
|
|
49
51
|
ignoreUnknownPluginIds?: boolean;
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -92,7 +94,8 @@ export const buildRegistry = (input: RegistryInput): Registry => {
|
|
|
92
94
|
const rule = rules.find((r) => r.id === id);
|
|
93
95
|
if (!rule) {
|
|
94
96
|
// A plugin that was skipped cannot have its rules configured, so a lenient
|
|
95
|
-
// run drops the setting and says so. A built-in id
|
|
97
|
+
// or collect (validating) run drops the setting and says so. A built-in id
|
|
98
|
+
// always fails.
|
|
96
99
|
if (ignoreUnknownPluginIds && isPluginRuleId(id)) {
|
|
97
100
|
ignored.push(id);
|
|
98
101
|
continue;
|
package/src/rules/shared.ts
CHANGED
|
@@ -93,5 +93,5 @@ export const contrastOf = (diagram: Diagram, profile: Profile): ContrastResult =
|
|
|
93
93
|
return result;
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
-
//
|
|
96
|
+
// Maps a diagram-relative line to a file line.
|
|
97
97
|
export const fileLine = (diagram: Diagram, line: number): number => diagram.firstLine + line - 1;
|
package/src/rules/types.ts
CHANGED
|
@@ -20,14 +20,14 @@ export const RULE = {
|
|
|
20
20
|
UNAUDITABLE: "contrast-directive-unauditable",
|
|
21
21
|
} as const;
|
|
22
22
|
|
|
23
|
-
// A core id has no slash. A plugin id is always namespace/name, so the slash
|
|
24
|
-
// is what tells the two apart.
|
|
25
23
|
export type CoreRuleId = (typeof RULE)[keyof typeof RULE];
|
|
26
24
|
|
|
27
25
|
export type Awaitable<T> = T | Promise<T>;
|
|
28
26
|
|
|
29
27
|
export type PluginRuleId = `${string}/${string}`;
|
|
30
28
|
|
|
29
|
+
// A core id has no slash. A plugin id is always namespace/name, so the slash
|
|
30
|
+
// is what tells the two apart.
|
|
31
31
|
export const isPluginRuleId = (id: string): id is PluginRuleId => id.includes("/");
|
|
32
32
|
|
|
33
33
|
export type RuleId = CoreRuleId | PluginRuleId;
|
package/src/testing.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// A test helper for plugin authors: run one plugin rule over real strings, with
|
|
2
|
-
// the same
|
|
3
|
-
// a real run. It
|
|
4
|
-
//
|
|
2
|
+
// the same contract checks as the loader, the same context and the same
|
|
3
|
+
// verified fix engine as a real run. It skips the reserved `local` namespace
|
|
4
|
+
// and cross-plugin conflict checks. It is a separate entry point so a plugin's
|
|
5
|
+
// tests import it and production code never does.
|
|
5
6
|
|
|
6
7
|
import { checkMarkdown, type RunFlags } from "./check.ts";
|
|
7
8
|
import { type FixReport, fixSourceReport } from "./fix/engine.ts";
|