-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prettier-plugin-jsdoc): add function to render example tags
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @typedef {import('../types').CommentTag} CommentTag | ||
*/ | ||
|
||
/** | ||
* Renders an `example` tag by just adding the code below the tag. | ||
* | ||
* @param {CommentTag} tag The tag to render. | ||
* @returns {string[]} | ||
*/ | ||
const renderExampleTag = (tag) => [ | ||
`@${tag.tag}`, | ||
...tag.description.split('\n'), | ||
]; | ||
|
||
module.exports.renderExampleTag = renderExampleTag; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
jest.unmock('../../../src/fns/renderExampleTag'); | ||
|
||
const { renderExampleTag } = require('../../../src/fns/renderExampleTag'); | ||
|
||
describe('renderExampleTag', () => { | ||
it('should ignore a tag that\'s not @example', () => { | ||
// Given | ||
const input = { | ||
tag: 'example', | ||
description: 'const fn = (msg) => console.log(msg);\nfn(\'hello world!\');', | ||
}; | ||
const output = [ | ||
'@example', | ||
'const fn = (msg) => console.log(msg);', | ||
'fn(\'hello world!\');', | ||
]; | ||
let result = null; | ||
// When | ||
result = renderExampleTag(input); | ||
// Then | ||
expect(result).toEqual(output); | ||
}); | ||
}); |