Skip to content

Commit

Permalink
fix(prettier-plugin-jsdoc): move names to a new line when the type is…
Browse files Browse the repository at this point in the history
… too long
  • Loading branch information
homer0 committed Oct 30, 2020
1 parent 93a5da1 commit 791e5e4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/fns/renderTagInLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ const renderTagInLine = R.curry((width, typePadding, namePadding, tag) => {
const tagHeaderWithSpace = `${tagHeader}${useTypePadding}{${tag.type}}${useNamePadding}`;
const nameWidth = width - tagHeaderWithSpace.length;
const nameLines = get(splitText)(tag.name, nameWidth);
result = [`${tagHeaderWithSpace}${nameLines.shift()}`.trimRight()];
const nameFirstLine = nameLines.shift();
const topLine = `${tagHeaderWithSpace}${nameFirstLine}`.trimRight();
if (topLine.length > width) {
result = [
tagHeaderWithSpace.trimRight(),
nameFirstLine,
];
} else {
result = [topLine];
}
if (nameLines.length) {
const namePaddingForLine = ' '.repeat(tagHeaderWithSpace.length);
result.push(...nameLines.map((line) => `${namePaddingForLine}${line}`));
Expand Down
25 changes: 21 additions & 4 deletions test/e2e/fixtures/random-01.fixture.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module.exports = {
only: true,
};

//# input

/**
* @external Jimple
* @see https://yarnpkg.com/en/package/jimple
*/

/**
* @type {Object} Something
* @description transform this into a sentence
Expand Down Expand Up @@ -33,8 +34,18 @@ const log = (name = 'batman', logger) => {};
* @returns {User} some description for the return value
*/

/**
* @typedef {StaticsControllerOptions & StaticsControllerWrapperOptionsProperties} StaticsControllerWrapperOptions
* @parent module:controllers
*/

//# output

/**
* @external Jimple
* @see https://yarnpkg.com/en/package/jimple
*/

/**
* Transform this into a sentence.
*
Expand Down Expand Up @@ -84,3 +95,9 @@ const log = (name = 'batman', logger) => {};
* @summary
* Something else.
*/

/**
* @typedef {StaticsControllerOptions & StaticsControllerWrapperOptionsProperties}
* StaticsControllerWrapperOptions
* @parent module:controllers
*/
18 changes: 18 additions & 0 deletions test/unit/fns/renderTagInLine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ describe('renderTagInLine', () => {
namePadding: 1,
},
},
{
it: 'should move the name to a new line when the type is too long',
input: {
tag: 'typedef',
type: 'StaticsControllerOptions & StaticsControllerWrapperOptionsProperties',
name: 'StaticsControllerWrapperOptions',
description: '',
},
output: [
'@typedef {StaticsControllerOptions & StaticsControllerWrapperOptionsProperties}',
'StaticsControllerWrapperOptions',
],
options: {
width: 90,
typePadding: 1,
namePadding: 1,
},
},
];

it.each(cases)('should correctly format the case %#', (caseInfo) => {
Expand Down

0 comments on commit 791e5e4

Please sign in to comment.