Consider removing comments that precede the rule
We should be very careful with comments that are being removed though.
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?
Duplicate of this issue, but with examples: https://github.com/AdguardTeam/DeadDomainsLinter/issues/9
@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.
Another approach could be an inverted logic, where only the patterns specified by the user are removed before a rule.