Skip to content

Commit 0c44bd1

Browse files
committed
add auto fixing
1 parent c84a5fd commit 0c44bd1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/remark-lint/src/rules/hashed-self-reference.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const hashedSelfReference = (tree, vfile) => {
3333

3434
if (targetURL.pathname === currentFileURL.pathname) {
3535
const expected = url.includes('#') ? url.slice(url.indexOf('#')) : '#';
36+
node.url = expected;
3637

3738
vfile.message(
3839
`Self-reference must start with hash (expected "${expected}", got "${url}")`,

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import createQueries from '@nodejs/doc-kit/src/utils/queries/index.mjs';
33
import { lintRule } from 'unified-lint-rule';
44
import { visit } from 'unist-util-visit';
55

6-
const SPACED_SEPERATOR_RE = /\s\||\|\s/g;
6+
const MATCH_RE = /\s\||\|\s/g;
7+
const REPLACE_RE = /\s*\|\s*/g;
78

89
/**
910
* Ensures that all type references are valid
@@ -14,17 +15,25 @@ const invalidTypeReference = (tree, vfile) => {
1415
const types = node.value.match(createQueries.QUERIES.normalizeTypes);
1516

1617
types.forEach(type => {
17-
if (type[0] !== '{' || type.at(-1) !== '}') {
18+
// Ensure wrapped in {}
19+
if (type[0] !== '{' || type[type.length - 1] !== '}') {
1820
vfile.message(
1921
`Type reference must be wrapped in "{}"; saw "${type}"`,
2022
node
2123
);
24+
25+
node.value = node.value.replace(type, `{${type.slice(1, -1)}}`);
2226
}
2327

24-
if (SPACED_SEPERATOR_RE.test(type)) {
28+
// Fix spaces around |
29+
if (MATCH_RE.test(type)) {
2530
vfile.message(
26-
`Type reference should be seperated by "|", without spaces; saw "${type}"`
31+
`Type reference should be separated by "|", without spaces; saw "${type}"`,
32+
node
2733
);
34+
35+
const normalized = type.replace(REPLACE_RE, '|');
36+
node.value = node.value.replace(type, normalized);
2837
}
2938

3039
if (transformTypeToReferenceLink(type) === type) {

0 commit comments

Comments
 (0)