richie5um / vscode-sort-json

VSCode Extension to Sort JSON objects
https://marketplace.visualstudio.com/items?itemName=richie5um2.vscode-sort-json
MIT License
110 stars 19 forks source link

Disabling sort on save #56

Open WORMSS opened 3 years ago

WORMSS commented 3 years ago

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.

nerdmax commented 3 years ago

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

nerdmax commented 3 years ago

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

thany commented 1 year ago

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:

(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.

mikestopcontinues commented 1 year ago

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 commented 1 year ago

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

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