-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(prettier-plugin-jsdoc): transform sentences on tags that use name
- Loading branch information
Showing
4 changed files
with
61 additions
and
12 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
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 |
---|---|---|
@@ -1,29 +1,58 @@ | ||
const R = require('ramda'); | ||
const { ensureSentence, hasValidProperty, isTag } = require('./utils'); | ||
const { getTagsWithNameAsDescription } = require('./constants'); | ||
const { get, provider } = require('./app'); | ||
|
||
/** | ||
* @typedef {import('../types').CommentTag} CommentTag | ||
*/ | ||
|
||
/** | ||
* Takes a tag property, transforms it into a sentence and updates the tag. | ||
* | ||
* @callback MakePropertyIntoSentenceFn | ||
* @param {string} property The name of the property to transform. | ||
* @param {CommentTag} tag The tag where the property will be updated. | ||
* @returns {CommentTag} | ||
*/ | ||
|
||
/** | ||
* @type {MakePropertyIntoSentenceFn} | ||
*/ | ||
const makePropertyIntoSentence = R.curry((property, tag) => R.compose( | ||
R.assoc(property, R.__, tag), | ||
get(ensureSentence), | ||
R.prop(property), | ||
)(tag)); | ||
|
||
/** | ||
* Prepares the description of a tag in order for it to be rendered. | ||
* | ||
* @param {CommentTag} tag The tag which description will be formatted. | ||
* @returns {CommentTag} | ||
*/ | ||
const prepareTagDescription = (tag) => R.when( | ||
R.allPass([ | ||
get(hasValidProperty)('description'), | ||
R.complement(get(isTag)(['example', 'examples'])), | ||
]), | ||
R.compose( | ||
R.assoc('description', R.__, tag), | ||
get(ensureSentence), | ||
R.prop('description'), | ||
), | ||
tag, | ||
); | ||
const prepareTagDescription = (tag) => { | ||
const useHasValidProperty = get(hasValidProperty); | ||
const useIsStag = get(isTag); | ||
const useMakePropertyInstoSentence = get(makePropertyIntoSentence); | ||
return R.when( | ||
R.complement(useIsStag(['example', 'examples'])), | ||
R.compose( | ||
R.when( | ||
useHasValidProperty('description'), | ||
useMakePropertyInstoSentence('description'), | ||
), | ||
R.when( | ||
R.allPass([ | ||
useIsStag(get(getTagsWithNameAsDescription)()), | ||
useHasValidProperty('name'), | ||
]), | ||
useMakePropertyInstoSentence('name'), | ||
), | ||
), | ||
tag, | ||
); | ||
}; | ||
|
||
module.exports.prepareTagDescription = prepareTagDescription; | ||
module.exports.provider = provider('prepareTagDescription', module.exports); |
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
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