yamlfix icon indicating copy to clipboard operation
yamlfix copied to clipboard

Add a configuration option to make dict entries and simple list elements alphabetically sorted

Open marcules opened this issue 2 years ago • 1 comments

Description

Currently dict entries and sequence / list elements are not sorted. It would be nice to have two configuration options to sort dict entries and list elements alphabetically. This of course does not work with all config files, especially something like kubernetes pod command and args, which need to stay in their original order to make sense, maybe a whitelist/blacklist option for this configuration could be implemented too, so that it is possible to say "in general I want lists ordered, except these" or "in general I don't want lists sorted, except for these lists".

Today:

list:
  - b
  - c
  - a
  - 1
  - null
  - true
  - false

map:
  z: 'key'
  a: 'key'

a: 'key'

After implementing this config option and setting both dict/sequence options to true:

a: 'key'

list:
- null
- true
- false
- 1
- a
- b
- c

map:
  a: 'key'
  z: 'key'

Possible Solution

Additional context

Related Issue

marcules avatar Dec 13 '22 22:12 marcules

Hi @marcules thanks for taking the time to open a new issue. I'd love to have this feature! but again, it won't be on my priority list to be implemented. However if you want to make a PR, I'll be happy to review it

lyz-code avatar Dec 14 '22 08:12 lyz-code