Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
6
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
P
prettier-plugin-jsdoc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gumen
prettier-plugin-jsdoc
Commits
9e2120ad
Commit
9e2120ad
authored
Jan 20, 2020
by
irekg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improvements
parent
52cb6b34
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
22 deletions
+23
-22
jsdoc_parser.js
jsdoc_parser.js
+23
-22
No files found.
jsdoc_parser.js
View file @
9e2120ad
const
cwd
=
process
.
cwd
()
const
path
=
require
(
'
path
'
)
const
doctrine
=
require
(
'
doctrine
'
)
const
prettier
=
require
(
'
prettier
'
)
const
babelFlow
=
require
(
path
.
join
(
cwd
,
'
node_modules/prettier/parser-babylon.js
'
)
).
parsers
[
'
babel-flow
'
]
const
babelFlow
=
require
(
'
prettier/parser-babylon
'
).
parsers
[
'
babel-flow
'
]
const
tagSynonyms
=
{
// One TAG TYPE can have different titles called SYNONYMS. We want
...
...
@@ -41,7 +39,7 @@ const tagSynonyms = {
}
/**
* Trim, make single line with capitalized text
and dot at the end.
* Trim, make single line with capitalized text
* @param {String} text
* @return {String}
*/
...
...
@@ -51,7 +49,6 @@ function formatDescription(text) {
text
=
text
.
replace
(
/
\s\s
+/g
,
'
'
)
// Avoid multiple spaces
text
=
text
.
replace
(
/
\n
/g
,
'
'
)
// Make single line
text
=
text
[
0
].
toUpperCase
()
+
text
.
slice
(
1
)
// Capitalize
if
(
text
[
text
.
length
-
1
]
!==
'
.
'
)
text
+=
'
.
'
// End with dot
return
text
||
''
}
...
...
@@ -63,16 +60,19 @@ function formatDescription(text) {
function
getTagOrderWeight
(
tagTitle
)
{
var
tagsWeightMap
=
{
'
private
'
:
1
,
'
memberof
'
:
2
,
'
see
'
:
3
,
'
description
'
:
4
,
'
examples
'
:
5
,
'
global
'
:
2
,
'
class
'
:
3
,
'
memberof
'
:
4
,
'
see
'
:
5
,
'
description
'
:
6
,
'
todo
'
:
7
,
'
examples
'
:
8
,
// TODO everything else could be sorted alphabetically
// Everything else will have
6
'
param
'
:
7
,
'
return
'
:
8
,
// Everything else will have
9
'
param
'
:
10
,
'
return
'
:
11
,
}
return
tagsWeightMap
[
tagTitle
]
||
6
return
tagsWeightMap
[
tagTitle
]
||
9
}
/** {@link https://prettier.io/docs/en/api.html#custom-parser-api} */
...
...
@@ -132,18 +132,21 @@ function jsdocParser(text, parsers, options) {
const
part2
=
part1
.
split
(
/
\s
/
)[
0
]
const
sliceIndex
=
part2
.
indexOf
(
'
=
'
)
if
(
sliceIndex
!==
-
1
)
tag
.
name
=
tag
.
name
+
part2
.
slice
(
sliceIndex
,
part2
.
length
).
replace
(
'
]
'
,
''
)
tag
.
name
=
tag
.
name
+
'
=
'
+
part2
.
slice
(
sliceIndex
+
1
,
part2
.
length
)
.
replace
(
'
]
'
,
''
)
.
trim
()
// Optional tag name
if
(
tag
.
type
.
type
===
'
OptionalType
'
)
tag
.
name
=
`[
${
tag
.
name
}
]`
}
}
if
([
'
description
'
,
'
param
'
,
'
return
'
].
includes
(
tag
.
title
))
if
([
'
description
'
,
'
param
'
,
'
return
'
,
'
todo
'
].
includes
(
tag
.
title
))
tag
.
description
=
formatDescription
(
tag
.
description
)
if
(
!
tag
.
description
&&
[
'
description
'
,
'
param
'
,
'
return
'
,
'
memberof
'
].
includes
(
tag
.
title
))
tag
.
description
=
'
TODO
.
'
if
(
!
tag
.
description
&&
[
'
description
'
,
'
param
'
,
'
return
'
,
'
todo
'
,
'
memberof
'
].
includes
(
tag
.
title
))
tag
.
description
=
'
TODO
'
return
tag
})
...
...
@@ -186,16 +189,14 @@ function jsdocParser(text, parsers, options) {
tagString
+=
formatedDescription
.
replace
(
/
(
^|
\n)
/g
,
'
\n
*
'
)
tagString
=
tagString
.
slice
(
0
,
tagString
.
length
-
6
)
}
catch
(
err
)
{
console
.
error
(
new
Error
(
'
Cannot format tag description
'
),
tag
.
description
)
const
description
=
tag
.
description
.
split
(
'
\n
'
).
map
(
l
=>
'
*
'
+
l
.
trim
()).
join
(
'
\n
'
)
tagString
+=
'
\n
* // ERROR Invalid JS
\n
'
+
description
tagString
+=
'
\n
'
+
tag
.
description
.
split
(
'
\n
'
).
map
(
l
=>
'
*
'
+
l
.
trim
()).
join
(
'
\n
'
)
}
}
tagString
+=
'
\n
'
// Add empty line after
@description or @example
if there is something below
if
([
'
description
'
,
'
example
'
].
includes
(
tag
.
title
)
&&
tagIndex
!==
parsed
.
tags
.
length
-
1
)
// Add empty line after
some tags
if there is something below
if
([
'
description
'
,
'
example
'
,
'
todo
'
].
includes
(
tag
.
title
)
&&
tagIndex
!==
parsed
.
tags
.
length
-
1
)
tagString
+=
'
*
\n
'
comment
.
value
+=
tagString
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment