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

Add option to keep quotes

Open Joris29 opened this issue 1 year ago • 9 comments

Could you add an option to just keep quotes as they are when sorting.

Example. parent_key: 'Pkey2 with space': k1: v1 k2: 'v2' 'Pkey1 with space': k1: 'v1' k2: v2

Would become: parent_key: Pkey1 with space: k1: v1 k2: v2 Pkey2 with space: k1: v1 k2: v2

What it should be if original quotes are ignored: parent_key: 'Pkey1 with space': k1: v1 k2: 'v2' 'Pkey2 with space': k1: 'v1' k2: v2

Joris29 avatar Mar 19 '24 12:03 Joris29

@pascalre ?

Joris29 avatar May 30 '24 10:05 Joris29

Yeah, I agree this is my only annoyance. This breaks my Ansible playbooks since some values need to be quoted, for example when you have a leading "{{".

paulcalabro avatar Jun 27 '24 14:06 paulcalabro

@pascalre Is this project dead because you don't seem to react to issues?

Joris29 avatar Jul 19 '24 17:07 Joris29

Hello @Joris29, this project is not dead. But my time is limited. Feel free to contribute with a PR.

pascalre avatar Jul 19 '24 18:07 pascalre

@pascalre Alright understandable I will try to do an attempt to create a PR for it but i have no knowledge of typescript but I guess I can learn it pretty fast

Joris29 avatar Jul 19 '24 19:07 Joris29

This is a reoccurrence of https://github.com/pascalre/vscode-yaml-sort/issues/142 which is partially resolved it's strange behaviour with quoting.

Using just single quotes or double quotes will change to nothing. Using double quotes inside single quotes like this ' "this is a text" ' will remain as it should. Using single quotes inside double quotes like this " 'this is a text' " will return three single quotes on each side

Very strange quoting behaviour but i will try to fix it

Joris29 avatar Jul 19 '24 20:07 Joris29

After doing some further research there is also another vscode extension for yaml validation which support sorting https://github.com/redhat-developer/yaml-language-server

@paulcalabro If you don't use the custom sorts it might be better to use that one for now. As the code is quite complex for me and it might take a while to have a working solution.

Joris29 avatar Jul 20 '24 22:07 Joris29

Seems like a lot of refactoring because the used library doesn't support it: https://github.com/nodeca/js-yaml/issues/711#issuecomment-1700532593

Joris29 avatar Jul 21 '24 14:07 Joris29

Thanks @Joris29 !

paulcalabro avatar Aug 18 '24 10:08 paulcalabro