Commit ea604042 authored by VectorW's avatar VectorW

Merge branch 'master' into 'keep-inner-types'

# Conflicts:
#   jsdoc_parser.js
parents 1fdbf6d6 375dba57
......@@ -249,7 +249,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')
}
}
......@@ -338,6 +339,11 @@ module.exports = {
category: 'jsdoc',
default: false,
description: 'Should union type be enclosed in parentheses'
jsdocKeepUnparseableExampleIndent: {
type: 'boolean',
category: 'jsdoc',
default: false,
description: 'Should unparseable esample (pseudo code or no js code) keep its indentation',
}
},
defaultOptions: {
......@@ -347,5 +353,6 @@ module.exports = {
jsdocDescriptionTag: true,
jsdocVerticalAlignment: false,
jsdocUnionTypeParentheses: false,
jsdocKeepUnparseableExampleIndent: false,
}
}
......@@ -462,3 +462,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)
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment