Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
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
375dba57
Commit
375dba57
authored
Jan 29, 2020
by
gumen
🐢
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'example-trim-option' into 'master'
Add option to keep unparseable example indent See merge request
!3
parents
3e95c1d9
72d41acb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
138 additions
and
1 deletion
+138
-1
jsdoc_parser.js
jsdoc_parser.js
+9
-1
tests/main.js
tests/main.js
+129
-0
No files found.
jsdoc_parser.js
View file @
375dba57
...
...
@@ -218,7 +218,8 @@ function jsdocParser(text, parsers, options) {
tagString
+=
formatedDescription
.
replace
(
/
(
^|
\n)
/g
,
'
\n
*
'
)
tagString
=
tagString
.
slice
(
0
,
tagString
.
length
-
6
)
}
catch
(
err
)
{
tagString
+=
'
\n
'
+
tag
.
description
.
split
(
'
\n
'
).
map
(
l
=>
'
*
'
+
l
.
trim
()).
join
(
'
\n
'
)
tagString
+=
'
\n
'
+
tag
.
description
.
split
(
'
\n
'
).
map
(
l
=>
` *
${
options
.
jsdocKeepUnparseableExampleIndent
?
l
:
l
.
trim
()}
`
).
join
(
'
\n
'
)
}
}
...
...
@@ -301,6 +302,12 @@ module.exports = {
category
:
'
jsdoc
'
,
default
:
false
,
description
:
'
Should tags, types, names and description be aligned
'
,
},
jsdocKeepUnparseableExampleIndent
:
{
type
:
'
boolean
'
,
category
:
'
jsdoc
'
,
default
:
false
,
description
:
'
Should unparseable esample (pseudo code or no js code) keep its indentation
'
,
}
},
defaultOptions
:
{
...
...
@@ -309,5 +316,6 @@ module.exports = {
jsdocDescriptionWithDot
:
false
,
jsdocDescriptionTag
:
true
,
jsdocVerticalAlignment
:
false
,
jsdocKeepUnparseableExampleIndent
:
false
,
}
}
tests/main.js
View file @
375dba57
...
...
@@ -325,3 +325,132 @@ test('yields should work like return tag', () => {
expect
(
Result4
).
toEqual
(
Expected4
)
expect
(
Result5
).
toEqual
(
Expected5
)
})
test
(
'
should trim whitespace on unparseable examples - default options
'
,
()
=>
{
const
Result1
=
subject
(
`/**
* @example
* {
* testArr: [
* 1,
* 2,
* ...
* ]
* }
*/`
)
const
Expected1
=
`/**
* @example
* {
* testArr: [
* 1,
* 2,
* ...
* ]
* }
*/
`
const
Result2
=
subject
(
`/**
* @example
* // sample call:
* foo(bar)
*
* // result
* [{
* foo: 1,
* foo: 2,
* ...,
* foo: 9,
* }, {
* bar: 1,
* ...,
* bar: 5
* }]
*/`
)
const
Expected2
=
`/**
* @example
* // sample call:
* foo(bar)
*
* // result
* [{
* foo: 1,
* foo: 2,
* ...,
* foo: 9,
* }, {
* bar: 1,
* ...,
* bar: 5
* }]
*/
`
expect
(
Result1
).
toEqual
(
Expected1
)
expect
(
Result2
).
toEqual
(
Expected2
)
})
test
(
'
should keep indent on unparseable examples - if flag set to true
'
,
()
=>
{
const
options
=
{
jsdocKeepUnparseableExampleIndent
:
true
,
}
const
Result1
=
subject
(
`/**
* @example
* {
* testArr: [
* 1,
* 2,
* ...
* ]
* }
*/`
,
options
)
const
Expected1
=
`/**
* @example
* {
* testArr: [
* 1,
* 2,
* ...
* ]
* }
*/
`
const
Result2
=
subject
(
`/**
* @example
* // sample call:
* foo(bar)
*
* // result
* [{
* foo: 1,
* foo: 2,
* ...,
* foo: 9,
* }, {
* bar: 1,
* ...,
* bar: 5
* }]
*/`
,
options
)
const
Expected2
=
`/**
* @example
* // sample call:
* foo(bar)
*
* // result
* [{
* foo: 1,
* foo: 2,
* ...,
* foo: 9,
* }, {
* bar: 1,
* ...,
* bar: 5
* }]
*/
`
expect
(
Result1
).
toEqual
(
Expected1
)
expect
(
Result2
).
toEqual
(
Expected2
)
})
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