Skip to content

Commit

Permalink
fix(prettier-plugin-jsdoc): add missing function to validate tags
Browse files Browse the repository at this point in the history
  • Loading branch information
homer0 committed Oct 22, 2020
1 parent 2efd010 commit 8a8bc18
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/fns/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const R = require('ramda');

/**
* @typedef {import('../types').CommentTag} CommentTag
*/

/**
* Ensures a given object is an array.
*
Expand Down Expand Up @@ -38,6 +42,28 @@ const findTagIndex = R.curry((targetTag, propName, step) => {
};
});

/**
* Checks if a tag is of an specified type (or types).
*
* @callback IsTagFn
* @param {string|string[]} targetTag The name of the tag or tags the function should validate
* against.
* @param {CommentTag} tag The tag to validate.
* @returns {boolean}
*/

/**
* @type {IsTagFn}
*/
const isTag = R.curry((targetTag, tag) => {
const targetTags = ensureArray(targetTag);
return R.propSatisfies(
R.includes(R.__, targetTags),
'tag',
tag,
);
});

/**
* Adds an item to a list, only if it wasn't already present.
*
Expand Down Expand Up @@ -186,6 +212,7 @@ const getIndexOrFallback = R.curry((list, fallback, item) => R.compose(

module.exports.ensureArray = ensureArray;
module.exports.findTagIndex = findTagIndex;
module.exports.isTag = isTag;
module.exports.appendIfNotPresent = appendIfNotPresent;
module.exports.joinIfNotEmpty = joinIfNotEmpty;
module.exports.replaceLastItem = replaceLastItem;
Expand Down

0 comments on commit 8a8bc18

Please sign in to comment.