pre-commit-hook-yamlfmt icon indicating copy to clipboard operation
pre-commit-hook-yamlfmt copied to clipboard

Adds ability to sort keys alphabetically and preserve comments

Open cristicalin opened this issue 2 years ago • 3 comments

This PR adds the ability to sort yaml keys (-k/--sort_keys command line) while retaining some comments. A CI test is also added illustrating the retention of comments.

When keys need to be moved around, some comments may be mistakenly left in their place, for example see https://stackoverflow.com/questions/53849036/how-to-keep-comments-in-ruamel which explains why the comments may be dissociated.

Fixes: #40

cristicalin avatar Jul 21 '22 13:07 cristicalin

We really need this :pray:

kaessert avatar Jul 21 '22 13:07 kaessert

/cc @jumanjiman

cristicalin avatar Jul 22 '22 14:07 cristicalin

I'm also interested in this feature! Not sure if the author is accepting PRs at the moment.

@cristicalin one thought on a trivial addition - I'd be interested in a "top keys" option, which allows certain keys to retain priority during sort. Happy to contribute this if you're still working on this feature.

whophil avatar Dec 22 '23 15:12 whophil