yaml-sort icon indicating copy to clipboard operation
yaml-sort copied to clipboard

feat: Support excluding lines

Open nkakouros opened this issue 5 months ago • 1 comments

In many yaml-based applications, like Ansible, Github workflows, etc, there are keys like name that make sense to be on top of the rest of the keys in a dict. It would be nice to supply a list of key names and/or an ignore-comment so that these lines are left at the same position after sorting keys. For example:

# Original
version: 1
name: test  # yaml-sort:no-sort
z: 3
a: 1

# Sorted (excluding "name")
a: 1
name: test
version: 1
z: 3

or instead of the no-sort, it could be run as:

yaml-sort --ignore name,some-other

Support for a file-level ignore comment would be nice too so that you can pass all yaml files in your codebase to yaml-sort and have it ignore those with e.g. # yaml-sort:no-sort-file somewhere in them (e.g. at the top).

nkakouros avatar Aug 14 '25 11:08 nkakouros

Like #28 ?

I can't sort keys and leave some in place. I can only customize the key comparison function.

ddebin avatar Aug 30 '25 14:08 ddebin