@@ -23,6 +23,7 @@ export default iterateJsdoc(({
23
23
propertyQuotes = null ,
24
24
separatorForSingleObjectField = false ,
25
25
stringQuotes = 'single' ,
26
+ typeBracketSpacing = '' ,
26
27
unionSpacing = ' ' ,
27
28
} = context . options [ 0 ] || { } ;
28
29
@@ -55,7 +56,10 @@ export default iterateJsdoc(({
55
56
return tokens . name || tokens . description ;
56
57
} ) ;
57
58
58
- const nameAndDesc = tag . source . slice ( beginNameOrDescIdx ) ;
59
+ const nameAndDesc = beginNameOrDescIdx === - 1 ?
60
+ null :
61
+ tag . source . slice ( beginNameOrDescIdx ) ;
62
+
59
63
const initialNumber = tag . source [ 0 ] . number ;
60
64
const src = [
61
65
// Get inevitably present tag from first `tag.source`
@@ -70,7 +74,7 @@ export default iterateJsdoc(({
70
74
postName : '' ,
71
75
postType : '' ,
72
76
} : { } ) ,
73
- type : '{' + firstTypeLine + ( ! typeLines . length && lastTypeLine === undefined ? '}' : '' ) ,
77
+ type : '{' + typeBracketSpacing + firstTypeLine + ( ! typeLines . length && lastTypeLine === undefined ? typeBracketSpacing + '}' : '' ) ,
74
78
} ,
75
79
} ,
76
80
// Get any intervening type lines
@@ -98,14 +102,14 @@ export default iterateJsdoc(({
98
102
// Merge any final type line and name and description
99
103
if (
100
104
// Name and description may be already included if present with the tag
101
- beginNameOrDescIdx > 0
105
+ nameAndDesc && beginNameOrDescIdx > 0
102
106
) {
103
107
src . push ( {
104
108
number : src . length + 1 ,
105
109
source : '' ,
106
110
tokens : {
107
111
...nameAndDesc [ 0 ] . tokens ,
108
- type : lastTypeLine + '}' ,
112
+ type : lastTypeLine + typeBracketSpacing + '}' ,
109
113
} ,
110
114
} ) ;
111
115
@@ -126,7 +130,7 @@ export default iterateJsdoc(({
126
130
} ) ,
127
131
) ;
128
132
}
129
- } else {
133
+ } else if ( nameAndDesc ) {
130
134
if ( lastTypeLine ) {
131
135
src . push ( {
132
136
number : src . length + 1 ,
@@ -137,14 +141,14 @@ export default iterateJsdoc(({
137
141
postTag : '' ,
138
142
start : indent + ' ' ,
139
143
tag : '' ,
140
- type : lastTypeLine + '}' ,
144
+ type : lastTypeLine + typeBracketSpacing + '}' ,
141
145
} ,
142
146
} ) ;
143
147
}
144
148
145
149
if (
146
150
// Get any remaining description lines
147
- nameAndDesc . length > 1
151
+ nameAndDesc && nameAndDesc . length > 1
148
152
) {
149
153
src . push (
150
154
...nameAndDesc . slice ( 1 ) . map ( ( {
@@ -172,6 +176,14 @@ export default iterateJsdoc(({
172
176
return tg ;
173
177
} ) ;
174
178
179
+ const initialEndSource = jsdoc . source . find ( ( {
180
+ tokens : {
181
+ end,
182
+ } ,
183
+ } ) => {
184
+ return end ;
185
+ } ) ;
186
+
175
187
jsdoc . source = [
176
188
...jsdoc . source . slice ( 0 , firstTagIdx ) ,
177
189
...jsdoc . tags . flatMap ( ( {
@@ -180,11 +192,21 @@ export default iterateJsdoc(({
180
192
return source ;
181
193
} ) ,
182
194
] ;
195
+
196
+ if ( initialEndSource && ! jsdoc . source . at ( - 1 ) ?. tokens ?. end ) {
197
+ jsdoc . source . push ( initialEndSource ) ;
198
+ }
183
199
} ;
184
200
185
201
/** @type {string[] } */
186
202
const errorMessages = [ ] ;
187
203
204
+ if ( typeBracketSpacing && ( ! tag . type . startsWith ( typeBracketSpacing ) || ! tag . type . endsWith ( typeBracketSpacing ) ) ) {
205
+ errorMessages . push ( `Must have initial and final "${ typeBracketSpacing } " spacing` ) ;
206
+ } else if ( ! typeBracketSpacing && ( ( / ^ \s / v) . test ( tag . type ) || ( / \s $ / v) . test ( tag . type ) ) ) {
207
+ errorMessages . push ( 'Must have no initial spacing' ) ;
208
+ }
209
+
188
210
// eslint-disable-next-line complexity -- Todo
189
211
traverse ( parsedType , ( nde ) => {
190
212
let errorMessage = '' ;
@@ -279,7 +301,8 @@ export default iterateJsdoc(({
279
301
}
280
302
} ) ;
281
303
282
- const differentResult = tag . type !== stringify ( parsedType ) ;
304
+ const differentResult = tag . type !==
305
+ typeBracketSpacing + stringify ( parsedType ) + typeBracketSpacing ;
283
306
284
307
if ( errorMessages . length && differentResult ) {
285
308
for ( const errorMessage of errorMessages ) {
@@ -299,9 +322,13 @@ export default iterateJsdoc(({
299
322
const tags = utils . getPresentTags ( [
300
323
'param' ,
301
324
'returns' ,
325
+ 'type' ,
326
+ 'typedef' ,
302
327
] ) ;
303
328
for ( const tag of tags ) {
304
- checkTypeFormats ( tag ) ;
329
+ if ( tag . type ) {
330
+ checkTypeFormats ( tag ) ;
331
+ }
305
332
}
306
333
} , {
307
334
iterateAllJsdocs : true ,
@@ -362,6 +389,9 @@ export default iterateJsdoc(({
362
389
'single' ,
363
390
] ,
364
391
} ,
392
+ typeBracketSpacing : {
393
+ type : 'string' ,
394
+ } ,
365
395
unionSpacing : {
366
396
type : 'string' ,
367
397
} ,
0 commit comments