Skip to content

Commit

Permalink
fix(prettier-plugin-jsdoc): only add period when is not URL and ends …
Browse files Browse the repository at this point in the history
…with a letter
  • Loading branch information
homer0 committed Mar 21, 2021
1 parent fb2835f commit d97d458
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
8 changes: 2 additions & 6 deletions src/fns/prepareTagDescription.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const R = require('ramda');
const { ensureSentence, hasValidProperty, isTag, isURL } = require('./utils');
const { ensureSentence, hasValidProperty, isTag } = require('./utils');
const { getTagsWithNameAsDescription } = require('./constants');
const { get, provider } = require('./app');

Expand All @@ -20,11 +20,7 @@ const { get, provider } = require('./app');
* @type {MakePropertyIntoSentenceFn}
*/
const makePropertyIntoSentence = R.curry((property, tag) =>
R.compose(
R.assoc(property, R.__, tag),
R.when(R.complement(get(isURL)), get(ensureSentence)),
R.prop(property),
)(tag),
R.compose(R.assoc(property, R.__, tag), get(ensureSentence), R.prop(property))(tag),
);

/**
Expand Down
43 changes: 24 additions & 19 deletions src/fns/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,18 @@ const getIndexOrFallback = R.curry((list, fallback, item) =>
* Formats a list in order to remove items repeated items next to each other.
*
* @callback LimitAdjacentRepetitionsFn
* @example
*
* limitAdjacentRepetitions(R.equals('\n'), 1, ['hello', '\n', '\n', 'world']);
* // ['hello', '\n', 'world']
*
* @param {LimitAdjacentRepetitionsPredFn} pred The function to validate if an item
* should be considered and start the
* count.
* @param {number} limit How many times an item that was
* validated with predicate function can be
* adjacently repeated.
* @param {Array} list The list to format.
* @example
*
* limitAdjacentRepetitions(R.equals('\n'), 1, ['hello', '\n', '\n', 'world']);
* // ['hello', '\n', 'world']
*
*/

/**
Expand Down Expand Up @@ -313,20 +313,6 @@ const splitLinesAndClean = R.curry((splitter, text) =>
R.compose(R.reject(R.isEmpty), R.map(R.trim), R.split(splitter))(text),
);

/**
* Ensures a text starts with an uppercase and ends with a period.
*
* @param {string} text The text to format.
* @returns {string}
*/
const ensureSentence = (text) =>
R.compose(
R.replace(/(\.)?(\s*)$/, (full, dot, padding) => `.${padding}`),
R.replace(
/^(\s*)(\w)/,
(full, padding, letter) => `${padding}${letter.toUpperCase()}`,
),
)(text);
/**
* Validates if a text is a valid URL.
*
Expand All @@ -339,6 +325,25 @@ const isURL = (text) =>
text,
);

/**
* Ensures a text starts with an uppercase and ends with a period.
*
* @param {string} text The text to format.
* @returns {string}
*/
const ensureSentence = (text) =>
R.when(
R.allPass([R.complement(get(isURL)), R.match(/\w\s*$/)]),
R.compose(
R.replace(/(\.)?(\s*)$/, (full, dot, padding) => `.${padding}`),
R.replace(
/^(\s*)(\w)/,
(full, padding, letter) => `${padding}${letter.toUpperCase()}`,
),
),
text,
);

module.exports.ensureArray = ensureArray;
module.exports.findTagIndex = findTagIndex;
module.exports.isTag = isTag;
Expand Down

0 comments on commit d97d458

Please sign in to comment.