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

Disabling sort on save

Open WORMSS opened this issue 3 years ago • 5 comments

It was more difficult that it needed to be to disable sorting on save.

I ended up having to manually write in the settings file

{
    "editor.codeActionsOnSave": {
        "source.fixAll.sortJSON": false
    }
}

Was very annoying.. I am not sure when sort on save became a thing, but I had been blaming vscode for messing up my files for ages until my co-workers who also use vscode were reporting no such problems.

WORMSS avatar Aug 18 '21 08:08 WORMSS

^Second that, and thx @WORMSS for sharing the config.

nerdmax avatar Sep 28 '21 03:09 nerdmax

Maybe we can have a config for this extension to control the sort on save behavior?

nerdmax avatar Sep 28 '21 03:09 nerdmax

Just ran into this issue the other day, in a project that has editor.formatOnSave: true in its project-level configuration. VSCode's default for this setting is false.

I understand there's a tradeoff when adding new functionality to an extension:

  • Making X discoverable by enabling it by default and have users opt-out if they so wish
  • Maintaining current behaviour and giving users the oppertunity to opt into X if and when they are ready to do so

(where X is a placeholder for any new feature that does an automatic thing)

Since formatting on save is an intrusive operation, in the sense that it changes your code, I feel it would have been better to stick with opt-in, and play it safe. That is, if a user happened to have editor.formatOnSave: true set. In other words, source.fixAll.sortJSON: false should've been the default, the way I see it.

thany avatar Feb 23 '23 14:02 thany

It seems that "source.fixAll.sortJSON": false no longer works. After some VSC updates, my package.json files keep getting sorted. I even tried setting:

"sortJSON.excludedFiles": [
    "package.json"
  ],

mikestopcontinues avatar Oct 16 '23 12:10 mikestopcontinues

Update: You should now use the following syntax rather than a boolean:

  "editor.codeActionsOnSave": {
    "source.fixAll": "always",
    "source.fixAll.sortJSON": "never"
  },

mikestopcontinues avatar Oct 16 '23 12:10 mikestopcontinues