Skip to content

Commit a5fcc2d

Browse files
committed
chore(remark-lint): migrate to @doc-kit/core
@node-core/doc-kit 2 moved its internals to @doc-kit/core, and removed the two helpers invalid-type-reference was built on: `transformTypeToReferenceLink` and `QUERIES.normalizeTypes`. - duplicate-stability-nodes and validate-links import the same modules from @doc-kit/core. - invalid-type-reference keeps its type pattern locally and resolves each `|` member with doc-kit's `resolveTypeReference`, so it accepts exactly what the generator can link. Types never reach it with `<>` in them, so the old generic handling is gone. - The old resolver accepted anything containing a `.`, which hid HTML comments and tags being read as `<type>` references. The html branch now only matches bare `<name>` nodes. - doc-kit 2 no longer turns `_` into `-` in slugs, matching the site's rehype-slug and the Node.js API anchors (`#child_process`). Over Node.js's doc/api with its type-map.json, the rule reports nothing new: it drops the HTML false positives (7103 -> 283 messages) and now resolves {object}, {QuotaExceededError}, {WorkerGlobalScope} and {DedicatedWorkerGlobalScope}. The site's markdown lint stays clean. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6920b1d commit a5fcc2d

8 files changed

Lines changed: 145 additions & 1235 deletions

File tree

‎.changeset/quiet-rules-migrate.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@node-core/remark-lint': patch
3+
---
4+
5+
Use `@doc-kit/core` instead of `@node-core/doc-kit` 1.x. Heading anchors now follow doc-kit 2's slugs (`child_process` links as `#child_process`), and `invalid-type-reference` no longer treats HTML comments and tags as type references.

‎packages/remark-lint/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"test:unit": "cross-env NODE_NO_WARNINGS=1 node --experimental-test-coverage --test \"**/*.test.mjs\""
2222
},
2323
"dependencies": {
24-
"@node-core/doc-kit": "^1.2.0",
24+
"@doc-kit/core": "^1.3.1",
2525
"mdast-util-to-string": "^4.0.0",
2626
"remark-gfm": "^4.0.1",
2727
"remark-lint-blockquote-indentation": "^4.0.1",

‎packages/remark-lint/src/rules/__tests__/invalid-type-reference.test.mjs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,28 @@ const value = {invalid};
3838
<div>{invalid}</div>`,
3939
expected: [],
4040
},
41+
{
42+
name: 'ignores HTML comments and tags',
43+
input: `<!--introduced_in=v0.10.0-->
44+
45+
<a id="module_builtins" href="module.html#builtins"></a>`,
46+
expected: [],
47+
},
48+
{
49+
name: 'array reference',
50+
input: 'Takes a {string[]}.',
51+
expected: [],
52+
},
53+
{
54+
name: 'module-qualified reference',
55+
input: 'Returns a {vm.Module}.',
56+
expected: [],
57+
},
58+
{
59+
name: 'union with one resolvable member',
60+
input: 'This is a {Unknown|number}.',
61+
expected: [],
62+
},
4163
{
4264
name: 'multiple references',
4365
input: 'Psst, are you a {string | boolean}',

‎packages/remark-lint/src/rules/__tests__/validate-links.test.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('validate-links', () => {
111111
'# Existing heading',
112112
'[Existing](#existing%2Dheading)',
113113
'# child_process',
114-
'[Node.js-style slug](#child-process)',
114+
'[Node.js-style slug](#child_process)',
115115
].join('\n\n')
116116
);
117117
const invalid = await processMarkdown(

‎packages/remark-lint/src/rules/duplicate-stability-nodes.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QUERIES } from '@node-core/doc-kit/src/utils/queries/index.mjs';
1+
import { QUERIES } from '@doc-kit/core/src/utils/queries/index.mjs';
22
import { lintRule } from 'unified-lint-rule';
33
import { visit } from 'unist-util-visit';
44

‎packages/remark-lint/src/rules/invalid-type-reference.mjs‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,51 @@
1-
import { transformTypeToReferenceLink } from '@node-core/doc-kit/src/generators/metadata/utils/transformers.mjs';
2-
import { QUERIES } from '@node-core/doc-kit/src/utils/queries/index.mjs';
1+
import { resolveTypeReference } from '@doc-kit/core/src/generators/metadata/utils/transformers.mjs';
32
import { lintRule } from 'unified-lint-rule';
43
import { visit } from 'unist-util-visit';
54

5+
const TYPE_RE = /(\{|<)(?! )[^<({})>]+(?! )(\}|>)/g;
6+
// Excludes HTML comments, closing tags and tags with attributes
7+
const HTML_TYPE_RE = /^<[^\s!/=]+>$/;
68
const MATCH_RE = /\s\||\| /g;
79
const REPLACE_RE = /\s*\| */g;
810

911
const isTypeNode = node => {
1012
if (node.type === 'text') {
11-
return QUERIES.normalizeTypes.test(node.value);
13+
return TYPE_RE.test(node.value);
1214
}
1315

1416
if (node.type === 'html') {
15-
return node.value.match(QUERIES.normalizeTypes)?.includes(node.value);
17+
return (
18+
HTML_TYPE_RE.test(node.value) &&
19+
node.value.match(TYPE_RE)?.includes(node.value)
20+
);
1621
}
1722

1823
return false;
1924
};
2025

26+
/**
27+
* Whether at least one member of a `{type}` reference links somewhere
28+
* @param {string} type
29+
* @param {Record<string, string>} typeMap
30+
* @returns {boolean}
31+
*/
32+
const isResolvable = (type, typeMap) =>
33+
type
34+
.slice(1, -1)
35+
.split('|')
36+
.some(piece => {
37+
const name = piece.trim().replace(/\[\]$/, '');
38+
39+
return name.length > 0 && resolveTypeReference(name, typeMap) !== '';
40+
});
41+
2142
/**
2243
* Ensures that all type references are valid
2344
* @type {import('unified-lint-rule').Rule<, import('../api.mjs').Options>}
2445
*/
2546
const invalidTypeReference = (tree, vfile, { typeMap = {} }) => {
2647
visit(tree, isTypeNode, node => {
27-
const types = node.value.match(QUERIES.normalizeTypes);
48+
const types = node.value.match(TYPE_RE);
2849

2950
types.forEach(type => {
3051
// Ensure wrapped in {}
@@ -50,7 +71,7 @@ const invalidTypeReference = (tree, vfile, { typeMap = {} }) => {
5071
node.value = node.value.replace(type, normalized);
5172
}
5273

53-
if (transformTypeToReferenceLink(type, typeMap) === type) {
74+
if (!isResolvable(type, typeMap)) {
5475
vfile.message(`Invalid type reference: ${type}`, node);
5576
}
5677
});

‎packages/remark-lint/src/rules/validate-links.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { readdir } from 'node:fs/promises';
22
import path from 'node:path';
33
import { fileURLToPath, pathToFileURL } from 'node:url';
44

5-
import createNodeSlugger from '@node-core/doc-kit/src/generators/metadata/utils/slugger.mjs';
5+
import createNodeSlugger from '@doc-kit/core/src/generators/metadata/utils/slugger.mjs';
66
import { toString } from 'mdast-util-to-string';
77
import { lintRule } from 'unified-lint-rule';
88
import { visit } from 'unist-util-visit';

0 commit comments

Comments
 (0)