Skip to content

refactor: remove the lodash dependency#808

Merged
brettz9 merged 10 commits intogajus:masterfrom
jaydenseric:jaydenseric/remove-lodash-dependency
Nov 29, 2021
Merged

refactor: remove the lodash dependency#808
brettz9 merged 10 commits intogajus:masterfrom
jaydenseric:jaydenseric/remove-lodash-dependency

Conversation

@jaydenseric
Copy link
Copy Markdown
Contributor

@jaydenseric jaydenseric commented Nov 26, 2021

This significantly reduces the package install size, as lodash has a 1.35 MB install size:

https://packagephobia.com/result?p=lodash@4.17.21

While the current total install size for eslint-plugin-jsdoc is 4.75 MB:

https://packagephobia.com/result?p=eslint-plugin-jsdoc@37.0.3

Also, presumably the native methods (Array.filter, Array.flatMap, Array.some, etc.) perform better than lodash functions.

Some of the more complicated helpers have been refactored to minimal dependencies, most or which were able to be dev dependencies to correctly ensure a minimal production installation for consumers.

This significantly reduces the package install size.
Comment thread src/rules/requireDescription.js
const abbreviationsRegex = abbreviations.length ?
new RegExp('\\b' + abbreviations.map((abbreviation) => {
return _.escapeRegExp(abbreviation.replace(/\.$/ug, '') + '.');
return escapeStringRegexp(abbreviation.replace(/\.$/ug, '') + '.');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe look into if that extra replacing is necessary.

Copy link
Copy Markdown
Contributor Author

@jaydenseric jaydenseric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the earlier seperate comment notifications; I thought I was queueing them for a single comment review but accidentally was spamming them as I went.

Comment thread src/jsdocUtils.js Outdated
@brettz9
Copy link
Copy Markdown
Collaborator

brettz9 commented Nov 26, 2021

Thanks! Looks good. Hope to have energy to review in the next few days... Re: scope creep, I don't mind a few small things--better to get things right, imo.

@brettz9
Copy link
Copy Markdown
Collaborator

brettz9 commented Nov 26, 2021

I pushed a couple minor tweaks and also fixed testing and linting. Could you handle the removal of the remaining lodash import in src/rules/noUndefinedTypes.js?

@brettz9
Copy link
Copy Markdown
Collaborator

brettz9 commented Nov 26, 2021

Actually, I think I've handled that last file all right--maybe just review all of my changes to see if you feel all right to move forward

Comment thread src/rules/requireJsdoc.js
Comment on lines +142 to +150
if (context.options[0] && option in context.options[0] &&
// Todo: boolean shouldn't be returning property, but tests currently require
(typeof context.options[0][option] === 'boolean' ||
key in context.options[0][option])
) {
return context.options[0][option][key];
}

return context.options[0][option][key];
return baseObject.properties[key].default;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware of the context for these changes, but trust it makes sense.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, although it is likely a bug (some issues reported which may suggest it), just using the boolean value of context.options[0][option] when found to be a boolean didn't work either, so would need investigation and a separate PR.

What this fix does is just restore the lodash behavior of avoiding erring when trying in checking on context.options[0][option] (as it will do when it is a boolean).

Copy link
Copy Markdown
Contributor Author

@jaydenseric jaydenseric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the polish, LGTM!

@brettz9 brettz9 force-pushed the jaydenseric/remove-lodash-dependency branch from e9011c6 to aecf6cd Compare November 29, 2021 23:38
@brettz9 brettz9 merged commit 33de9d4 into gajus:master Nov 29, 2021
@jaydenseric jaydenseric deleted the jaydenseric/remove-lodash-dependency branch November 30, 2021 00:42
@Trott
Copy link
Copy Markdown

Trott commented Dec 1, 2021

I'm excited to see this change has landed. Is there any chance that a new release will be published soon? I'm asking because we're waiting for this change to make it into a release over in Node.js core.

@gajus
Copy link
Copy Markdown
Owner

gajus commented Dec 1, 2021

🎉 This PR is included in version 37.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Dec 1, 2021
@brettz9
Copy link
Copy Markdown
Collaborator

brettz9 commented Dec 1, 2021

@Trott : As per the automated release, this is now released in v37.1.0. And thanks for the heads up on its use on the Node.js codebase! Hope it works well for y'all...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants