mdrefine 0.2.0-rc.2 → 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/CHANGELOG.md +577 -0
- package/CODE_OF_CONDUCT.md +30 -0
- package/CONTRIBUTING.md +189 -16
- package/README.md +100 -154
- package/SECURITY.md +15 -13
- package/config.schema.json +91 -0
- package/dist/cli/diff.d.ts +10 -0
- package/dist/cli/diff.js +247 -0
- package/dist/cli/diff.js.map +1 -0
- package/dist/cli/main.js +270 -150
- package/dist/cli/main.js.map +1 -1
- package/dist/config/load.js +67 -6
- package/dist/config/load.js.map +1 -1
- package/dist/config/problems.d.ts +7 -0
- package/dist/config/problems.js +208 -0
- package/dist/config/problems.js.map +1 -0
- package/dist/config/resolve.d.ts +42 -109
- package/dist/config/resolve.js +193 -52
- package/dist/config/resolve.js.map +1 -1
- package/dist/core/directives.d.ts +7 -0
- package/dist/core/directives.js +25 -13
- package/dist/core/directives.js.map +1 -1
- package/dist/core/engine.d.ts +42 -4
- package/dist/core/engine.js +518 -79
- package/dist/core/engine.js.map +1 -1
- package/dist/core/frozen.d.ts +6 -0
- package/dist/core/frozen.js +15 -0
- package/dist/core/frozen.js.map +1 -0
- package/dist/core/scope.d.ts +30 -0
- package/dist/core/scope.js +122 -0
- package/dist/core/scope.js.map +1 -0
- package/dist/core/types.d.ts +202 -23
- package/dist/core/types.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +3 -0
- package/dist/node.js +4 -0
- package/dist/node.js.map +1 -0
- package/dist/rules/blocks.d.ts +34 -0
- package/dist/rules/blocks.js +550 -0
- package/dist/rules/blocks.js.map +1 -0
- package/dist/rules/content.d.ts +2 -0
- package/dist/rules/content.js +85 -0
- package/dist/rules/content.js.map +1 -0
- package/dist/rules/dialects.js +10 -6
- package/dist/rules/dialects.js.map +1 -1
- package/dist/rules/links.js +302 -6
- package/dist/rules/links.js.map +1 -1
- package/dist/rules/lists.d.ts +2 -0
- package/dist/rules/lists.js +924 -0
- package/dist/rules/lists.js.map +1 -0
- package/dist/rules/structure.js +127 -1
- package/dist/rules/structure.js.map +1 -1
- package/dist/rules/style.d.ts +8 -2
- package/dist/rules/style.js +1137 -165
- package/dist/rules/style.js.map +1 -1
- package/dist/syntax/block-identifier.d.ts +18 -0
- package/dist/syntax/block-identifier.js +24 -0
- package/dist/syntax/block-identifier.js.map +1 -0
- package/dist/syntax/obsidian.d.ts +29 -11
- package/dist/syntax/obsidian.js +9 -10
- package/dist/syntax/obsidian.js.map +1 -1
- package/dist/syntax/parse.d.ts +87 -3
- package/dist/syntax/parse.js +247 -19
- package/dist/syntax/parse.js.map +1 -1
- package/dist/workspace/access.d.ts +12 -3
- package/dist/workspace/access.js +33 -5
- package/dist/workspace/access.js.map +1 -1
- package/dist/workspace/discovery.d.ts +85 -0
- package/dist/workspace/discovery.js +155 -0
- package/dist/workspace/discovery.js.map +1 -0
- package/dist/workspace/encoding.d.ts +24 -0
- package/dist/workspace/encoding.js +113 -0
- package/dist/workspace/encoding.js.map +1 -0
- package/dist/workspace/files.d.ts +92 -6
- package/dist/workspace/files.js +715 -59
- package/dist/workspace/files.js.map +1 -1
- package/dist/workspace/git.d.ts +54 -0
- package/dist/workspace/git.js +198 -0
- package/dist/workspace/git.js.map +1 -0
- package/dist/workspace/index.d.ts +58 -3
- package/dist/workspace/index.js +136 -37
- package/dist/workspace/index.js.map +1 -1
- package/dist/workspace/selection.d.ts +2 -2
- package/dist/workspace/selection.js +3 -3
- package/dist/workspace/selection.js.map +1 -1
- package/dist/workspace/slug.js +8 -1
- package/dist/workspace/slug.js.map +1 -1
- package/dist/workspace/vault.js +3 -1
- package/dist/workspace/vault.js.map +1 -1
- package/docs/api.md +239 -0
- package/docs/benchmarks.md +140 -200
- package/docs/changelog.md +1 -0
- package/docs/cli.md +281 -89
- package/docs/configuration.md +193 -480
- package/docs/design.md +163 -284
- package/docs/dialects.md +169 -0
- package/docs/examples.md +151 -109
- package/docs/index.md +21 -37
- package/docs/integrations.md +144 -0
- package/docs/obsidian.md +91 -115
- package/docs/plugins.md +147 -212
- package/docs/quick-start.md +68 -74
- package/docs/rules.md +1237 -0
- package/docs/versions.md +56 -0
- package/examples/README.md +17 -14
- package/examples/automation/summarize-report.mjs +5 -2
- package/examples/library/lint-folder.mjs +5 -4
- package/examples/library/lint-workspace.mjs +32 -0
- package/examples/plugin/notes/release-checklist.md +2 -2
- package/examples/plugin/rules.mjs +17 -23
- package/examples/workspaces/obsidian-vault/after/mdtools.config.jsonc +2 -2
- package/examples/workspaces/obsidian-vault/before/mdtools.config.jsonc +2 -2
- package/examples/workspaces/repository-docs/after/README.md +2 -2
- package/examples/workspaces/repository-docs/after/mdtools.config.jsonc +0 -2
- package/examples/workspaces/repository-docs/before/README.md +2 -2
- package/examples/workspaces/repository-docs/before/docs/guide.md +7 -7
- package/examples/workspaces/repository-docs/before/docs/reference.md +3 -1
- package/examples/workspaces/repository-docs/before/mdtools.config.jsonc +0 -2
- package/package.json +38 -12
- package/docs/contributing.md +0 -218
- package/docs/releases/0.1.0-beta.1.md +0 -39
- package/docs/releases/0.1.0-beta.2.md +0 -83
- package/docs/releases/0.1.0-beta.3.md +0 -61
- package/docs/releases/0.1.0-beta.4.md +0 -50
- package/docs/releases/0.1.0-rc.1.md +0 -99
- package/docs/releases/0.2.0-rc.1.md +0 -141
- package/docs/releases/0.2.0-rc.2.md +0 -225
- package/docs/releases.md +0 -144
- package/docs/testing.md +0 -93
package/dist/core/directives.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { walk } from "../syntax/walk.js";
|
|
2
2
|
import { range } from "../syntax/parse.js";
|
|
3
|
+
/** The directive that an HTML node's value holds, if it is one. */
|
|
4
|
+
export function directive(value) {
|
|
5
|
+
const match = /^<!--\s*mdtools-(disable-next-line|disable|enable)(?:\s+([^]*?))?\s*-->$/.exec(value.trim());
|
|
6
|
+
if (!match)
|
|
7
|
+
return undefined;
|
|
8
|
+
const names = match[2]
|
|
9
|
+
?.trim()
|
|
10
|
+
.split(/[\s,]+/)
|
|
11
|
+
.filter(Boolean) ?? ["*"];
|
|
12
|
+
return { kind: match[1], rules: new Set(names.length ? names : ["*"]) };
|
|
13
|
+
}
|
|
3
14
|
/** Directives are recognized only in parsed HTML comments, never in code examples. */
|
|
4
15
|
export function suppressions(document) {
|
|
5
16
|
// Directives can only appear in HTML comments containing this prefix.
|
|
@@ -8,23 +19,24 @@ export function suppressions(document) {
|
|
|
8
19
|
const intervals = [];
|
|
9
20
|
const active = new Map();
|
|
10
21
|
walk(document.tree, "html", (node) => {
|
|
11
|
-
const
|
|
12
|
-
if (!
|
|
22
|
+
const found = directive(node.value);
|
|
23
|
+
if (!found)
|
|
13
24
|
return;
|
|
14
|
-
const
|
|
15
|
-
?.trim()
|
|
16
|
-
.split(/[\s,]+/)
|
|
17
|
-
.filter(Boolean) ?? ["*"];
|
|
18
|
-
const rules = new Set(names.length ? names : ["*"]);
|
|
25
|
+
const { rules } = found;
|
|
19
26
|
const [start, end] = range(node);
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
if (found.kind === "disable-next-line") {
|
|
28
|
+
// The line after the directive's own, whichever of CommonMark's line endings ends each.
|
|
29
|
+
const lineBreak = /\r\n|\r|\n/g;
|
|
30
|
+
lineBreak.lastIndex = end;
|
|
31
|
+
const first = lineBreak.exec(document.source);
|
|
32
|
+
if (!first)
|
|
23
33
|
return;
|
|
24
|
-
const
|
|
25
|
-
|
|
34
|
+
const next = first.index + first[0].length;
|
|
35
|
+
lineBreak.lastIndex = next;
|
|
36
|
+
const last = lineBreak.exec(document.source);
|
|
37
|
+
intervals.push({ start: next, end: last ? last.index : document.source.length, rules });
|
|
26
38
|
}
|
|
27
|
-
else if (
|
|
39
|
+
else if (found.kind === "disable") {
|
|
28
40
|
for (const rule of rules)
|
|
29
41
|
if (!active.has(rule))
|
|
30
42
|
active.set(rule, end);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"directives.js","sourceRoot":"","sources":["../../src/core/directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"directives.js","sourceRoot":"","sources":["../../src/core/directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAO3C,mEAAmE;AACnE,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,MAAM,KAAK,GAAG,0EAA0E,CAAC,IAAI,CAC3F,KAAK,CAAC,IAAI,EAAE,CACb,CAAC;IACF,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;QACpB,EAAE,IAAI,EAAE;SACP,KAAK,CAAC,QAAQ,CAAC;SACf,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5B,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAsB,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;AAC/F,CAAC;AACD,sFAAsF;AACtF,MAAM,UAAU,YAAY,CAAC,QAAkB;IAC7C,sEAAsE;IACtE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC;IAC9D,MAAM,SAAS,GAAyD,EAAE,CAAC;IAC3E,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAA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ourcesContent":["import { walk } from \"../syntax/walk.js\";\nimport type { Document, Finding } from \"./types.js\";\nimport { range } from \"../syntax/parse.js\";\n\n/** A suppression directive and the rules it names, `*` for all of them. */\nexport interface Directive {\n kind: \"disable-next-line\" | \"disable\" | \"enable\";\n rules: Set<string>;\n}\n/** The directive that an HTML node's value holds, if it is one. */\nexport function directive(value: string): Directive | undefined {\n const match = /^<!--\\s*mdtools-(disable-next-line|disable|enable)(?:\\s+([^]*?))?\\s*-->$/.exec(\n value.trim(),\n );\n if (!match) return undefined;\n const names = match[2]\n ?.trim()\n .split(/[\\s,]+/)\n .filter(Boolean) ?? [\"*\"];\n return { kind: match[1] as Directive[\"kind\"], rules: new Set(names.length ? names : [\"*\"]) };\n}\n/** Directives are recognized only in parsed HTML comments, never in code examples. */\nexport function suppressions(document: Document): (rule: string, finding: Finding) => boolean {\n // Directives can only appear in HTML comments containing this prefix.\n if (!document.source.includes(\"mdtools-\")) return () => false;\n const intervals: { start: number; end: number; rules: Set<string> }[] = [];\n const active = new Map<string, number>();\n walk(document.tree, \"html\", (node) => {\n const found = directive(node.value);\n if (!found) return;\n const { rules } = found;\n const [start, end] = range(node);\n if (found.kind === \"disable-next-line\") {\n // The line after the directive's own, whichever of CommonMark's line endings ends each.\n const lineBreak = /\\r\\n|\\r|\\n/g;\n lineBreak.lastIndex = end;\n const first = lineBreak.exec(document.source);\n if (!first) return;\n const next = first.index + first[0].length;\n lineBreak.lastIndex = next;\n const last = lineBreak.exec(document.source);\n intervals.push({ start: next, end: last ? last.index : document.source.length, rules });\n } else if (found.kind === \"disable\") {\n for (const rule of rules) if (!active.has(rule)) active.set(rule, end);\n } else {\n for (const rule of rules.has(\"*\") ? active.keys() : rules) {\n const from = active.get(rule);\n if (from !== undefined) intervals.push({ start: from, end: start, rules: new Set([rule]) });\n active.delete(rule);\n }\n }\n });\n for (const [rule, start] of active)\n intervals.push({ start, end: document.source.length, rules: new Set([rule]) });\n return (rule, finding) =>\n intervals.some((interval) => {\n const start = finding.edit?.start ?? finding.start;\n const end = finding.edit?.end ?? finding.end ?? finding.start;\n return (\n (interval.rules.has(\"*\") || interval.rules.has(rule)) &&\n start <= interval.end &&\n end >= interval.start\n );\n });\n}\n"]}
|
package/dist/core/engine.d.ts
CHANGED
|
@@ -1,8 +1,46 @@
|
|
|
1
1
|
import type { Diagnostic, Document, Edit, FormatResult, Plugin, ProcessOptions, Rule, Workspace } from "./types.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The built-in rules by rule ID. The table and the rules in it are frozen, so
|
|
4
|
+
* that no caller can change what another one runs.
|
|
5
|
+
*/
|
|
6
|
+
export declare const builtInRules: Readonly<Record<string, Readonly<Rule>>>;
|
|
7
|
+
/**
|
|
8
|
+
* The prefix of the engine's own diagnostics, such as `engine/rule-error`. A
|
|
9
|
+
* plugin of this name could report findings that pass for the engine's, which
|
|
10
|
+
* concern the whole document and make the CLI exit with code 2.
|
|
11
|
+
*/
|
|
12
|
+
export declare const reservedPluginName = "engine";
|
|
13
|
+
/**
|
|
14
|
+
* The built-in rules and those of `plugins`, by rule ID, in a new table. A
|
|
15
|
+
* plugin name that is invalid, reserved, or used twice, a rule ID that exists
|
|
16
|
+
* already, and a plugin rule that does not have the shape of a `Rule` are
|
|
17
|
+
* errors that name them.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ruleRegistry(plugins?: readonly Plugin[]): Record<string, Readonly<Rule>>;
|
|
20
|
+
/**
|
|
21
|
+
* The diagnostics of the enabled rules for `source`, sorted by position. A rule
|
|
22
|
+
* that fails is skipped and reported as `engine/rule-error`. An invalid
|
|
23
|
+
* configuration, an unknown rule, invalid rule options, an invalid plugin, and
|
|
24
|
+
* an error that the workspace throws are thrown.
|
|
25
|
+
*/
|
|
4
26
|
export declare function lint(source: string, options?: ProcessOptions): Diagnostic[];
|
|
5
|
-
|
|
6
|
-
|
|
27
|
+
/**
|
|
28
|
+
* `source` with `edits` applied, which are `{ start, end, text }` replacements
|
|
29
|
+
* at UTF-16 offsets into it. Repeats of one edit count once; an edit outside
|
|
30
|
+
* the source, or one that overlaps another, is an error.
|
|
31
|
+
*/
|
|
32
|
+
export declare function applyEdits(source: string, edits: readonly Edit[]): string;
|
|
33
|
+
/**
|
|
34
|
+
* The meaning of a parsed document as text, which `format` compares before and
|
|
35
|
+
* after edits to refuse a change of meaning: its syntax tree without positions,
|
|
36
|
+
* with runs of whitespace in text alike, and with each link's destination as
|
|
37
|
+
* the workspace resolves it, so that two spellings of one target are the same.
|
|
38
|
+
*/
|
|
7
39
|
export declare function semanticFingerprint(document: Document, workspace?: Workspace): string;
|
|
40
|
+
/**
|
|
41
|
+
* Format a document: apply the edits of the enabled style rules, in passes
|
|
42
|
+
* until nothing changes, leaving out the edits of a rule that would change the
|
|
43
|
+
* document's meaning. Byte order marks that it starts with stay in the output
|
|
44
|
+
* and are not part of what the rules see. Errors are thrown as by `lint`.
|
|
45
|
+
*/
|
|
8
46
|
export declare function format(source: string, options?: ProcessOptions): FormatResult;
|