Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove the lodash dependency #808

Merged
merged 10 commits into from
Nov 29, 2021

Conversation

jaydenseric
Copy link
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.
@@ -164,7 +165,7 @@ export default iterateJsdoc(({

const abbreviationsRegex = abbreviations.length ?
new RegExp('\\b' + abbreviations.map((abbreviation) => {
return _.escapeRegExp(abbreviation.replace(/\.$/ug, '') + '.');
return escapeStringRegexp(abbreviation.replace(/\.$/ug, '') + '.');
Copy link
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
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.

src/jsdocUtils.js Outdated Show resolved Hide resolved
@brettz9
Copy link
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
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
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 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
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
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
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

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
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
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