1
1
import {
2
+ type Reflection ,
2
3
ReflectionKind ,
3
4
type Comment ,
4
5
type CommentDisplayPart ,
@@ -17,7 +18,7 @@ function getBrokenPartLinks(parts: readonly CommentDisplayPart[]) {
17
18
linkTags . includes ( part . tag ) &&
18
19
! part . target
19
20
) {
20
- links . push ( part . text ) ;
21
+ links . push ( part . text . trim ( ) ) ;
21
22
}
22
23
}
23
24
@@ -40,79 +41,109 @@ export function validateLinks(
40
41
logger : Logger ,
41
42
) : void {
42
43
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
+ }
44
51
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
+ ) ;
66
73
}
67
74
}
75
+ }
68
76
69
- for ( const broken of getBrokenLinks ( reflection . comment ) ) {
77
+ if ( reflection . isDocument ( ) ) {
78
+ for ( const broken of getBrokenPartLinks ( reflection . content ) ) {
70
79
// #2360, "@" is a future reserved character in TSDoc component paths
71
80
// If a link starts with it, and doesn't include a module source indicator "!"
72
81
// then the user probably is trying to link to a package containing "@" with an absolute link.
73
82
if ( broken . startsWith ( "@" ) && ! broken . includes ( "!" ) ) {
74
83
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 (
76
85
broken ,
77
86
reflection . getFriendlyFullName ( ) ,
78
87
broken . replace ( / [ . # ~ ] / , "!" ) ,
79
88
) ,
80
89
) ;
81
90
} else {
82
91
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 (
84
93
broken ,
85
94
reflection . getFriendlyFullName ( ) ,
86
95
) ,
87
96
) ;
88
97
}
89
98
}
99
+ }
90
100
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
+ ) ;
116
147
}
117
148
}
118
149
}
0 commit comments