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:
106106<!-- llm_description= Utilities for working with file paths -->
107107```
108108
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+
109125### ` node-core:yaml-comments `
110126
111127Enforces structure and content of YAML comment blocks:
Original file line number Diff line number Diff line change @@ -14,10 +14,17 @@ const testCases = [
1414 input : 'Just a {number}.' ,
1515 expected : [ ] ,
1616 } ,
17+ {
18+ name : 'miswrapped reference' ,
19+ input : 'First a {string}, then a \\<number>.' ,
20+ expected : [ 'Type reference must be wrapped in "{}"; saw "<number>"' ] ,
21+ } ,
1722 {
1823 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+ ] ,
2128 } ,
2229 {
2330 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';
33import { lintRule } from 'unified-lint-rule' ;
44import { visit } from 'unist-util-visit' ;
55
6+ const SPACED_SEPERATOR_RE = / \s \| | \| \s / g;
7+
68/**
7- * Ensures that all self- references begin with `#`
9+ * Ensures that all type references are valid
810 * @type {import('unified-lint-rule').Rule }
911 */
1012const invalidTypeReference = ( tree , vfile ) => {
1113 visit ( tree , createQueries . UNIST . isTextWithType , node => {
1214 const types = node . value . match ( createQueries . QUERIES . normalizeTypes ) ;
1315
1416 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+
1530 if ( transformTypeToReferenceLink ( type ) === type ) {
1631 vfile . message ( `Invalid type reference: ${ type } ` , node ) ;
1732 }
You can’t perform that action at this time.
0 commit comments