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
db6ed576
Commit
db6ed576
authored
Jan 23, 2020
by
Wiktor Walasek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option for vertical alignment
parent
a4596bf0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
6 deletions
+55
-6
jsdoc_parser.js
jsdoc_parser.js
+54
-4
tests/main.js
tests/main.js
+1
-2
No files found.
jsdoc_parser.js
View file @
db6ed576
...
...
@@ -38,6 +38,14 @@ const tagSynonyms = {
'
params
'
:
'
param
'
,
}
const
vertiacallyAlignableTags
=
[
'
param
'
,
'
property
'
,
'
return
'
,
'
throws
'
,
'
yields
'
,
]
/**
* Trim, make single line with capitalized text. Insert dot if flag for it is
* set to true and last character is a word character
...
...
@@ -90,6 +98,11 @@ function jsdocParser(text, parsers, options) {
if
(
parsed
.
description
&&
!
parsed
.
tags
.
find
(
t
=>
t
.
title
.
toLowerCase
()
===
'
description
'
))
parsed
.
tags
.
push
({
title
:
'
description
'
,
description
:
parsed
.
description
})
let
notAligmentTag
let
maxTagTitleLength
=
0
let
maxTagTypeNameLength
=
0
let
maxTagNameLength
=
0
parsed
.
tags
// Prepare tags data
...
...
@@ -97,6 +110,9 @@ function jsdocParser(text, parsers, options) {
tag
.
title
=
tag
.
title
.
trim
().
toLowerCase
()
tag
.
title
=
tagSynonyms
[
tag
.
title
]
||
tag
.
title
if
(
vertiacallyAlignableTags
.
includes
(
tag
.
title
))
maxTagTitleLength
=
Math
.
max
(
maxTagTitleLength
,
tag
.
title
.
length
)
if
(
tag
.
type
)
{
// Figure out tag.type.name
if
(
!
tag
.
type
.
name
)
{
...
...
@@ -118,6 +134,9 @@ function jsdocParser(text, parsers, options) {
}
}
if
(
vertiacallyAlignableTags
.
includes
(
tag
.
title
))
maxTagTypeNameLength
=
Math
.
max
(
maxTagTypeNameLength
,
tag
.
type
.
name
.
length
)
// Additional operations on tag.name
if
(
tag
.
name
)
{
// Figure out if tag type have default value
...
...
@@ -126,6 +145,8 @@ function jsdocParser(text, parsers, options) {
// Optional tag name
if
(
tag
.
type
.
type
===
'
OptionalType
'
)
tag
.
name
=
`[
${
tag
.
name
}
]`
if
(
vertiacallyAlignableTags
.
includes
(
tag
.
title
))
maxTagNameLength
=
Math
.
max
(
maxTagNameLength
,
tag
.
name
.
length
)
}
}
...
...
@@ -144,19 +165,41 @@ function jsdocParser(text, parsers, options) {
// Create final jsDoc string
.
forEach
((
tag
,
tagIndex
)
=>
{
let
tagTitleGapAdj
=
0
let
tagTypeGapAdj
=
0
let
tagNameGapAdj
=
0
let
descGapAdj
=
0
if
(
options
.
jsdocVerticalAlignment
&&
vertiacallyAlignableTags
.
includes
(
tag
.
title
))
{
if
(
tag
.
title
)
tagTitleGapAdj
+=
maxTagTitleLength
-
tag
.
title
.
length
else
descGapAdj
+=
maxTagTitleLength
+
gap
.
length
if
(
tag
.
type
.
name
)
tagTypeGapAdj
+=
maxTagTypeNameLength
-
tag
.
type
.
name
.
length
else
descGapAdj
+=
maxTagTypeNameLength
+
gap
.
length
if
(
tag
.
name
)
tagNameGapAdj
+=
maxTagNameLength
-
tag
.
name
.
length
else
descGapAdj
=
maxTagNameLength
+
gap
.
length
}
let
useTagTitle
=
(
tag
.
title
!==
'
description
'
||
options
.
jsdocDescriptionTag
)
let
tagString
=
` * `
if
(
useTagTitle
)
tagString
+=
`@
${
tag
.
title
}
`
if
(
tag
.
type
&&
tag
.
type
.
name
)
tagString
+=
gap
+
`{
${
tag
.
type
.
name
}
}`
if
(
tag
.
name
)
tagString
+=
gap
+
tag
.
name
if
(
useTagTitle
)
tagString
+=
`@
${
tag
.
title
}
`
+
'
'
.
repeat
(
tagTitleGapAdj
)
if
(
tag
.
type
&&
tag
.
type
.
name
)
tagString
+=
gap
+
`{
${
tag
.
type
.
name
}
}`
+
'
'
.
repeat
(
tagTypeGapAdj
)
if
(
tag
.
name
)
tagString
+=
gap
+
tag
.
name
+
'
'
.
repeat
(
tagNameGapAdj
)
// Add description (complicated because of text wrap)
if
(
tag
.
description
&&
tag
.
title
!==
'
example
'
)
{
if
([
'
memberof
'
,
'
see
'
].
includes
(
tag
.
title
))
{
// Avoid wrapping
tagString
+=
tag
.
description
}
else
{
// Wrap tag description
if
(
useTagTitle
)
tagString
+=
gap
if
(
useTagTitle
)
tagString
+=
gap
+
'
'
.
repeat
(
descGapAdj
)
const
marginLength
=
tagString
.
length
let
maxWidth
=
printWidth
if
(
marginLength
>=
maxWidth
)
maxWidth
=
marginLength
+
40
...
...
@@ -257,6 +300,12 @@ module.exports = {
category
:
'
Global
'
,
default
:
true
,
description
:
'
please disable me
'
,
},
jsdocVerticalAlignment
:
{
type
:
'
boolean
'
,
category
:
'
Global
'
,
default
:
false
,
description
:
'
keep nice and align
'
,
}
},
defaultOptions
:
{
...
...
@@ -264,5 +313,6 @@ module.exports = {
jsdocPrintWidth
:
80
,
jsdocAddDotToDescription
:
false
,
jsdocDescriptionTag
:
true
,
jsdocVerticalAlignment
:
false
,
}
}
tests/main.js
View file @
db6ed576
...
...
@@ -8,8 +8,7 @@ function subject(code, options = {}) {
parser
:
'
jsdoc-parser
'
,
plugins
:
[
'
.
'
],
jsdocSpaces
:
1
,
jsdocPrintWidth
:
80
,
jsdocAddDotToDescription
:
true
jsdocPrintWidth
:
80
});
}
...
...
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