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

Custom sort recursively does not work with sort arrays. #136

Open
huxuan opened this issue Jun 8, 2023 · 2 comments
Open

Custom sort recursively does not work with sort arrays. #136

huxuan opened this issue Jun 8, 2023 · 2 comments
Labels
feature New feature or request

Comments

@huxuan
Copy link

huxuan commented Jun 8, 2023

When enable both Use Custom Sort Recursively and Sort Arrays, it is supposed to apply custom sort arrays but actually not.

For example:

python_version:
  - '3.8'
  - '3.9'
  - '3.10'
  - '3.11'

When enable both Use Custom Sort Recursively and Sort Arrays, with effective custom sort keys:

"vscode-yaml-sort.customSortKeywords_2": [
    "3.8",
    "3.9",
    "3.10",
    "3.11"
]

it will be formatted as following instead which is supposed to keep the original order.

python_version:
  - '3.10'
  - '3.11'
  - '3.8'
  - '3.9'

BTW, objects work as expected.

@pascalre
Copy link
Owner

Hello @huxuan , the customSortKeywords does only apply for keywords and not for list items. I will keep this issue open, for a feature to custom sort lists.

@pascalre pascalre added the feature New feature or request label Aug 17, 2023
@Ghostbird
Copy link

Ghostbird commented Dec 24, 2024

Tangentially related. I was trying to sort some infrastructure-as-code YAML with a custom sort definition that started with name. It would have been really nice if the array sort had sorted my list of services by values the sorted keys. However, I think that in many situations that would make no sense at all, so I don't know exactly how to define a good sort order.

Example

services:
  - name: foo
    type: api
  - name: bar
    type: worker

When my custom sort definition is name or name, type, I'd like this to be sorted as:

services:
  - name: bar
    type: worker
  - name: foo
    type: api

When my custom sort definition is type or type, name, I'd like this to be sorted as:

services:
  - type: api
    name: foo
  - type: worker
    name: bar

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

No branches or pull requests

3 participants