Skip to content

Commit

Permalink
fix(prettier-plugin-jsdoc): remove ifElse
Browse files Browse the repository at this point in the history
Using formatStringLiterals with a R.ifElse meant that the getReducer function was being executed
every time, no matter if there were no string literals on the type.
The alternative could've been using R.curry with getReducer, but that would make the parsing of
the options and the composition for the formatter to happen on each iteration.

I prefer using a non Ramda function and parsing the options and creating the formatter only
once per type.
  • Loading branch information
homer0 committed Oct 3, 2020
1 parent a692445 commit 404061d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/fns/formatStringLiterals.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ const extractLiterals = R.match(/['"][\w\|\-\s'"]+['"](?:\s+)?/g);
* @returns {string}
*/
const formatStringLiterals = (type, options) => R.compose(
R.ifElse(
R.prop('length'),
R.reduce(getReducer(options), type),
R.always(type),
(literals) => (
literals.length ?
R.reduce(getReducer(options), type, literals) :
type
),
extractLiterals,
)(type);
Expand Down
5 changes: 1 addition & 4 deletions test/fns/formatStringLiterals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ describe('formatStringLiterals', () => {
const output = 'string';
let result = null;
// When
result = formatStringLiterals(input, {
jsdocUseSingleQuotesForStringLiterals: true,
jsdocSpacesBetweenStringLiterals: 0,
});
result = formatStringLiterals(input);
// Then
expect(result).toBe(output);
});
Expand Down

0 comments on commit 404061d

Please sign in to comment.