DeadDomainsLinter icon indicating copy to clipboard operation
DeadDomainsLinter copied to clipboard

Consider removing comments that precede the rule

Open ameshkov opened this issue 1 year ago • 4 comments

We should be very careful with comments that are being removed though.

ameshkov avatar Jan 28 '24 22:01 ameshkov

This is also a good question from the point of view of the rule sorter. If we ever write a rule sorter, based on what criteria should we decide whether to move the comment with the rule?

scripthunter7 avatar Jan 30 '24 16:01 scripthunter7

Duplicate of this issue, but with examples: https://github.com/AdguardTeam/DeadDomainsLinter/issues/9

Alex-302 avatar Feb 02 '24 10:02 Alex-302

@ameshkov @Alex-302 I think a possible approach could be to remove any comments that directly precede a rule without empty lines in between. Additionally, we could allow an ignore pattern in the config to specify which comments should not be deleted, even if they directly precede a rule.

So, for example, if we remove the ||example.com^ rule, then from the following input:

! comment1
! comment2
||example.com^

everything should be removed.

However, from this input:

! comment1

! comment2
||example.com^

the ! comment1 should remain because there is an empty line separating it from the rest.

Additionally, we also need to remove leftover preprocessor directives. For example, if an if block contains no remaining rules or only comments, the entire block should be removed. For instance:

!#if (conditions)
! this rule will be removed
||example.com^
!#endif

In this case, the whole block should be deleted.

scripthunter7 avatar Mar 05 '25 10:03 scripthunter7

Another approach could be an inverted logic, where only the patterns specified by the user are removed before a rule.

scripthunter7 avatar Mar 05 '25 10:03 scripthunter7