If we find a keep-sorted start or keep-sorted end line that don't have a corresponding keep-sorted end or keep-sorted start line, we recommend that it be deleted. That's certainly one way to solve the problem, but the other way to solve it would be to add the required directive somewhere else in the file.
Internal users have often run afoul of this especially with code templates that want the result to use keep-sorted, but the code template itself is using keep-sorted incorrectly.
The main problem they run into is that running keep-sorted in fix mode eagerly removes these lines without any prompting, which can be pretty frustrating. I think we should have some better behavior here so that the tool is a little less annoying to use
Some ideas:
--mode=fix should not automatically remove unmatched directives. It could instead log a warning
I think it'd still be useful for the findings to recommend the unmatched directives be removed (that way there's an easy fix in our review tool if they do want to remove the line)
I'm questioning whether we want to try and sort anything if there are unmatched directives. There's a pretty good chance we'll construct blocks that are unintended, and sorting would be pretty destructive (maybe just if there are unmatched start directives?). Perhaps we want to only report that there are unmatched directives, and let the user clean that up first before sorting anything
https://github.com/google/keep-sorted/blob/bac77d0c1cffd305d3bc17666616deacfc7fac4c/keepsorted/keep_sorted.go#L143-L154
If we find a
keep-sorted start
orkeep-sorted end
line that don't have a correspondingkeep-sorted end
orkeep-sorted start
line, we recommend that it be deleted. That's certainly one way to solve the problem, but the other way to solve it would be to add the required directive somewhere else in the file.Internal users have often run afoul of this especially with code templates that want the result to use keep-sorted, but the code template itself is using keep-sorted incorrectly.
The main problem they run into is that running keep-sorted in fix mode eagerly removes these lines without any prompting, which can be pretty frustrating. I think we should have some better behavior here so that the tool is a little less annoying to use
Some ideas:
--mode=fix
should not automatically remove unmatched directives. It could instead log a warning