11import {
2+ type Reflection ,
23 ReflectionKind ,
34 type Comment ,
45 type CommentDisplayPart ,
@@ -17,7 +18,7 @@ function getBrokenPartLinks(parts: readonly CommentDisplayPart[]) {
1718 linkTags . includes ( part . tag ) &&
1819 ! part . target
1920 ) {
20- links . push ( part . text ) ;
21+ links . push ( part . text . trim ( ) ) ;
2122 }
2223 }
2324
@@ -40,79 +41,109 @@ export function validateLinks(
4041 logger : Logger ,
4142) : void {
4243 for ( const id in project . reflections ) {
43- const reflection = project . reflections [ id ] ;
44+ checkReflection ( project . reflections [ id ] , logger ) ;
45+ }
46+
47+ if ( ! ( project . id in project . reflections ) ) {
48+ checkReflection ( project , logger ) ;
49+ }
50+ }
4451
45- if ( reflection . isProject ( ) || reflection . isDeclaration ( ) ) {
46- for ( const broken of getBrokenPartLinks ( reflection . readme || [ ] ) ) {
47- // #2360, "@" is a future reserved character in TSDoc component paths
48- // If a link starts with it, and doesn't include a module source indicator "!"
49- // then the user probably is trying to link to a package containing "@" with an absolute link.
50- if ( broken . startsWith ( "@" ) && ! broken . includes ( "!" ) ) {
51- logger . warn (
52- logger . i18n . failed_to_resolve_link_to_0_in_readme_for_1_may_have_meant_2 (
53- broken ,
54- reflection . getFriendlyFullName ( ) ,
55- broken . replace ( / [ . # ~ ] / , "!" ) ,
56- ) ,
57- ) ;
58- } else {
59- logger . warn (
60- logger . i18n . failed_to_resolve_link_to_0_in_readme_for_1 (
61- broken ,
62- reflection . getFriendlyFullName ( ) ,
63- ) ,
64- ) ;
65- }
52+ function checkReflection ( reflection : Reflection , logger : Logger ) {
53+ if ( reflection . isProject ( ) || reflection . isDeclaration ( ) ) {
54+ for ( const broken of getBrokenPartLinks ( reflection . readme || [ ] ) ) {
55+ // #2360, "@" is a future reserved character in TSDoc component paths
56+ // If a link starts with it, and doesn't include a module source indicator "!"
57+ // then the user probably is trying to link to a package containing "@" with an absolute link.
58+ if ( broken . startsWith ( "@" ) && ! broken . includes ( "!" ) ) {
59+ logger . warn (
60+ logger . i18n . failed_to_resolve_link_to_0_in_readme_for_1_may_have_meant_2 (
61+ broken ,
62+ reflection . getFriendlyFullName ( ) ,
63+ broken . replace ( / [ . # ~ ] / , "!" ) ,
64+ ) ,
65+ ) ;
66+ } else {
67+ logger . warn (
68+ logger . i18n . failed_to_resolve_link_to_0_in_readme_for_1 (
69+ broken ,
70+ reflection . getFriendlyFullName ( ) ,
71+ ) ,
72+ ) ;
6673 }
6774 }
75+ }
6876
69- for ( const broken of getBrokenLinks ( reflection . comment ) ) {
77+ if ( reflection . isDocument ( ) ) {
78+ for ( const broken of getBrokenPartLinks ( reflection . content ) ) {
7079 // #2360, "@" is a future reserved character in TSDoc component paths
7180 // If a link starts with it, and doesn't include a module source indicator "!"
7281 // then the user probably is trying to link to a package containing "@" with an absolute link.
7382 if ( broken . startsWith ( "@" ) && ! broken . includes ( "!" ) ) {
7483 logger . warn (
75- logger . i18n . failed_to_resolve_link_to_0_in_comment_for_1_may_have_meant_2 (
84+ logger . i18n . failed_to_resolve_link_to_0_in_document_1_may_have_meant_2 (
7685 broken ,
7786 reflection . getFriendlyFullName ( ) ,
7887 broken . replace ( / [ . # ~ ] / , "!" ) ,
7988 ) ,
8089 ) ;
8190 } else {
8291 logger . warn (
83- logger . i18n . failed_to_resolve_link_to_0_in_comment_for_1 (
92+ logger . i18n . failed_to_resolve_link_to_0_in_document_1 (
8493 broken ,
8594 reflection . getFriendlyFullName ( ) ,
8695 ) ,
8796 ) ;
8897 }
8998 }
99+ }
90100
91- if (
92- reflection . isDeclaration ( ) &&
93- reflection . kindOf ( ReflectionKind . TypeAlias ) &&
94- reflection . type ?. type === "union" &&
95- reflection . type . elementSummaries
96- ) {
97- for ( const broken of reflection . type . elementSummaries . flatMap (
98- getBrokenPartLinks ,
99- ) ) {
100- if ( broken . startsWith ( "@" ) && ! broken . includes ( "!" ) ) {
101- logger . warn (
102- logger . i18n . failed_to_resolve_link_to_0_in_comment_for_1_may_have_meant_2 (
103- broken ,
104- reflection . getFriendlyFullName ( ) ,
105- broken . replace ( / [ . # ~ ] / , "!" ) ,
106- ) ,
107- ) ;
108- } else {
109- logger . warn (
110- logger . i18n . failed_to_resolve_link_to_0_in_comment_for_1 (
111- broken ,
112- reflection . getFriendlyFullName ( ) ,
113- ) ,
114- ) ;
115- }
101+ for ( const broken of getBrokenLinks ( reflection . comment ) ) {
102+ // #2360, "@" is a future reserved character in TSDoc component paths
103+ // If a link starts with it, and doesn't include a module source indicator "!"
104+ // then the user probably is trying to link to a package containing "@" with an absolute link.
105+ if ( broken . startsWith ( "@" ) && ! broken . includes ( "!" ) ) {
106+ logger . warn (
107+ logger . i18n . failed_to_resolve_link_to_0_in_comment_for_1_may_have_meant_2 (
108+ broken ,
109+ reflection . getFriendlyFullName ( ) ,
110+ broken . replace ( / [ . # ~ ] / , "!" ) ,
111+ ) ,
112+ ) ;
113+ } else {
114+ logger . warn (
115+ logger . i18n . failed_to_resolve_link_to_0_in_comment_for_1 (
116+ broken ,
117+ reflection . getFriendlyFullName ( ) ,
118+ ) ,
119+ ) ;
120+ }
121+ }
122+
123+ if (
124+ reflection . isDeclaration ( ) &&
125+ reflection . kindOf ( ReflectionKind . TypeAlias ) &&
126+ reflection . type ?. type === "union" &&
127+ reflection . type . elementSummaries
128+ ) {
129+ for ( const broken of reflection . type . elementSummaries . flatMap (
130+ getBrokenPartLinks ,
131+ ) ) {
132+ if ( broken . startsWith ( "@" ) && ! broken . includes ( "!" ) ) {
133+ logger . warn (
134+ logger . i18n . failed_to_resolve_link_to_0_in_comment_for_1_may_have_meant_2 (
135+ broken ,
136+ reflection . getFriendlyFullName ( ) ,
137+ broken . replace ( / [ . # ~ ] / , "!" ) ,
138+ ) ,
139+ ) ;
140+ } else {
141+ logger . warn (
142+ logger . i18n . failed_to_resolve_link_to_0_in_comment_for_1 (
143+ broken ,
144+ reflection . getFriendlyFullName ( ) ,
145+ ) ,
146+ ) ;
116147 }
117148 }
118149 }
0 commit comments