leoafarias / fvm

Flutter Version Management: A simple CLI to manage Flutter SDK versions.
https://fvm.app
MIT License
4.71k stars 230 forks source link

[BUG] `fvm use` makes unrelated changes to settings.json. #635

Open bkleineibst opened 9 months ago

bkleineibst commented 9 months ago

Before creating a bug report please make check the following

Describe the bug When running fvm use, the settings.json file is update to set the new version to use. However, comments are removed from the file and tabs are changed to spaces.

To Reproduce Steps to reproduce the behavior:

  1. Add comments to settings.json.
  2. Set it to save tabs, not spaces.
  3. Run fvm use stable
  4. Comments will be removed and tabs will be changed to spaces.

Expected behavior Only the version number should be changed. Tab/space indentation should match rest of file.

leoafarias commented 9 months ago

@bkleineibst I might look into adjusting this at a later time, but for now you can disable the manage VsCode settings by adding updateVscodeSettings to false on the .fvmrc

bkleineibst commented 9 months ago

Thanks @leoafarias

jibbers42 commented 9 months ago

Regarding https://github.com/leoafarias/fvm/issues/642#issuecomment-1959787353:

Comments are not part of the JSON specification. Therefore, it will not be supported.

It's worth mentioning that vscode does support comments in their settings files by using jsonc under the hood https://code.visualstudio.com/docs/languages/json#_json-with-comments:

VS Code also has a JSON with Comments (jsonc) mode. This mode is used for the VS Code configuration files such as settings.json, tasks.json, or launch.json

leoafarias commented 9 months ago

Thanks @jibbers42 I did not find any existing dart package that supports not only reading but also writing back of json with comments, so will have to do further research on this later.

But for anyone else having this issue here is a workaround

Comments are not part of the JSON specification. Therefore, are not supported. However, if you choose to comment, I suggest doing the following:

{
    "_comment": "This is the basic data",
    "key": "value"
}

This would allow valid comments with json