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

[Feature request] Optimization steps #12

Open
ammnt opened this issue Apr 20, 2021 · 5 comments
Open

[Feature request] Optimization steps #12

ammnt opened this issue Apr 20, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@ammnt
Copy link

ammnt commented Apr 20, 2021

Hello,

please, consider about implement these optimization steps:

  • remove empty lines;
  • remove leading and trailing spaces;
  • sort alphabetically;
  • remove ||www.example.com rules or replacing them to ||example.com^;

Thank you.
Cheers☺️

@ameshkov ameshkov added the enhancement New feature or request label Apr 20, 2021
@ammnt
Copy link
Author

ammnt commented Apr 27, 2021

  • Convert list to lower case;
  • sort by TLD.

@scripthunter7
Copy link
Member

scripthunter7 commented Jun 2, 2022

Empty lines and trim are done: #33

@ameshkov In your opinion what is the correct sorting strategy if a rule has one or more comments? For example:

Input:

! Random comment 1, since it is followed by an empty line, it does not belong to any of the rules

b.com
! Comment for a.com
a.com

! Random comment 2, since it is followed by an empty line, it does not belong to any of the rules

d.com
c.com

Possible output:

! Random comment, since it is followed by an empty line, it does not belong to any of the rules

! Comment for a.com
a.com
b.com

! Random comment 2, since it is followed by an empty line, it does not belong to any of the rules

c.com
d.com

I've done something similar before, here's the link:
https://github.com/hufilter/hufilter-dev/tree/master/assets/scripts/orderer

@ameshkov
Copy link
Member

ameshkov commented Jun 3, 2022

@scripthunter7 Hmm, that's a good question.

Your approach seems very reasonable to me.

@scripthunter7
Copy link
Member

@ameshkov As my free time allows, I'd like to further develop the linked script and convert it to an NPM package. After I'm done with it, the package can be easily integrated to Hostlist Compiler as a transformation such as SortRulesDesc / SortRulesAsc / SortRules or anything else.

It is not closely related to this topic, but I will describe what I mean by further development. The rules could be grouped according to their type, then the rules within that group can then be sorted again. For example:

domain3.org##.selector3
domain2.org##.selector2
#.selector5
#.selector4
domain1.org##.selector1

! Comment
#.selector7

to:

#.selector4
#.selector5
! Comment
#.selector7
domain1.org##.selector1
domain2.org##.selector2
domain3.org##.selector3

The configuration for this sorting script can be something like this:

{
    "groupOrder": [
        "general_hide",
        "specific_hide",
        etc.
    ]
}

It is similar to the current script anyway, but it does not automatically detect groups yet.

However, it is also necessary to clarify key issues such as the proper handling of comments (headers / sections / conditions etc).

@ameshkov
Copy link
Member

However, it is also necessary to clarify key issues such as the proper handling of comments (headers / sections / conditions etc).

Yeah, pre-compiler directives should retain the order and work like a comment with a following empty line.

Also, there are hints that should be also considered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants