File tree Expand file tree Collapse file tree 3 files changed +41
-3
lines changed Expand file tree Collapse file tree 3 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,22 @@ Metadata can be provided in comments:
106
106
<!-- llm_description= Utilities for working with file paths -->
107
107
```
108
108
109
+ ### ` node-core:invalid-type-reference `
110
+
111
+ Ensures that all ` {type} ` references are valid types and formatted correctly.
112
+
113
+ ** Allowed:**
114
+
115
+ ``` markdown
116
+ This is usually a {boolean}, but it could also be a {string|number}.
117
+ ```
118
+
119
+ ** Not allowed:**
120
+
121
+ ``` markdown
122
+ This is an {invalid} type, and so is {string | number}.
123
+ ```
124
+
109
125
### ` node-core:yaml-comments `
110
126
111
127
Enforces structure and content of YAML comment blocks:
Original file line number Diff line number Diff line change @@ -14,10 +14,17 @@ const testCases = [
14
14
input : 'Just a {number}.' ,
15
15
expected : [ ] ,
16
16
} ,
17
+ {
18
+ name : 'miswrapped reference' ,
19
+ input : 'First a {string}, then a \\<number>.' ,
20
+ expected : [ 'Type reference must be wrapped in "{}"; saw "<number>"' ] ,
21
+ } ,
17
22
{
18
23
name : 'multiple references' ,
19
- input : 'Psst, are you a {string} or a {boolean}' ,
20
- expected : [ ] ,
24
+ input : 'Psst, are you a {string | boolean}' ,
25
+ expected : [
26
+ 'Type reference should be seperated by "|", without spaces; saw "{string | boolean}"' ,
27
+ ] ,
21
28
} ,
22
29
{
23
30
name : 'invalid references' ,
Original file line number Diff line number Diff line change @@ -3,15 +3,30 @@ import createQueries from '@nodejs/doc-kit/src/utils/queries/index.mjs';
3
3
import { lintRule } from 'unified-lint-rule' ;
4
4
import { visit } from 'unist-util-visit' ;
5
5
6
+ const SPACED_SEPERATOR_RE = / \s \| | \| \s / g;
7
+
6
8
/**
7
- * Ensures that all self- references begin with `#`
9
+ * Ensures that all type references are valid
8
10
* @type {import('unified-lint-rule').Rule }
9
11
*/
10
12
const invalidTypeReference = ( tree , vfile ) => {
11
13
visit ( tree , createQueries . UNIST . isTextWithType , node => {
12
14
const types = node . value . match ( createQueries . QUERIES . normalizeTypes ) ;
13
15
14
16
types . forEach ( type => {
17
+ if ( type [ 0 ] !== '{' || type . at ( - 1 ) !== '}' ) {
18
+ vfile . message (
19
+ `Type reference must be wrapped in "{}"; saw "${ type } "` ,
20
+ node
21
+ ) ;
22
+ }
23
+
24
+ if ( SPACED_SEPERATOR_RE . test ( type ) ) {
25
+ vfile . message (
26
+ `Type reference should be seperated by "|", without spaces; saw "${ type } "`
27
+ ) ;
28
+ }
29
+
15
30
if ( transformTypeToReferenceLink ( type ) === type ) {
16
31
vfile . message ( `Invalid type reference: ${ type } ` , node ) ;
17
32
}
You can’t perform that action at this time.
0 commit comments