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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problems.js","sourceRoot":"","sources":["../../src/config/problems.ts"],"names":[],"mappings":"AAEA,kFAAkF;AAClF,MAAM,UAAU,KAAK,CAAC,KAAc;IAClC,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG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C,KAAK,CAAC,EAAE;gCAC9B,CAAC,CAAC,GAAG,KAAK,IAAI,KAAK,CAAC,OAAO,IAAI,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAC5F,CAAC;oBACJ,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,YAAY,CAC1B,MAA8B,EAC9B,KAAc,EACd,QAA2B;IAE3B,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC;AAC5E,CAAC;AACD,kFAAkF;AAClF,MAAM,UAAU,YAAY,CAAC,MAA8B,EAAE,KAAc;IACzE,OAAO,OAAO,CACZ,MAAM,EACN,KAAK,EACL,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACT,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC;QACtB,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,aAAa;KAC1D,CAAC,EACF,QAAQ,CACT,CAAC;AACJ,CAAC","sourcesContent":["import type { ErrorObject } from \"ajv\";\n\n/** A short description of a value that was given where something else belongs. */\nexport function shown(value: unknown): string {\n switch (typeof value) {\n case \"string\":\n return JSON.stringify(value.length > 40 ? `${value.slice(0, 40)}…` : value);\n case \"number\":\n case \"bigint\":\n case \"boolean\":\n case \"undefined\":\n return String(value);\n case \"function\":\n return \"a function\";\n case \"symbol\":\n return \"a symbol\";\n default:\n return value === null ? \"null\" : Array.isArray(value) ? \"a list\" : \"an object\";\n }\n}\n/** Alternatives in prose: `\"a\", \"b\", or \"c\"`. */\nfunction either(items: readonly string[]): string {\n return items.length < 3\n ? items.join(\" or \")\n : `${items.slice(0, -1).join(\", \")}, or ${items.at(-1)}`;\n}\n/** The keys of a JSON pointer, such as `/rules/style~1wrap`, unescaped. */\nfunction keys(pointer: string): string[] {\n return pointer\n ? pointer\n .slice(1)\n .split(\"/\")\n .map((key) => key.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"))\n : [];\n}\n/** Keys as a path written the way a reader finds them in a file: `overrides[0].files`. */\nfunction written(path: readonly string[]): string {\n let text = \"\";\n for (const key of path) text += /^\\d+$/.test(key) ? `[${key}]` : text ? `.${key}` : key;\n return text;\n}\n/** The part of `value` at `path`. */\nfunction at(value: unknown, path: readonly string[]): unknown {\n for (const key of path)\n value =\n value && typeof value === \"object\" && Object.hasOwn(value, key)\n ? (value as Record<string, unknown>)[key]\n : undefined;\n return value;\n}\nconst typeWords: Record<string, string> = {\n string: \"a string\",\n number: \"a number\",\n integer: \"an integer\",\n boolean: \"true or false\",\n object: \"an object\",\n array: \"a list\",\n null: \"null\",\n};\n/** Limits in plain words, by keyword. */\nconst limits: Record<string, (limit: unknown) => string> = {\n minimum: (limit) => `must be at least ${String(limit)}`,\n maximum: (limit) => `must be at most ${String(limit)}`,\n exclusiveMinimum: (limit) => `must be more than ${String(limit)}`,\n exclusiveMaximum: (limit) => `must be less than ${String(limit)}`,\n minItems: (limit) => `must hold at least ${String(limit)} item(s)`,\n maxItems: (limit) => `must hold at most ${String(limit)} item(s)`,\n minLength: (limit) => `must be at least ${String(limit)} character(s) long`,\n maxLength: (limit) => `must be at most ${String(limit)} character(s) long`,\n};\n/** Keywords whose failure means that the value itself is of the wrong kind, so naming it helps. */\nconst kinds = new Set([\"type\", \"enum\", \"const\"]);\n\n/** What a part of the configuration is called in a message, and what it must be. */\ninterface Place {\n /** Places of one setting, whose errors are reported together. */\n setting: string;\n label: string;\n expected?: string;\n}\nconst severities = either(['\"off\"', '\"warn\"', '\"error\"']);\n/** Where `path` lies in a configuration, or in the override `scope` when it is set. */\nfunction place(path: readonly string[], dialects: readonly string[], scope?: string): Place {\n const [key, ...rest] = path;\n const name = (keys: readonly string[]) => `\"${scope ? `${scope}.` : \"\"}${written(keys)}\"`;\n const setting = written(scope ? [scope, ...path.slice(0, 1)] : path.slice(0, 1));\n const item = (whole: string, one: string): Place =>\n rest.length\n ? { setting, label: name(path.slice(0, 2)), expected: one }\n : { setting, label: name(path), expected: whole };\n switch (key) {\n case undefined:\n return scope\n ? { setting: scope, label: `\"${scope}\"`, expected: 'an object with \"files\"' }\n : { setting: \"\", label: \"the configuration\", expected: \"an object\" };\n case \"$schema\":\n return { setting, label: name(path), expected: \"a string\" };\n case \"resolve\":\n return rest.length\n ? {\n setting: written(path.slice(0, 2)),\n label: name(path.slice(0, 2)),\n expected: \"true or false\",\n }\n : { setting, label: name(path), expected: \"an object\" };\n case \"extends\":\n return item(\"a preset name or a list of preset names\", \"a preset name\");\n case \"dialect\":\n return { setting, label: name(path), expected: either(dialects.map((item) => `\"${item}\"`)) };\n case \"ignore\":\n return item(\"a list of path patterns\", \"a path pattern\");\n case \"plugins\":\n return item(\"a list of file or package names\", \"a file or package name\");\n case \"files\":\n return item(\"a list of one or more path patterns\", \"a path pattern\");\n case \"rules\": {\n const [id, part] = rest;\n if (id === undefined)\n return { setting, label: name(path), expected: \"an object of rule IDs and their settings\" };\n const of = `\"${id}\"${scope ? ` in \"${scope}\"` : \"\"}`;\n const rule = `${setting}/${id}`;\n if (part === \"0\")\n return { setting: rule, label: `the severity of ${of}`, expected: severities };\n if (part === \"1\")\n return { setting: rule, label: `the options of ${of}`, expected: \"an object\" };\n return {\n setting: rule,\n label: `the setting of ${of}`,\n expected: `${severities}, or a list of a severity and, optionally, the rule's options`,\n };\n }\n case \"overrides\": {\n const [index, ...inside] = rest;\n if (index === undefined)\n return { setting, label: name(path), expected: 'a list of objects with \"files\"' };\n return place(inside, dialects, `overrides[${index}]`);\n }\n default:\n return { setting: written(path), label: name(path) };\n }\n}\n\n/**\n * Validation errors of a JSON Schema as one message in plain words, with each\n * part named as it is written in the file: `\"extends[1]\" must be a preset name,\n * not 5`. `describe` names a part and says what it must be; without\n * `expected`, the validator's own words say it. Of the errors of one setting,\n * only those deepest in the value are kept: they are the ones that a list or\n * an object allowed as a whole still breaks.\n */\nfunction phrased(\n errors: readonly ErrorObject[],\n value: unknown,\n describe: (path: readonly string[]) => Place,\n unknown: string,\n): string {\n const messages = new Set<string>();\n /** The remaining errors of each setting, at the depth that counts. */\n const settings = new Map<string, { depth: number; errors: ErrorObject[] }>();\n for (const error of errors) {\n const path = keys(error.instancePath);\n if (error.keyword === \"additionalProperties\") {\n const extra = String((error.params as { additionalProperty: string }).additionalProperty);\n messages.add(`unknown ${unknown} \"${written([...path, extra])}\"`);\n continue;\n }\n if (error.keyword === \"required\") {\n const missing = String((error.params as { missingProperty: string }).missingProperty);\n messages.add(`${describe(path).label} must have \"${missing}\"`);\n continue;\n }\n // A summary of alternatives that each failed; the alternatives say how.\n if (error.keyword === \"anyOf\" || error.keyword === \"oneOf\") continue;\n const { setting } = describe(path);\n const held = settings.get(setting);\n if (!held || path.length > held.depth)\n settings.set(setting, { depth: path.length, errors: [error] });\n else if (path.length === held.depth) held.errors.push(error);\n }\n for (const { errors: kept } of settings.values()) {\n const byPath = new Map<string, ErrorObject[]>();\n for (const error of kept)\n byPath.set(error.instancePath, [...(byPath.get(error.instancePath) ?? []), error]);\n for (const [pointer, group] of byPath) {\n const path = keys(pointer);\n const { label, expected } = describe(path);\n const given = group.every((error) => kinds.has(error.keyword))\n ? `, not ${shown(at(value, path))}`\n : \"\";\n if (expected) messages.add(`${label} must be ${expected}${given}`);\n else {\n const types = group.flatMap((error) =>\n error.keyword === \"type\" ? [error.params as { type: string | string[] }] : [],\n );\n if (types.length === group.length)\n messages.add(\n `${label} must be ${either(types.flatMap(({ type }) => type).map((type) => typeWords[type] ?? type))}${given}`,\n );\n else\n for (const error of group) {\n const { allowedValues, limit } = error.params as {\n allowedValues?: unknown[];\n limit?: unknown;\n };\n const limited = limits[error.keyword];\n messages.add(\n error.keyword === \"enum\" && allowedValues\n ? `${label} must be ${either(allowedValues.map((item) => JSON.stringify(item)))}${given}`\n : limited && limit !== undefined\n ? `${label} ${limited(limit)}`\n : `${label} ${error.message ?? \"is not valid\"}${kinds.has(error.keyword) ? given : \"\"}`,\n );\n }\n }\n }\n }\n return [...messages].join(\"; \");\n}\n\n/** The configuration's validation errors in plain words, naming each setting as it is written. */\nexport function configErrors(\n errors: readonly ErrorObject[],\n value: unknown,\n dialects: readonly string[],\n): string {\n return phrased(errors, value, (path) => place(path, dialects), \"setting\");\n}\n/** A rule's option errors in plain words, naming each option as it is written. */\nexport function optionErrors(errors: readonly ErrorObject[], value: unknown): string {\n return phrased(\n errors,\n value,\n (path) => ({\n setting: written(path),\n label: path.length ? `\"${written(path)}\"` : \"the options\",\n }),\n \"option\",\n );\n}\n"]}
|
package/dist/config/resolve.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type { Config, Dialect, DialectName,
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { Config, Dialect, DialectName, JsonSchemaObject, ResolveConfigOptions, ResolvedConfig, RuleSetting } from "../core/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Alias names that select an existing dialect, mapped to that dialect:
|
|
4
|
+
* Codeberg runs Forgejo's renderer. The table is frozen.
|
|
5
|
+
*/
|
|
6
|
+
export declare const dialectAliases: Readonly<Record<Exclude<DialectName, Dialect>, Dialect>>;
|
|
7
|
+
/** The dialects, in the order the documentation lists them. The list is frozen. */
|
|
8
|
+
export declare const dialects: readonly Dialect[];
|
|
5
9
|
/**
|
|
6
10
|
* The dialect assumed when nothing names one and the caller knows no better.
|
|
7
11
|
* GitHub's syntax is the common base of the Forgejo, Gitea, and Obsidian
|
|
@@ -9,116 +13,45 @@ export declare const dialects: Dialect[];
|
|
|
9
13
|
* ordinary paragraph and reflowed.
|
|
10
14
|
*/
|
|
11
15
|
export declare const fallbackDialect: Dialect;
|
|
16
|
+
/**
|
|
17
|
+
* The dialect that `name` stands for: an alias's dialect, or `name` itself.
|
|
18
|
+
* A name that is neither is returned as it is.
|
|
19
|
+
*/
|
|
12
20
|
export declare function canonicalDialect(name: DialectName): Dialect;
|
|
13
|
-
|
|
14
|
-
export declare
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
type: string;
|
|
28
|
-
};
|
|
29
|
-
nestedRepositories: {
|
|
30
|
-
type: string;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
extends: {
|
|
35
|
-
type: string;
|
|
36
|
-
items: {
|
|
37
|
-
type: string;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
dialect: {
|
|
41
|
-
enum: string[];
|
|
42
|
-
};
|
|
43
|
-
rules: {
|
|
44
|
-
type: string;
|
|
45
|
-
additionalProperties: {
|
|
46
|
-
anyOf: ({
|
|
47
|
-
enum: string[];
|
|
48
|
-
} | {
|
|
49
|
-
type: string;
|
|
50
|
-
items: ({
|
|
51
|
-
enum: string[];
|
|
52
|
-
} | {
|
|
53
|
-
type: string;
|
|
54
|
-
})[];
|
|
55
|
-
minItems: number;
|
|
56
|
-
maxItems: number;
|
|
57
|
-
})[];
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
ignore: {
|
|
61
|
-
type: string;
|
|
62
|
-
items: {
|
|
63
|
-
type: string;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
plugins: {
|
|
67
|
-
type: string;
|
|
68
|
-
items: {
|
|
69
|
-
type: string;
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
overrides: {
|
|
73
|
-
type: string;
|
|
74
|
-
items: {
|
|
75
|
-
type: string;
|
|
76
|
-
required: string[];
|
|
77
|
-
additionalProperties: boolean;
|
|
78
|
-
properties: {
|
|
79
|
-
files: {
|
|
80
|
-
type: string;
|
|
81
|
-
items: {
|
|
82
|
-
type: string;
|
|
83
|
-
};
|
|
84
|
-
minItems: number;
|
|
85
|
-
};
|
|
86
|
-
dialect: {
|
|
87
|
-
enum: string[];
|
|
88
|
-
};
|
|
89
|
-
rules: {
|
|
90
|
-
type: string;
|
|
91
|
-
additionalProperties: {
|
|
92
|
-
anyOf: ({
|
|
93
|
-
enum: string[];
|
|
94
|
-
} | {
|
|
95
|
-
type: string;
|
|
96
|
-
items: ({
|
|
97
|
-
enum: string[];
|
|
98
|
-
} | {
|
|
99
|
-
type: string;
|
|
100
|
-
})[];
|
|
101
|
-
minItems: number;
|
|
102
|
-
maxItems: number;
|
|
103
|
-
})[];
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
/** What is wrong with `value` as a configuration, or undefined when it is valid. */
|
|
21
|
+
/** The dialect that `name` stands for, or an error that says what was named. */
|
|
22
|
+
export declare function knownDialect(name: DialectName, what?: string): Dialect;
|
|
23
|
+
/**
|
|
24
|
+
* The built-in presets by name. The table and everything in it are frozen, so
|
|
25
|
+
* that no caller can change what another one gets.
|
|
26
|
+
*/
|
|
27
|
+
export declare const presets: Readonly<Record<string, Readonly<Config>>>;
|
|
28
|
+
/**
|
|
29
|
+
* The configuration's JSON Schema, which `validateConfig` enforces. The
|
|
30
|
+
* package ships it as `config.schema.json`, which a test keeps equal to it,
|
|
31
|
+
* and the documentation site serves it for editors.
|
|
32
|
+
*/
|
|
33
|
+
export declare const configSchema: JsonSchemaObject;
|
|
34
|
+
/** What is wrong with `value` as a configuration, in plain words, or undefined when it is valid. */
|
|
112
35
|
export declare function configProblem(value: unknown): string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Throws an error that says what is wrong when `value` is not a configuration
|
|
38
|
+
* that `configSchema` describes, naming each setting as it is written, as in
|
|
39
|
+
* `Invalid configuration: "extends[1]" must be a preset name, not 5`. Rule IDs,
|
|
40
|
+
* preset names, and rule options are checked when a document is processed.
|
|
41
|
+
*/
|
|
113
42
|
export declare function validateConfig(value: unknown): asserts value is Config;
|
|
114
43
|
export declare function setting(value: RuleSetting): {
|
|
115
44
|
severity: "off" | "warn" | "error";
|
|
116
|
-
options: Record<string, unknown
|
|
45
|
+
options: Readonly<Record<string, unknown>>;
|
|
117
46
|
};
|
|
118
47
|
/**
|
|
119
|
-
* The configuration in effect for
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
48
|
+
* The configuration in effect for one document: its dialect, rule settings,
|
|
49
|
+
* `ignore` patterns, and `resolve` settings. It takes the `path`, `config`,
|
|
50
|
+
* `plugins`, and `defaultDialect` that `lint` and `format` take, so their
|
|
51
|
+
* options serve as they are. `defaultDialect` is the dialect to assume when
|
|
52
|
+
* neither the configuration, a preset, nor a matching override names one:
|
|
53
|
+
* `github` unless the caller knows better, as the CLI does inside an Obsidian
|
|
54
|
+
* vault. An invalid configuration or default dialect, an unknown preset, and a
|
|
55
|
+
* cycle of presets throw an error.
|
|
123
56
|
*/
|
|
124
|
-
export declare function resolveConfig(
|
|
57
|
+
export declare function resolveConfig(options?: ResolveConfigOptions): ResolvedConfig;
|
package/dist/config/resolve.js
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { Ajv } from "ajv";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { Minimatch } from "minimatch";
|
|
3
|
+
import { configErrors } from "./problems.js";
|
|
4
|
+
import { deepFreeze } from "../core/frozen.js";
|
|
5
|
+
/**
|
|
6
|
+
* Alias names that select an existing dialect, mapped to that dialect:
|
|
7
|
+
* Codeberg runs Forgejo's renderer. The table is frozen.
|
|
8
|
+
*/
|
|
9
|
+
export const dialectAliases = Object.freeze({ codeberg: "forgejo" });
|
|
10
|
+
/** The dialects, in the order the documentation lists them. The list is frozen. */
|
|
11
|
+
export const dialects = Object.freeze([
|
|
12
|
+
"commonmark",
|
|
13
|
+
"github",
|
|
14
|
+
"forgejo",
|
|
15
|
+
"gitea",
|
|
16
|
+
"obsidian",
|
|
17
|
+
]);
|
|
6
18
|
/**
|
|
7
19
|
* The dialect assumed when nothing names one and the caller knows no better.
|
|
8
20
|
* GitHub's syntax is the common base of the Forgejo, Gitea, and Obsidian
|
|
@@ -10,17 +22,49 @@ export const dialects = ["commonmark", "github", "forgejo", "gitea", "obsidian"]
|
|
|
10
22
|
* ordinary paragraph and reflowed.
|
|
11
23
|
*/
|
|
12
24
|
export const fallbackDialect = "github";
|
|
25
|
+
/**
|
|
26
|
+
* The dialect that `name` stands for: an alias's dialect, or `name` itself.
|
|
27
|
+
* A name that is neither is returned as it is.
|
|
28
|
+
*/
|
|
13
29
|
export function canonicalDialect(name) {
|
|
14
|
-
return dialectAliases
|
|
30
|
+
return Object.hasOwn(dialectAliases, name)
|
|
31
|
+
? dialectAliases[name]
|
|
32
|
+
: name;
|
|
33
|
+
}
|
|
34
|
+
/** The dialect that `name` stands for, or an error that says what was named. */
|
|
35
|
+
export function knownDialect(name, what = "dialect") {
|
|
36
|
+
const dialect = canonicalDialect(name);
|
|
37
|
+
if (!dialects.includes(dialect))
|
|
38
|
+
throw new Error(`Unknown ${what}: ${String(name)}`);
|
|
39
|
+
return dialect;
|
|
15
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The built-in presets by name. The table and everything in it are frozen, so
|
|
43
|
+
* that no caller can change what another one gets.
|
|
44
|
+
*/
|
|
16
45
|
export const presets = {
|
|
17
46
|
recommended: {
|
|
18
47
|
rules: {
|
|
19
48
|
"style/wrap": ["warn", { width: 80 }],
|
|
20
49
|
"style/emphasis": ["warn", { marker: "_" }],
|
|
21
50
|
"style/strong": ["warn", { marker: "*" }],
|
|
51
|
+
"style/heading": "warn",
|
|
52
|
+
"style/table": "warn",
|
|
53
|
+
"style/code-fence": "warn",
|
|
54
|
+
"style/thematic-break": "warn",
|
|
55
|
+
"style/blank-lines": "warn",
|
|
56
|
+
"style/trailing-space": "warn",
|
|
22
57
|
"style/final-newline": "warn",
|
|
58
|
+
"style/list-marker": ["warn", { marker: "-" }],
|
|
59
|
+
"style/ordered-list": ["warn", { delimiter: ".", numbering: "auto" }],
|
|
60
|
+
"style/list-indent": "warn",
|
|
23
61
|
"links/valid": "error",
|
|
62
|
+
"links/undefined-reference": "warn",
|
|
63
|
+
"links/unused-definition": "warn",
|
|
64
|
+
"links/empty": "warn",
|
|
65
|
+
"structure/heading-increment": "warn",
|
|
66
|
+
"content/image-alt": "warn",
|
|
67
|
+
"content/table-columns": "warn",
|
|
24
68
|
},
|
|
25
69
|
},
|
|
26
70
|
github: {
|
|
@@ -57,97 +101,193 @@ export const presets = {
|
|
|
57
101
|
},
|
|
58
102
|
},
|
|
59
103
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
104
|
+
deepFreeze(presets);
|
|
105
|
+
// Each dialect is followed by its aliases, as the command line lists them.
|
|
106
|
+
const dialectNames = dialects.flatMap((dialect) => [
|
|
107
|
+
dialect,
|
|
108
|
+
...Object.entries(dialectAliases).flatMap(([alias, of]) => (of === dialect ? [alias] : [])),
|
|
109
|
+
]);
|
|
110
|
+
const strings = { type: "array", items: { type: "string" } };
|
|
111
|
+
/**
|
|
112
|
+
* The configuration's JSON Schema, which `validateConfig` enforces. The
|
|
113
|
+
* package ships it as `config.schema.json`, which a test keeps equal to it,
|
|
114
|
+
* and the documentation site serves it for editors.
|
|
115
|
+
*/
|
|
116
|
+
export const configSchema = deepFreeze({
|
|
72
117
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
118
|
+
title: "mdtools configuration",
|
|
119
|
+
description: "Configuration of the mdtools command of mdrefine: https://viell-dev.github.io/slop-markdown-tools/configuration.html",
|
|
73
120
|
type: "object",
|
|
74
121
|
additionalProperties: false,
|
|
75
122
|
properties: {
|
|
76
|
-
$schema: { type: "string" },
|
|
123
|
+
$schema: { description: "The JSON Schema for editors; the tool ignores it.", type: "string" },
|
|
77
124
|
resolve: {
|
|
125
|
+
description: "Files that links may lead to, which are never linted or formatted.",
|
|
78
126
|
type: "object",
|
|
79
127
|
additionalProperties: false,
|
|
80
|
-
properties: {
|
|
128
|
+
properties: {
|
|
129
|
+
gitIgnored: {
|
|
130
|
+
description: "Files that .gitignore files exclude are link targets. Default: false.",
|
|
131
|
+
type: "boolean",
|
|
132
|
+
},
|
|
133
|
+
nestedRepositories: {
|
|
134
|
+
description: "Files of nested Git repositories are link targets. Default: false.",
|
|
135
|
+
type: "boolean",
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
extends: {
|
|
140
|
+
description: "Presets to start from, in order: a preset name or a list of them. Without it, the configuration starts from recommended.",
|
|
141
|
+
anyOf: [{ type: "string" }, strings],
|
|
142
|
+
},
|
|
143
|
+
dialect: { $ref: "#/definitions/dialect" },
|
|
144
|
+
rules: { $ref: "#/definitions/rules" },
|
|
145
|
+
ignore: {
|
|
146
|
+
description: "Path patterns of documents that are never linted or formatted, matched with their letter case. They stay link targets.",
|
|
147
|
+
...strings,
|
|
148
|
+
},
|
|
149
|
+
plugins: {
|
|
150
|
+
description: "Plugins to load: files relative to this file, or package names.",
|
|
151
|
+
...strings,
|
|
81
152
|
},
|
|
82
|
-
extends: { type: "array", items: { type: "string" } },
|
|
83
|
-
dialect,
|
|
84
|
-
rules,
|
|
85
|
-
ignore: { type: "array", items: { type: "string" } },
|
|
86
|
-
plugins: { type: "array", items: { type: "string" } },
|
|
87
153
|
overrides: {
|
|
154
|
+
description: "Settings for the documents that match one of the patterns in files.",
|
|
88
155
|
type: "array",
|
|
89
156
|
items: {
|
|
90
157
|
type: "object",
|
|
91
158
|
required: ["files"],
|
|
92
159
|
additionalProperties: false,
|
|
93
160
|
properties: {
|
|
94
|
-
files: {
|
|
95
|
-
|
|
96
|
-
|
|
161
|
+
files: {
|
|
162
|
+
description: "Path patterns, matched with their letter case against paths relative to the workspace root.",
|
|
163
|
+
...strings,
|
|
164
|
+
minItems: 1,
|
|
165
|
+
},
|
|
166
|
+
dialect: { $ref: "#/definitions/dialect" },
|
|
167
|
+
rules: { $ref: "#/definitions/rules" },
|
|
97
168
|
},
|
|
98
169
|
},
|
|
99
170
|
},
|
|
100
171
|
},
|
|
101
|
-
|
|
172
|
+
definitions: {
|
|
173
|
+
dialect: {
|
|
174
|
+
description: "The renderer whose syntax documents are read in. When nothing names one, github is assumed, or obsidian inside a vault.",
|
|
175
|
+
enum: dialectNames,
|
|
176
|
+
},
|
|
177
|
+
severity: { enum: ["off", "warn", "error"] },
|
|
178
|
+
rules: {
|
|
179
|
+
description: 'Rule IDs and their settings: a severity, or a list of a severity and the rule\'s options, as in ["warn", { "width": 100 }].',
|
|
180
|
+
type: "object",
|
|
181
|
+
additionalProperties: {
|
|
182
|
+
anyOf: [
|
|
183
|
+
{ $ref: "#/definitions/severity" },
|
|
184
|
+
{ type: "array", items: [{ $ref: "#/definitions/severity" }], minItems: 1, maxItems: 1 },
|
|
185
|
+
{
|
|
186
|
+
type: "array",
|
|
187
|
+
items: [{ $ref: "#/definitions/severity" }, { type: "object" }],
|
|
188
|
+
minItems: 2,
|
|
189
|
+
maxItems: 2,
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
});
|
|
102
196
|
const validate = new Ajv({ allErrors: true }).compile(configSchema);
|
|
103
|
-
/** What is wrong with `value` as a configuration, or undefined when it is valid. */
|
|
197
|
+
/** What is wrong with `value` as a configuration, in plain words, or undefined when it is valid. */
|
|
104
198
|
export function configProblem(value) {
|
|
105
|
-
return validate(value) ? undefined :
|
|
199
|
+
return validate(value) ? undefined : configErrors(validate.errors ?? [], value, dialectNames);
|
|
106
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Throws an error that says what is wrong when `value` is not a configuration
|
|
203
|
+
* that `configSchema` describes, naming each setting as it is written, as in
|
|
204
|
+
* `Invalid configuration: "extends[1]" must be a preset name, not 5`. Rule IDs,
|
|
205
|
+
* preset names, and rule options are checked when a document is processed.
|
|
206
|
+
*/
|
|
107
207
|
export function validateConfig(value) {
|
|
108
208
|
const problem = configProblem(value);
|
|
109
209
|
if (problem)
|
|
110
210
|
throw new Error(`Invalid configuration: ${problem}`);
|
|
111
211
|
}
|
|
212
|
+
const noOptions = Object.freeze({});
|
|
112
213
|
export function setting(value) {
|
|
113
214
|
return Array.isArray(value)
|
|
114
|
-
? { severity: value[0], options: value[1] }
|
|
115
|
-
: { severity: value, options:
|
|
215
|
+
? { severity: value[0], options: value[1] ?? noOptions }
|
|
216
|
+
: { severity: value, options: noOptions };
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Set each of `rules` in `target`. A rule named `__proto__` becomes a setting
|
|
220
|
+
* like any other, to be reported as unknown, instead of replacing the
|
|
221
|
+
* object's prototype as an assignment would.
|
|
222
|
+
*/
|
|
223
|
+
function addRules(target, rules = {}) {
|
|
224
|
+
for (const [name, value] of Object.entries(rules))
|
|
225
|
+
Object.defineProperty(target, name, {
|
|
226
|
+
value,
|
|
227
|
+
enumerable: true,
|
|
228
|
+
writable: true,
|
|
229
|
+
configurable: true,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/** Settings that only a configuration has, which show a call in the prereleases' form. */
|
|
233
|
+
const configOnly = new Set(Object.keys(configSchema.properties).filter((key) => key !== "plugins"));
|
|
234
|
+
/**
|
|
235
|
+
* The matchers of override patterns, by pattern. A configuration is resolved
|
|
236
|
+
* for every document, and compiling its patterns each time cost several times
|
|
237
|
+
* as much as matching them.
|
|
238
|
+
*/
|
|
239
|
+
const overridePatterns = new Map();
|
|
240
|
+
function overridePattern(pattern) {
|
|
241
|
+
let matches = overridePatterns.get(pattern);
|
|
242
|
+
if (!matches) {
|
|
243
|
+
// A process that loads many configurations keeps only recent patterns.
|
|
244
|
+
if (overridePatterns.size >= 1000)
|
|
245
|
+
overridePatterns.clear();
|
|
246
|
+
const matcher = new Minimatch(pattern, { dot: true });
|
|
247
|
+
matches = (file) => matcher.match(file);
|
|
248
|
+
overridePatterns.set(pattern, matches);
|
|
249
|
+
}
|
|
250
|
+
return matches;
|
|
116
251
|
}
|
|
117
252
|
/**
|
|
118
|
-
* The configuration in effect for
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
253
|
+
* The configuration in effect for one document: its dialect, rule settings,
|
|
254
|
+
* `ignore` patterns, and `resolve` settings. It takes the `path`, `config`,
|
|
255
|
+
* `plugins`, and `defaultDialect` that `lint` and `format` take, so their
|
|
256
|
+
* options serve as they are. `defaultDialect` is the dialect to assume when
|
|
257
|
+
* neither the configuration, a preset, nor a matching override names one:
|
|
258
|
+
* `github` unless the caller knows better, as the CLI does inside an Obsidian
|
|
259
|
+
* vault. An invalid configuration or default dialect, an unknown preset, and a
|
|
260
|
+
* cycle of presets throw an error.
|
|
122
261
|
*/
|
|
123
|
-
export function resolveConfig(
|
|
262
|
+
export function resolveConfig(options = {}) {
|
|
263
|
+
// The prereleases took the configuration, path, plugins, and default dialect one by one.
|
|
264
|
+
if (arguments.length > 1 ||
|
|
265
|
+
typeof options !== "object" ||
|
|
266
|
+
options === null ||
|
|
267
|
+
Object.keys(options).some((key) => configOnly.has(key)))
|
|
268
|
+
throw new TypeError("resolveConfig takes one options object, { path, config, plugins, defaultDialect }, since mdrefine 0.2.0.");
|
|
269
|
+
const { config = {}, path = "document.md", plugins = [] } = options;
|
|
124
270
|
validateConfig(config);
|
|
125
|
-
|
|
126
|
-
throw new Error(`Unknown default dialect: ${String(defaultDialect)}`);
|
|
271
|
+
const assumed = knownDialect(options.defaultDialect ?? fallbackDialect, "default dialect");
|
|
127
272
|
const available = { ...presets };
|
|
128
273
|
for (const plugin of plugins)
|
|
129
274
|
for (const [name, preset] of Object.entries(plugin.presets ?? {}))
|
|
130
275
|
available[`${plugin.name}/${name}`] = preset;
|
|
131
|
-
const result = {
|
|
132
|
-
dialect: canonicalDialect(defaultDialect),
|
|
133
|
-
rules: {},
|
|
134
|
-
ignore: [],
|
|
135
|
-
resolve: {},
|
|
136
|
-
};
|
|
276
|
+
const result = { dialect: assumed, rules: {}, ignore: [], resolve: {} };
|
|
137
277
|
const overrides = [];
|
|
138
278
|
function merge(part, chain) {
|
|
139
279
|
validateConfig(part);
|
|
140
|
-
for (const name of part.extends ?? []) {
|
|
280
|
+
for (const name of typeof part.extends === "string" ? [part.extends] : (part.extends ?? [])) {
|
|
141
281
|
if (chain.includes(name))
|
|
142
282
|
throw new Error(`Circular preset: ${[...chain, name].join(" -> ")}`);
|
|
143
|
-
|
|
144
|
-
if (!
|
|
283
|
+
// Names such as `toString` are found on every object; only defined presets count.
|
|
284
|
+
if (!Object.hasOwn(available, name))
|
|
145
285
|
throw new Error(`Unknown preset: ${name}`);
|
|
146
|
-
merge(
|
|
286
|
+
merge(available[name], [...chain, name]);
|
|
147
287
|
}
|
|
148
288
|
if (part.dialect)
|
|
149
289
|
result.dialect = canonicalDialect(part.dialect);
|
|
150
|
-
|
|
290
|
+
addRules(result.rules, part.rules);
|
|
151
291
|
Object.assign(result.resolve, part.resolve);
|
|
152
292
|
result.ignore.push(...(part.ignore ?? []));
|
|
153
293
|
overrides.push(...(part.overrides ?? []));
|
|
@@ -155,11 +295,12 @@ export function resolveConfig(config = {}, path = "document.md", plugins = [], d
|
|
|
155
295
|
if (config.extends === undefined)
|
|
156
296
|
merge(presets.recommended, []);
|
|
157
297
|
merge(config, []);
|
|
298
|
+
const document = path.replaceAll("\\", "/");
|
|
158
299
|
for (const override of overrides) {
|
|
159
|
-
if (override.files.some((pattern) =>
|
|
300
|
+
if (override.files.some((pattern) => overridePattern(pattern)(document))) {
|
|
160
301
|
if (override.dialect)
|
|
161
302
|
result.dialect = canonicalDialect(override.dialect);
|
|
162
|
-
|
|
303
|
+
addRules(result.rules, override.rules);
|
|
163
304
|
}
|
|
164
305
|
}
|
|
165
306
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/config/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAUtC,qFAAqF;AACrF,MAAM,CAAC,MAAM,cAAc,GAA4B,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;AAC/E,MAAM,CAAC,MAAM,QAAQ,GAAc,CAAC,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;AAC5F;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAY,QAAQ,CAAC;AACjD,MAAM,UAAU,gBAAgB,CAAC,IAAiB;IAChD,OAAO,cAAc,CAAC,IAAI,CAAC,IAAK,IAAgB,CAAC;AACnD,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAA2B;IAC7C,WAAW,EAAE;QACX,KAAK,EAAE;YACL,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;YACrC,gBAAgB,EAAE,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YAC3C,cAAc,EAAE,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YACzC,qBAAqB,EAAE,MAAM;YAC7B,aAAa,EAAE,OAAO;SACvB;KACF;IACD,MAAM,EAAE;QACN,OAAO,EAAE,QAAQ;QACjB,KAAK,EAAE,EAAE,oBAAoB,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,EAAE,a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IAClE,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAClB,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,IACE,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAC9B,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAC9D,EACD,CAAC;YACD,IAAI,QAAQ,CAAC,OAAO;gBAAE,MAAM,CAAC,OAAO,GAAG,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC1E,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Ajv } from \"ajv\";\nimport { minimatch } from \"minimatch\";\nimport type {\n Config,\n Dialect,\n DialectName,\n Plugin,\n ResolvedConfig,\n RuleSetting,\n} from \"../core/types.js\";\n\n/** Alias names that select an existing dialect; Codeberg runs Forgejo's renderer. */\nexport const dialectAliases: Record<string, Dialect> = { codeberg: \"forgejo\" };\nexport const dialects: Dialect[] = [\"commonmark\", \"github\", \"forgejo\", \"gitea\", \"obsidian\"];\n/**\n * The dialect assumed when nothing names one and the caller knows no better.\n * GitHub's syntax is the common base of the Forgejo, Gitea, and Obsidian\n * dialects, so a table or a footnote written for any of them is not read as an\n * ordinary paragraph and reflowed.\n */\nexport const fallbackDialect: Dialect = \"github\";\nexport function canonicalDialect(name: DialectName): Dialect {\n return dialectAliases[name] ?? (name as Dialect);\n}\n\nexport const presets: Record<string, Config> = {\n recommended: {\n rules: {\n \"style/wrap\": [\"warn\", { width: 80 }],\n \"style/emphasis\": [\"warn\", { marker: \"_\" }],\n \"style/strong\": [\"warn\", { marker: \"*\" }],\n \"style/final-newline\": \"warn\",\n \"links/valid\": \"error\",\n },\n },\n github: {\n dialect: \"github\",\n rules: { \"github/task-marker\": \"warn\", \"github/alert-marker\": \"warn\", \"style/table\": \"warn\" },\n },\n forgejo: {\n dialect: \"forgejo\",\n rules: {\n \"github/task-marker\": \"warn\",\n \"github/alert-marker\": \"warn\",\n \"style/table\": \"warn\",\n \"forgejo/heading-id\": \"error\",\n },\n },\n codeberg: { extends: [\"forgejo\"] },\n gitea: {\n dialect: \"gitea\",\n rules: {\n \"github/task-marker\": \"warn\",\n \"github/alert-marker\": \"warn\",\n \"style/table\": \"warn\",\n \"forgejo/heading-id\": \"error\",\n },\n },\n obsidian: {\n dialect: \"obsidian\",\n rules: {\n \"obsidian/callout-marker\": \"warn\",\n \"obsidian/block-reference\": \"error\",\n \"obsidian/strict-line-breaks\": \"warn\",\n \"github/task-marker\": \"warn\",\n \"style/table\": \"warn\",\n },\n },\n};\nconst severity = { enum: [\"off\", \"warn\", \"error\"] };\nconst dialect = { enum: [...dialects, ...Object.keys(dialectAliases)] };\nconst rules = {\n type: \"object\",\n additionalProperties: {\n anyOf: [\n severity,\n { type: \"array\", items: [severity, { type: \"object\" }], minItems: 2, maxItems: 2 },\n ],\n },\n};\nexport const configSchema = {\n $schema: \"http://json-schema.org/draft-07/schema#\",\n type: \"object\",\n additionalProperties: false,\n properties: {\n $schema: { type: \"string\" },\n resolve: {\n type: \"object\",\n additionalProperties: false,\n properties: { gitIgnored: { type: \"boolean\" }, nestedRepositories: { type: \"boolean\" } },\n },\n extends: { type: \"array\", items: { type: \"string\" } },\n dialect,\n rules,\n ignore: { type: \"array\", items: { type: \"string\" } },\n plugins: { type: \"array\", items: { type: \"string\" } },\n overrides: {\n type: \"array\",\n items: {\n type: \"object\",\n required: [\"files\"],\n additionalProperties: false,\n properties: {\n files: { type: \"array\", items: { type: \"string\" }, minItems: 1 },\n dialect,\n rules,\n },\n },\n },\n },\n};\nconst validate = new Ajv({ allErrors: true }).compile(configSchema);\n/** What is wrong with `value` as a configuration, or undefined when it is valid. */\nexport function configProblem(value: unknown): string | undefined {\n return validate(value) ? undefined : new Ajv().errorsText(validate.errors);\n}\nexport function validateConfig(value: unknown): asserts value is Config {\n const problem = configProblem(value);\n if (problem) throw new Error(`Invalid configuration: ${problem}`);\n}\nexport function setting(value: RuleSetting): {\n severity: \"off\" | \"warn\" | \"error\";\n options: Record<string, unknown>;\n} {\n return Array.isArray(value)\n ? { severity: value[0], options: value[1] }\n : { severity: value, options: {} };\n}\n/**\n * The configuration in effect for the document at `path`. `defaultDialect` is\n * the dialect to assume when neither the configuration, a preset, nor a\n * matching override names one: `github` unless the caller knows better, as the\n * CLI does at the root of an Obsidian vault.\n */\nexport function resolveConfig(\n config: Config = {},\n path = \"document.md\",\n plugins: Plugin[] = [],\n defaultDialect: DialectName = fallbackDialect,\n): ResolvedConfig {\n validateConfig(config);\n if (!dialects.includes(canonicalDialect(defaultDialect)))\n throw new Error(`Unknown default dialect: ${String(defaultDialect)}`);\n const available = { ...presets };\n for (const plugin of plugins)\n for (const [name, preset] of Object.entries(plugin.presets ?? {}))\n available[`${plugin.name}/${name}`] = preset;\n const result: ResolvedConfig = {\n dialect: canonicalDialect(defaultDialect),\n rules: {},\n ignore: [],\n resolve: {},\n };\n const overrides: NonNullable<Config[\"overrides\"]> = [];\n function merge(part: Config, chain: string[]) {\n validateConfig(part);\n for (const name of part.extends ?? []) {\n if (chain.includes(name))\n throw new Error(`Circular preset: ${[...chain, name].join(\" -> \")}`);\n const preset = available[name];\n if (!preset) throw new Error(`Unknown preset: ${name}`);\n merge(preset, [...chain, name]);\n }\n if (part.dialect) result.dialect = canonicalDialect(part.dialect);\n Object.assign(result.rules, part.rules);\n Object.assign(result.resolve, part.resolve);\n result.ignore.push(...(part.ignore ?? []));\n overrides.push(...(part.overrides ?? []));\n }\n if (config.extends === undefined) merge(presets.recommended!, []);\n merge(config, []);\n for (const override of overrides) {\n if (\n override.files.some((pattern) =>\n minimatch(path.replaceAll(\"\\\\\", \"/\"), pattern, { dot: true }),\n )\n ) {\n if (override.dialect) result.dialect = canonicalDialect(override.dialect);\n Object.assign(result.rules, override.rules);\n }\n }\n return result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/config/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAW/C;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;AACzC,mFAAmF;AACnF,MAAM,CAAC,MAAM,QAAQ,GAAuB,MAAM,CAAC,MAAM,CAAC;IACxD,YAAY;IACZ,QAAQ;IACR,SAAS;IACT,OAAO;IACP,UAAU;CACX,CAAC,CAAC;AACH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAY,QAAQ,CAAC;AACjD;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAiB;IAChD,OAAO,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC;QACxC,CAAC,CAAC,cAAc,CAAC,IAAmC,CAAC;QACrD,CAAC,CAAE,IAAgB,CAAC;AACxB,CAAC;AACD,gFAAgF;AAChF,MAAM,UAAU,YAAY,CAAC,IAAiB,EAAE,IAAI,GAAG,SAAS;IAC9D,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAG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AAC,CAAC;IAC5C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YACzE,IAAI,QAAQ,CAAC,OAAO;gBAAE,MAAM,CAAC,OAAO,GAAG,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC1E,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Ajv } from \"ajv\";\nimport { Minimatch } from \"minimatch\";\nimport { configErrors } from \"./problems.js\";\nimport { deepFreeze } from \"../core/frozen.js\";\nimport type {\n Config,\n Dialect,\n DialectName,\n JsonSchemaObject,\n ResolveConfigOptions,\n ResolvedConfig,\n RuleSetting,\n} from \"../core/types.js\";\n\n/**\n * Alias names that select an existing dialect, mapped to that dialect:\n * Codeberg runs Forgejo's renderer. The table is frozen.\n */\nexport const dialectAliases: Readonly<Record<Exclude<DialectName, Dialect>, Dialect>> =\n Object.freeze({ codeberg: \"forgejo\" });\n/** The dialects, in the order the documentation lists them. The list is frozen. */\nexport const dialects: readonly Dialect[] = Object.freeze([\n \"commonmark\",\n \"github\",\n \"forgejo\",\n \"gitea\",\n \"obsidian\",\n]);\n/**\n * The dialect assumed when nothing names one and the caller knows no better.\n * GitHub's syntax is the common base of the Forgejo, Gitea, and Obsidian\n * dialects, so a table or a footnote written for any of them is not read as an\n * ordinary paragraph and reflowed.\n */\nexport const fallbackDialect: Dialect = \"github\";\n/**\n * The dialect that `name` stands for: an alias's dialect, or `name` itself.\n * A name that is neither is returned as it is.\n */\nexport function canonicalDialect(name: DialectName): Dialect {\n return Object.hasOwn(dialectAliases, name)\n ? dialectAliases[name as keyof typeof dialectAliases]\n : (name as Dialect);\n}\n/** The dialect that `name` stands for, or an error that says what was named. */\nexport function knownDialect(name: DialectName, what = \"dialect\"): Dialect {\n const dialect = canonicalDialect(name);\n if (!dialects.includes(dialect)) throw new Error(`Unknown ${what}: ${String(name)}`);\n return dialect;\n}\n\n/**\n * The built-in presets by name. The table and everything in it are frozen, so\n * that no caller can change what another one gets.\n */\nexport const presets: Readonly<Record<string, Readonly<Config>>> = {\n recommended: {\n rules: {\n \"style/wrap\": [\"warn\", { width: 80 }],\n \"style/emphasis\": [\"warn\", { marker: \"_\" }],\n \"style/strong\": [\"warn\", { marker: \"*\" }],\n \"style/heading\": \"warn\",\n \"style/table\": \"warn\",\n \"style/code-fence\": \"warn\",\n \"style/thematic-break\": \"warn\",\n \"style/blank-lines\": \"warn\",\n \"style/trailing-space\": \"warn\",\n \"style/final-newline\": \"warn\",\n \"style/list-marker\": [\"warn\", { marker: \"-\" }],\n \"style/ordered-list\": [\"warn\", { delimiter: \".\", numbering: \"auto\" }],\n \"style/list-indent\": \"warn\",\n \"links/valid\": \"error\",\n \"links/undefined-reference\": \"warn\",\n \"links/unused-definition\": \"warn\",\n \"links/empty\": \"warn\",\n \"structure/heading-increment\": \"warn\",\n \"content/image-alt\": \"warn\",\n \"content/table-columns\": \"warn\",\n },\n },\n github: {\n dialect: \"github\",\n rules: { \"github/task-marker\": \"warn\", \"github/alert-marker\": \"warn\", \"style/table\": \"warn\" },\n },\n forgejo: {\n dialect: \"forgejo\",\n rules: {\n \"github/task-marker\": \"warn\",\n \"github/alert-marker\": \"warn\",\n \"style/table\": \"warn\",\n \"forgejo/heading-id\": \"error\",\n },\n },\n codeberg: { extends: [\"forgejo\"] },\n gitea: {\n dialect: \"gitea\",\n rules: {\n \"github/task-marker\": \"warn\",\n \"github/alert-marker\": \"warn\",\n \"style/table\": \"warn\",\n \"forgejo/heading-id\": \"error\",\n },\n },\n obsidian: {\n dialect: \"obsidian\",\n rules: {\n \"obsidian/callout-marker\": \"warn\",\n \"obsidian/block-reference\": \"error\",\n \"obsidian/strict-line-breaks\": \"warn\",\n \"github/task-marker\": \"warn\",\n \"style/table\": \"warn\",\n },\n },\n};\ndeepFreeze(presets);\n// Each dialect is followed by its aliases, as the command line lists them.\nconst dialectNames = dialects.flatMap((dialect) => [\n dialect,\n ...Object.entries(dialectAliases).flatMap(([alias, of]) => (of === dialect ? [alias] : [])),\n]);\nconst strings = { type: \"array\", items: { type: \"string\" } };\n/**\n * The configuration's JSON Schema, which `validateConfig` enforces. The\n * package ships it as `config.schema.json`, which a test keeps equal to it,\n * and the documentation site serves it for editors.\n */\nexport const configSchema: JsonSchemaObject = deepFreeze({\n $schema: \"http://json-schema.org/draft-07/schema#\",\n title: \"mdtools configuration\",\n description:\n \"Configuration of the mdtools command of mdrefine: https://viell-dev.github.io/slop-markdown-tools/configuration.html\",\n type: \"object\",\n additionalProperties: false,\n properties: {\n $schema: { description: \"The JSON Schema for editors; the tool ignores it.\", type: \"string\" },\n resolve: {\n description: \"Files that links may lead to, which are never linted or formatted.\",\n type: \"object\",\n additionalProperties: false,\n properties: {\n gitIgnored: {\n description: \"Files that .gitignore files exclude are link targets. Default: false.\",\n type: \"boolean\",\n },\n nestedRepositories: {\n description: \"Files of nested Git repositories are link targets. Default: false.\",\n type: \"boolean\",\n },\n },\n },\n extends: {\n description:\n \"Presets to start from, in order: a preset name or a list of them. Without it, the configuration starts from recommended.\",\n anyOf: [{ type: \"string\" }, strings],\n },\n dialect: { $ref: \"#/definitions/dialect\" },\n rules: { $ref: \"#/definitions/rules\" },\n ignore: {\n description:\n \"Path patterns of documents that are never linted or formatted, matched with their letter case. They stay link targets.\",\n ...strings,\n },\n plugins: {\n description: \"Plugins to load: files relative to this file, or package names.\",\n ...strings,\n },\n overrides: {\n description: \"Settings for the documents that match one of the patterns in files.\",\n type: \"array\",\n items: {\n type: \"object\",\n required: [\"files\"],\n additionalProperties: false,\n properties: {\n files: {\n description:\n \"Path patterns, matched with their letter case against paths relative to the workspace root.\",\n ...strings,\n minItems: 1,\n },\n dialect: { $ref: \"#/definitions/dialect\" },\n rules: { $ref: \"#/definitions/rules\" },\n },\n },\n },\n },\n definitions: {\n dialect: {\n description:\n \"The renderer whose syntax documents are read in. When nothing names one, github is assumed, or obsidian inside a vault.\",\n enum: dialectNames,\n },\n severity: { enum: [\"off\", \"warn\", \"error\"] },\n rules: {\n description:\n 'Rule IDs and their settings: a severity, or a list of a severity and the rule\\'s options, as in [\"warn\", { \"width\": 100 }].',\n type: \"object\",\n additionalProperties: {\n anyOf: [\n { $ref: \"#/definitions/severity\" },\n { type: \"array\", items: [{ $ref: \"#/definitions/severity\" }], minItems: 1, maxItems: 1 },\n {\n type: \"array\",\n items: [{ $ref: \"#/definitions/severity\" }, { type: \"object\" }],\n minItems: 2,\n maxItems: 2,\n },\n ],\n },\n },\n },\n});\nconst validate = new Ajv({ allErrors: true }).compile(configSchema);\n/** What is wrong with `value` as a configuration, in plain words, or undefined when it is valid. */\nexport function configProblem(value: unknown): string | undefined {\n return validate(value) ? undefined : configErrors(validate.errors ?? [], value, dialectNames);\n}\n/**\n * Throws an error that says what is wrong when `value` is not a configuration\n * that `configSchema` describes, naming each setting as it is written, as in\n * `Invalid configuration: \"extends[1]\" must be a preset name, not 5`. Rule IDs,\n * preset names, and rule options are checked when a document is processed.\n */\nexport function validateConfig(value: unknown): asserts value is Config {\n const problem = configProblem(value);\n if (problem) throw new Error(`Invalid configuration: ${problem}`);\n}\nconst noOptions: Readonly<Record<string, unknown>> = Object.freeze({});\nexport function setting(value: RuleSetting): {\n severity: \"off\" | \"warn\" | \"error\";\n options: Readonly<Record<string, unknown>>;\n} {\n return Array.isArray(value)\n ? { severity: value[0], options: value[1] ?? noOptions }\n : { severity: value as Exclude<RuleSetting, readonly unknown[]>, options: noOptions };\n}\n/**\n * Set each of `rules` in `target`. A rule named `__proto__` becomes a setting\n * like any other, to be reported as unknown, instead of replacing the\n * object's prototype as an assignment would.\n */\nfunction addRules(target: Record<string, RuleSetting>, rules: Config[\"rules\"] = {}) {\n for (const [name, value] of Object.entries(rules))\n Object.defineProperty(target, name, {\n value,\n enumerable: true,\n writable: true,\n configurable: true,\n });\n}\n/** Settings that only a configuration has, which show a call in the prereleases' form. */\nconst configOnly = new Set(\n Object.keys(configSchema.properties as object).filter((key) => key !== \"plugins\"),\n);\n/**\n * The matchers of override patterns, by pattern. A configuration is resolved\n * for every document, and compiling its patterns each time cost several times\n * as much as matching them.\n */\nconst overridePatterns = new Map<string, (file: string) => boolean>();\nfunction overridePattern(pattern: string): (file: string) => boolean {\n let matches = overridePatterns.get(pattern);\n if (!matches) {\n // A process that loads many configurations keeps only recent patterns.\n if (overridePatterns.size >= 1000) overridePatterns.clear();\n const matcher = new Minimatch(pattern, { dot: true });\n matches = (file) => matcher.match(file);\n overridePatterns.set(pattern, matches);\n }\n return matches;\n}\n/**\n * The configuration in effect for one document: its dialect, rule settings,\n * `ignore` patterns, and `resolve` settings. It takes the `path`, `config`,\n * `plugins`, and `defaultDialect` that `lint` and `format` take, so their\n * options serve as they are. `defaultDialect` is the dialect to assume when\n * neither the configuration, a preset, nor a matching override names one:\n * `github` unless the caller knows better, as the CLI does inside an Obsidian\n * vault. An invalid configuration or default dialect, an unknown preset, and a\n * cycle of presets throw an error.\n */\nexport function resolveConfig(options: ResolveConfigOptions = {}): ResolvedConfig {\n // The prereleases took the configuration, path, plugins, and default dialect one by one.\n if (\n arguments.length > 1 ||\n typeof options !== \"object\" ||\n options === null ||\n Object.keys(options).some((key) => configOnly.has(key))\n )\n throw new TypeError(\n \"resolveConfig takes one options object, { path, config, plugins, defaultDialect }, since mdrefine 0.2.0.\",\n );\n const { config = {}, path = \"document.md\", plugins = [] } = options;\n validateConfig(config);\n const assumed = knownDialect(options.defaultDialect ?? fallbackDialect, \"default dialect\");\n const available: Record<string, Readonly<Config>> = { ...presets };\n for (const plugin of plugins)\n for (const [name, preset] of Object.entries(plugin.presets ?? {}))\n available[`${plugin.name}/${name}`] = preset;\n const result: ResolvedConfig = { dialect: assumed, rules: {}, ignore: [], resolve: {} };\n const overrides: NonNullable<Config[\"overrides\"]>[number][] = [];\n function merge(part: Readonly<Config>, chain: readonly string[]) {\n validateConfig(part);\n for (const name of typeof part.extends === \"string\" ? [part.extends] : (part.extends ?? [])) {\n if (chain.includes(name))\n throw new Error(`Circular preset: ${[...chain, name].join(\" -> \")}`);\n // Names such as `toString` are found on every object; only defined presets count.\n if (!Object.hasOwn(available, name)) throw new Error(`Unknown preset: ${name}`);\n merge(available[name]!, [...chain, name]);\n }\n if (part.dialect) result.dialect = canonicalDialect(part.dialect);\n addRules(result.rules, part.rules);\n Object.assign(result.resolve, part.resolve);\n result.ignore.push(...(part.ignore ?? []));\n overrides.push(...(part.overrides ?? []));\n }\n if (config.extends === undefined) merge(presets.recommended!, []);\n merge(config, []);\n const document = path.replaceAll(\"\\\\\", \"/\");\n for (const override of overrides) {\n if (override.files.some((pattern) => overridePattern(pattern)(document))) {\n if (override.dialect) result.dialect = canonicalDialect(override.dialect);\n addRules(result.rules, override.rules);\n }\n }\n return result;\n}\n"]}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { Document, Finding } from "./types.js";
|
|
2
|
+
/** A suppression directive and the rules it names, `*` for all of them. */
|
|
3
|
+
export interface Directive {
|
|
4
|
+
kind: "disable-next-line" | "disable" | "enable";
|
|
5
|
+
rules: Set<string>;
|
|
6
|
+
}
|
|
7
|
+
/** The directive that an HTML node's value holds, if it is one. */
|
|
8
|
+
export declare function directive(value: string): Directive | undefined;
|
|
2
9
|
/** Directives are recognized only in parsed HTML comments, never in code examples. */
|
|
3
10
|
export declare function suppressions(document: Document): (rule: string, finding: Finding) => boolean;
|