keep-sorted icon indicating copy to clipboard operation
keep-sorted copied to clipboard

Feature request: option for newline-separated groups

Open drubery opened this issue 4 months ago • 1 comments

I'm using keep-sorted in Chromium to sort some experimental flags by name. This is a little challenging as the flag definitions can span multiple lines (#if for per-platform behavior, parameters associated with a flag, etc.). Right now we're using group_prefixes to apply to everything except empty lines, but it would be nice to have a simpler solution there.

Something simple like group_by_newlines=yes which would take precedence over other grouping rules, accumulating groups until an empty line is encountered, would easily solve this for us.

(Happy to send a PR for this if it would be considered useful)

drubery avatar Sep 05 '25 22:09 drubery

Yeah I think this feature would be pretty useful for toml/INI type files as well (see #102). We also have a similar internal FR that was looking to better support SQL files, and I pitched that perhaps keep-sorted could allow a user-defined delimiter instead of always using \n. SQL files would use ;, and in your case, the delimiter you want is two newlines: \n\n.

I'm happy to review any PRs for this. One thing top of mind that we'll need to be careful with is that git has some pretty terrible newline magic, and we'll need to make sure any solution here continues to work on windows (our tests will run against mac and windows automatically, so we'll have some coverage to detect these before merging)

Here is the code that detects the current line ending for the file being sorted. We end up using that detected newline sequence throughout the code to avoid the crlf issues

JeffFaer avatar Oct 06 '25 18:10 JeffFaer