madr-lint 0.4.2 → 0.5.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 +12 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +49 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.js +49 -1
- package/dist/index.js.map +1 -1
- package/package.json +14 -13
package/dist/index.d.ts
CHANGED
|
@@ -426,7 +426,7 @@ interface MetadataPosition {
|
|
|
426
426
|
column: number;
|
|
427
427
|
}
|
|
428
428
|
interface ParsedFile {
|
|
429
|
-
/** Parsed
|
|
429
|
+
/** Parsed frontmatter (v3/v4), or null if absent. */
|
|
430
430
|
frontmatter: Record<string, unknown> | null;
|
|
431
431
|
/**
|
|
432
432
|
* v2 body-list metadata extracted from the leading metadata block, or null if
|
|
@@ -555,7 +555,16 @@ interface SupersedesBidirectionalOptions extends Record<string, unknown> {
|
|
|
555
555
|
declare const rule: ProjectRule<SupersedesBidirectionalOptions>;
|
|
556
556
|
|
|
557
557
|
declare namespace index {
|
|
558
|
-
export {
|
|
558
|
+
export {
|
|
559
|
+
rule$7 as dateIso8601,
|
|
560
|
+
rule$6 as filenameFormat,
|
|
561
|
+
rule$5 as noBrokenLinks,
|
|
562
|
+
rule$4 as noDuplicateNumbering,
|
|
563
|
+
rule$3 as noNumberingGap,
|
|
564
|
+
rule$2 as requiredSections,
|
|
565
|
+
rule$1 as statusEnum,
|
|
566
|
+
rule as supersedesBidirectional,
|
|
567
|
+
};
|
|
559
568
|
}
|
|
560
569
|
|
|
561
570
|
declare const recommended: Record<string, RuleSeverity>;
|
|
@@ -651,4 +660,5 @@ interface MadrLintConfig {
|
|
|
651
660
|
*/
|
|
652
661
|
declare function defineConfig(config: MadrLintConfig): MadrLintConfig;
|
|
653
662
|
|
|
654
|
-
export {
|
|
663
|
+
export { BASELINE_VERSION, INTERNAL_ERROR_RULE_NAME, MAX_FIX_PASSES, RuleOptionsError, applyBaseline, applyEdits, applyEditsCounted, baselinePath, buildBaseline, buildProjectFile, collectFixes, collectProjectFixes, defineConfig, extractListMetadata, fixFileContent, frontmatterOffset, isProjectRule, loadBaseline, makeFixer, parseFile, recommended, index as rules, runRule, runRulesOnFile, runRulesOnProject, serializeBaseline, unifiedDiff, writeBaseline };
|
|
664
|
+
export type { AnyRule, Baseline, BaselineApplyResult, Diagnostic, FileContext, FixFileResult, FixFn, Fixer, MadrLintConfig, MadrVersion, MdastNode, MdastNodeType, ParsedFile, ProjectFile, ProjectRule, ProjectRuleContext, Rule, RuleContext, RuleListeners, RuleMeta, RuleSeverity, RunRuleOptions, Severity, TextEdit };
|
package/dist/index.js
CHANGED
|
@@ -9,13 +9,60 @@ import { fromMarkdown } from "mdast-util-from-markdown";
|
|
|
9
9
|
import { toString } from "mdast-util-to-string";
|
|
10
10
|
import grayMatter from "gray-matter";
|
|
11
11
|
|
|
12
|
+
// src/core/js-frontmatter.ts
|
|
13
|
+
import { createRequire } from "module";
|
|
14
|
+
var MAX_DEPTH = 64;
|
|
15
|
+
var json5;
|
|
16
|
+
function loadJson5() {
|
|
17
|
+
json5 ??= createRequire(import.meta.url)("json5");
|
|
18
|
+
return json5;
|
|
19
|
+
}
|
|
20
|
+
function invalid(reason) {
|
|
21
|
+
return new Error(
|
|
22
|
+
`Invalid JavaScript frontmatter (---js): ${reason}. Only a static object literal is allowed (strings, numbers, booleans, null, arrays, objects). Use YAML frontmatter for anything else.`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
function parseStaticJsFrontmatter(block) {
|
|
26
|
+
let root;
|
|
27
|
+
try {
|
|
28
|
+
root = loadJson5().parse(block);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw invalid(error instanceof Error ? error.message : "parse failed");
|
|
31
|
+
}
|
|
32
|
+
if (root === null || typeof root !== "object" || Array.isArray(root)) {
|
|
33
|
+
throw invalid("the top level must be an object");
|
|
34
|
+
}
|
|
35
|
+
const pending = [
|
|
36
|
+
{ value: root, depth: 1 }
|
|
37
|
+
];
|
|
38
|
+
for (let next = pending.pop(); next; next = pending.pop()) {
|
|
39
|
+
const { value, depth } = next;
|
|
40
|
+
if (typeof value === "number" && !Number.isFinite(value)) {
|
|
41
|
+
throw invalid("Infinity and NaN are not allowed");
|
|
42
|
+
}
|
|
43
|
+
if (value === null || typeof value !== "object") continue;
|
|
44
|
+
if (depth > MAX_DEPTH) {
|
|
45
|
+
throw invalid(`nesting is limited to ${MAX_DEPTH} levels`);
|
|
46
|
+
}
|
|
47
|
+
for (const [key, child] of Object.entries(value)) {
|
|
48
|
+
if (key === "__proto__") throw invalid("the __proto__ key is not allowed");
|
|
49
|
+
pending.push({ value: child, depth: depth + 1 });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return root;
|
|
53
|
+
}
|
|
54
|
+
|
|
12
55
|
// src/core/null-proto-map.ts
|
|
13
56
|
function nullProtoMap() {
|
|
14
57
|
return /* @__PURE__ */ Object.create(null);
|
|
15
58
|
}
|
|
16
59
|
|
|
17
60
|
// src/core/parser.ts
|
|
18
|
-
var GRAY_MATTER_OPTIONS = Object.freeze({
|
|
61
|
+
var GRAY_MATTER_OPTIONS = Object.freeze({
|
|
62
|
+
engines: {
|
|
63
|
+
javascript: parseStaticJsFrontmatter
|
|
64
|
+
}
|
|
65
|
+
});
|
|
19
66
|
function frontmatterOffset(content) {
|
|
20
67
|
return content.length - grayMatter(content, GRAY_MATTER_OPTIONS).content.length;
|
|
21
68
|
}
|
|
@@ -1443,6 +1490,7 @@ function frontmatterInsertEdit(content, key, value) {
|
|
|
1443
1490
|
const fmEnd = frontmatterOffset(content);
|
|
1444
1491
|
if (fmEnd === 0) return null;
|
|
1445
1492
|
const fmBlock = content.slice(0, fmEnd);
|
|
1493
|
+
if (!/^\uFEFF?---[ \t]*\r?\n/.test(fmBlock)) return null;
|
|
1446
1494
|
const closeMatch = /\r?\n(---[ \t]*\r?\n)$/.exec(fmBlock);
|
|
1447
1495
|
if (!closeMatch) return null;
|
|
1448
1496
|
const fenceLine = closeMatch[1];
|