Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Drop lodash #89

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

Open
SukkaW wants to merge 1 commit into AdguardTeam:master
base: master
Choose a base branch
Loading
from SukkaW:drop-lodash
Open

Drop lodash #89

SukkaW wants to merge 1 commit into AdguardTeam:master from SukkaW:drop-lodash

Conversation

Copy link

@SukkaW SukkaW commented Jun 20, 2025
edited
Loading

Drop lodash from HostslistCompiler.

(削除) WIP: some unit tests are failing, still figuring out why. (削除ここまで) All fixed.

@SukkaW SukkaW force-pushed the drop-lodash branch 2 times, most recently from 9f23922 to 033e75c Compare June 20, 2025 12:18
@SukkaW SukkaW marked this pull request as ready for review June 20, 2025 12:19
@SukkaW SukkaW changed the title (削除) WIP: Remove lodash (削除ここまで) (追記) Drop lodash (追記ここまで) Jun 20, 2025
Copy link

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

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

Other comments (4)
  • src/transformations/compress.js (73-73) The change from `_.isEmpty(props.options)` to `props.options.length === 0` assumes that `props.options` is always an array. If `props.options` could be undefined, null, or an object in some cases, this change might introduce bugs. Consider adding a check to ensure `props.options` is an array or has a length property before accessing it.
  • src/transformations/validate.js (91-91) The replacement of `_.isEmpty(props.hostnames)` with `!props.hostnames?.length` is close but not exactly equivalent. While it handles null/undefined cases correctly with the optional chaining, an empty array would evaluate to `length === 0` which is falsy. However, if you want to be more explicit, you could use `!props.hostnames || props.hostnames.length === 0`.
  • src/index.js (57-57) For consistency with the other property checks, consider using optional chaining here as well:
    if (source.name?.length > 0) {
    
  • src/index.js (57-57) For consistency with how other properties are checked, consider simplifying this to match the pattern used elsewhere:
    if (source.name?.length) {
    

💡 To request another review, post a new comment with "/windsurf-review".

if (_.startsWith(toTest,'://')) {
toTest = _.trimStart(toTest,'://');
if (toTest.startsWith('://')) {
toTest = toTest.replace('://','');
Copy link

@windsurf-bot windsurf-bot bot Jun 20, 2025

Choose a reason for hiding this comment

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

The replacement of _.trimStart(toTest, '://') with toTest.replace('://', '') might not be equivalent in all cases. trimStart removes all leading occurrences of the specified characters, while replace only replaces the first occurrence. Consider using toTest.substring(3) instead for a more direct replacement.

Copy link
Author

@SukkaW SukkaW Jun 20, 2025
edited
Loading

Choose a reason for hiding this comment

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

This is equivalent. We already know that :// is always at the start (that's what .startsWith(://) for). So, it will always replace the leading one.

Also, unlike .slice(3), .replace() prevents string CoW inside Node.js v8, which helps release memory pressure by allowing old strings to be GCed from the memory (.slice() holds the reference of the original string, preventing that from being GCed).

for (let i = filtered.length - 1; i >= 0; i -= 1) {
const isValidRule = valid(filtered[i], this.allowedIP);
const isCommentOrEmptyLine = ruleUtils.isComment(filtered[i]) || _.isEmpty(filtered[i]);
const isCommentOrEmptyLine = ruleUtils.isComment(filtered[i]) || filtered[i].length===0;
Copy link

@windsurf-bot windsurf-bot bot Jun 20, 2025

Choose a reason for hiding this comment

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

The replacement of _.isEmpty(filtered[i]) with filtered[i].length === 0 might not handle undefined or null values correctly. Consider using !filtered[i] || filtered[i].length === 0 to maintain the same behavior as lodash's isEmpty.

Copy link
Author

Choose a reason for hiding this comment

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

This is not necessary. We already know that the filtered is string[], so filtered[i] will never be nullish.

*/
function valid(ruleText, allowedIP) {
if (ruleUtils.isComment(ruleText) || _.isEmpty(_.trim(ruleText))) {
if (ruleUtils.isComment(ruleText) || ruleText.trim().length===0) {
Copy link

@windsurf-bot windsurf-bot bot Jun 20, 2025

Choose a reason for hiding this comment

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

The replacement of _.isEmpty(_.trim(ruleText)) with ruleText.trim().length === 0 might throw an error if ruleText is undefined or null. Consider using a null check: !ruleText || ruleText.trim().length === 0.

Copy link
Author

Choose a reason for hiding this comment

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

We already know that ruleText is a string and will never be falsy.

Copy link
Author

SukkaW commented Oct 9, 2025

cc @jellizaveta

Would you like to review this?

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

Reviewers

@windsurf-bot windsurf-bot[bot] windsurf-bot[bot] left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /