madr-lint 0.4.1 → 0.4.2

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/dist/index.d.ts CHANGED
@@ -488,11 +488,13 @@ declare function parseFile(content: string): ParsedFile;
488
488
  * heading, or any other block before the first list, means there is no
489
489
  * metadata block. The block itself is the leading RUN of lists, joined across
490
490
  * HTML comments — a comment ends the CommonMark list yet renders as nothing,
491
- * so a field below it is still metadata (#73). Only comments bridge; once the
492
- * run has started, visible HTML, a paragraph, a code fence, a thematic break,
493
- * a blockquote, and a heading of ANY depth all end the block, as does a second
494
- * list with no comment before it. Each `listItem` is read as one `Key: value`
495
- * pair in either of two shapes:
491
+ * so a field below it is still metadata (#73). A second list with nothing
492
+ * between it and the first (a bullet-marker change, or an ordered list) joins
493
+ * the run when EVERY one of its items reads as a `Key: value` pair (#115); a
494
+ * list carrying any other item is prose and ends the block. Once the run has
495
+ * started, visible HTML, a paragraph, a code fence, a thematic break, a
496
+ * blockquote, and a heading of ANY depth all end the block. Each `listItem` is
497
+ * read as one `Key: value` pair in either of two shapes:
496
498
  *
497
499
  * - Bold key: `- **Status**: accepted` (some MADR v2 authors)
498
500
  * - Plain key: `* Status: accepted` (official MADR v2.1.2 template)
package/dist/index.js CHANGED
@@ -8,11 +8,19 @@ var __export = (target, all) => {
8
8
  import { fromMarkdown } from "mdast-util-from-markdown";
9
9
  import { toString } from "mdast-util-to-string";
10
10
  import grayMatter from "gray-matter";
11
+
12
+ // src/core/null-proto-map.ts
13
+ function nullProtoMap() {
14
+ return /* @__PURE__ */ Object.create(null);
15
+ }
16
+
17
+ // src/core/parser.ts
18
+ var GRAY_MATTER_OPTIONS = Object.freeze({});
11
19
  function frontmatterOffset(content) {
12
- return content.length - grayMatter(content).content.length;
20
+ return content.length - grayMatter(content, GRAY_MATTER_OPTIONS).content.length;
13
21
  }
14
22
  function parseFile(content) {
15
- const matter = grayMatter(content);
23
+ const matter = grayMatter(content, GRAY_MATTER_OPTIONS);
16
24
  const data = matter.data;
17
25
  const frontmatter = Object.keys(data).length > 0 ? data : null;
18
26
  const ast = fromMarkdown(matter.content);
@@ -22,7 +30,7 @@ function parseFile(content) {
22
30
  let metadataLoc = listResult && Object.keys(listResult.loc).length > 0 ? { ...listResult.loc } : null;
23
31
  let metadataValueLoc = listResult && Object.keys(listResult.valueOffsets).length > 0 ? { ...listResult.valueOffsets } : null;
24
32
  if (frontmatter && listMetadata) {
25
- const frontmatterDefined = {};
33
+ const frontmatterDefined = nullProtoMap();
26
34
  for (const [k, v] of Object.entries(frontmatter)) {
27
35
  if (v !== null && v !== void 0) frontmatterDefined[k] = v;
28
36
  }
@@ -92,7 +100,7 @@ function extractListMetadataWithLoc(ast, body) {
92
100
  bridged = true;
93
101
  continue;
94
102
  }
95
- if (child.type === "list" && bridged) {
103
+ if (child.type === "list" && (bridged || child.children.length > 0 && child.children.every((item) => extractListItemKV(item)))) {
96
104
  segments.push(child);
97
105
  bridged = false;
98
106
  continue;
@@ -100,13 +108,13 @@ function extractListMetadataWithLoc(ast, body) {
100
108
  break;
101
109
  }
102
110
  if (segments.length === 0) return null;
103
- const values = {};
104
- const loc = {};
105
- const valueOffsets = {};
111
+ const values = nullProtoMap();
112
+ const loc = nullProtoMap();
113
+ const valueOffsets = nullProtoMap();
106
114
  for (const list of segments) {
107
115
  for (const item of list.children) {
108
116
  const pair = extractListItemKV(item);
109
- if (pair && !(pair.key in values)) {
117
+ if (pair && !Object.hasOwn(values, pair.key)) {
110
118
  values[pair.key] = pair.value;
111
119
  const start = item.position?.start;
112
120
  if (start) loc[pair.key] = { line: start.line, column: start.column };
@@ -119,7 +127,7 @@ function extractListMetadataWithLoc(ast, body) {
119
127
  const hasRecognizedKey = Object.keys(values).some(
120
128
  (k) => RECOGNIZED_METADATA_KEYS.has(k)
121
129
  );
122
- return hasRecognizedKey ? { values, loc, valueOffsets } : null;
130
+ return hasRecognizedKey ? { values: { ...values }, loc, valueOffsets } : null;
123
131
  }
124
132
  var KEY_PATTERN = /^[A-Za-z][A-Za-z0-9 \-_]*$/;
125
133
  var SEPARATOR_PATTERN = /^\s*:\s*/;
@@ -380,7 +388,7 @@ var DIRECTIVE_KINDS = /* @__PURE__ */ new Set([
380
388
  "disable-next-line"
381
389
  ]);
382
390
  var DIRECTIVE_PREFIX = "madr-lint-";
383
- function parseDirective(value, line) {
391
+ function parseDirective(value, line, endLine) {
384
392
  const trimmed = value.trim();
385
393
  if (!trimmed.startsWith("<!--") || !trimmed.endsWith("-->")) return null;
386
394
  const inner = trimmed.slice(4, -3).trim();
@@ -391,7 +399,12 @@ function parseDirective(value, line) {
391
399
  const keyword = wsIndex === -1 ? afterPrefix : afterPrefix.slice(0, wsIndex);
392
400
  if (!DIRECTIVE_KINDS.has(keyword)) return null;
393
401
  const rest = wsIndex === -1 ? "" : afterPrefix.slice(wsIndex);
394
- return { kind: keyword, rules: parseRuleList(rest), line };
402
+ return {
403
+ kind: keyword,
404
+ rules: parseRuleList(rest),
405
+ line,
406
+ endLine
407
+ };
395
408
  }
396
409
  function parseRuleList(rest) {
397
410
  const trimmed = rest.trim();
@@ -402,8 +415,9 @@ function parseRuleList(rest) {
402
415
  function walkHtml(node, out) {
403
416
  if (node.type === "html") {
404
417
  const line = node.position?.start.line;
405
- if (typeof line === "number") {
406
- const directive = parseDirective(node.value, line);
418
+ const endLine = node.position?.end.line;
419
+ if (typeof line === "number" && typeof endLine === "number") {
420
+ const directive = parseDirective(node.value, line, endLine);
407
421
  if (directive) out.push(directive);
408
422
  }
409
423
  }
@@ -442,7 +456,7 @@ function collectDirectives(ast, body) {
442
456
  break;
443
457
  }
444
458
  case "disable-next-line": {
445
- const target = nextNonBlankLine(directive.line);
459
+ const target = nextNonBlankLine(directive.endLine);
446
460
  if (target === null) break;
447
461
  let entry = index.nextLine.get(target);
448
462
  if (!entry) {
@@ -1568,9 +1582,6 @@ var BASELINE_VERSION = 1;
1568
1582
  function baselinePath(cwd) {
1569
1583
  return join(cwd, ".madr-lint", "baseline.json");
1570
1584
  }
1571
- function nullProtoMap() {
1572
- return /* @__PURE__ */ Object.create(null);
1573
- }
1574
1585
  function buildBaseline(diagnostics) {
1575
1586
  const entries = nullProtoMap();
1576
1587
  for (const d of diagnostics) {