borkdude / rewrite-edn

Utility lib on top of rewrite-clj with common operations to update EDN while preserving whitespace and comments.
Eclipse Public License 1.0
85 stars 14 forks source link

Maintain alphabetical ordering #18

Open stefan-toubia opened 2 years ago

stefan-toubia commented 2 years ago

It would be very useful to be able to programmatically manage deps.edn files but it's somewhat of a dealbreaker that we cannot currently maintain alphabetical ordering since the config files should remain human readable as well.

borkdude commented 2 years ago

@stefan-toubia I'm open to a PR for this

borkdude commented 1 year ago

I think we can make an explicit sort-map function that takes a map and sorts it, or a more general sort-alphabetical that takes a collection. Clojure-lsp has some logic for it which we could borrow:

https://github.com/clojure-lsp/clojure-lsp/blob/6fc2636affc18254c503f8182d9b0685aec19086/lib/src/clojure_lsp/feature/sort_clauses.clj

borkdude commented 1 year ago

Here is some more info by @lread on the challenges of sorting a map:

https://nextjournal.com/lread/sorting-maps-by-key-with-rewrite-clj

borkdude commented 1 year ago

@lread That code you got there isn't maybe so bad and better than nothing? Maybe I'll just add it and then refine it as we come across issues...

lread commented 1 year ago

It might be an OK start. @mainej has done a lot more thinking on this than I have.