Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to sort keys alphabetically and preserve comments #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cristicalin
Copy link

@cristicalin cristicalin commented Jul 21, 2022

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

@kaessert
Copy link

We really need this 🙏

@cristicalin cristicalin force-pushed the add_key_sorting branch 3 times, most recently from ede2a21 to 9da50f4 Compare July 22, 2022 14:13
This has the ability to preserve comments.

Added CI coverage for the sorting feature.
@cristicalin cristicalin changed the title add ability to sort keys alphabetically and preserve comments Adds ability to sort keys alphabetically and preserve comments Jul 22, 2022
@cristicalin
Copy link
Author

/cc @jumanjiman

@whophil
Copy link

whophil commented Dec 22, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement dictionary key sorting
3 participants