I am using Visual Studio Code for my front end development. I have enabled the sort-keys
rule which requires the keys of all object to be in alphabetical order.
I came to find out that neither ESLint, nor Prettier supports autofixing it, due to potential bugs the auto-fix can introduce, thus both of them has rejected the proposal to even consider adding auto-fix as option.
Now I have a very large legacy code base where I just added ESLint, and I need this sort-keys rule in the project. Is there any way I can auto-fix them provided I know what am I doing, possibly through some VSCode plugin or a custom script?
I am sure that changing the order of the keys will not affect my code negatively. I need it for both JSON objects as well as JS object literals.
Not exactly an automated solution but it helps with sorting object keys manually during development.
Sort JS object keys VS Code plugin
{
and }
. Hint: expand selection keyboard shortcut ⌃⇧⌘→ is helpful for this.