File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -8,10 +8,13 @@ const translate: Record<string, string> = {
8
8
} ;
9
9
10
10
function formatDocs ( docs : string ) : string [ ] {
11
- const lines = docs . replaceAll ( / \* \/ / g, "* /" ) . split ( "\n" ) . map ( ( v ) =>
12
- ` * ${ v } `
13
- ) ;
14
- return [ "/**" , ...lines , " */" ] ;
11
+ const lines = docs . replaceAll ( / \* \/ / g, "* /" ) . split ( "\n" ) ;
12
+ const leading =
13
+ lines . map ( ( v ) => v . match ( / ^ \s * / ) ! [ 0 ] ) . reduce ( ( a , v ) =>
14
+ a . length < v . length ? a : v
15
+ ) . length ;
16
+ const normalizedLines = lines . map ( ( v ) => ` * ${ v . substring ( leading ) } ` ) ;
17
+ return [ "/**" , ...normalizedLines , " */" ] ;
15
18
}
16
19
17
20
function formatVariants ( fn : string , vars : Variant [ ] ) : string [ ] {
Original file line number Diff line number Diff line change @@ -21,10 +21,13 @@ function defaultValue(type: string): string {
21
21
}
22
22
23
23
function formatDocs ( docs : string ) : string [ ] {
24
- const lines = docs . replaceAll ( / \* \/ / g, "* /" ) . split ( "\n" ) . map ( ( v ) =>
25
- ` * ${ v } `
26
- ) ;
27
- return [ "/**" , ...lines , " */" ] ;
24
+ const lines = docs . replaceAll ( / \* \/ / g, "* /" ) . split ( "\n" ) ;
25
+ const leading =
26
+ lines . map ( ( v ) => v . match ( / ^ \s * / ) ! [ 0 ] ) . reduce ( ( a , v ) =>
27
+ a . length < v . length ? a : v
28
+ ) . length ;
29
+ const normalizedLines = lines . map ( ( v ) => ` * ${ v . substring ( leading ) } ` ) ;
30
+ return [ "/**" , ...normalizedLines , " */" ] ;
28
31
}
29
32
30
33
function formatOption ( { name, type, scope, docs } : Option ) : string [ ] {
You can’t perform that action at this time.
0 commit comments