devbox icon indicating copy to clipboard operation
devbox copied to clipboard

Support `devbox.jsonc` for better editor & diff highlighting

Open gjoseph92 opened this issue 8 months ago • 5 comments

What problem are you trying to solve?

devbox.json supports comments, which is quite helpful. By default though, IDEs and GitHub diffs don't expect .json files to have comments, and highlight them as errors.

What solution would you like?

If devbox supported searching for devbox.jsonc files as well as .json, I could just name them accurately and most syntax highlighters would just work.

Alternatives you've considered

In VSCode, I've added this to my settings.json, which at least helps in the IDE:

    "files.associations": {
      "devbox.json": "jsonc"
    }

However, even with devbox.json linguist-language=JSON-with-Comments in .gitattributes, I can't get GitHub diffs to not highlight comments in red in diffs of the devbox.json, which makes PR review annoying.

gjoseph92 avatar Apr 28 '25 19:04 gjoseph92

Yes, this would be one less rough spot for new users. I'd also vote for just using YAML.

glennpratt avatar Apr 29 '25 17:04 glennpratt

I think YAML would be great for another reason: YAML has powerful multi-line strings that I think are really nice when writing shell scripts. Coming from writing shells scripts in YAML for GitLab CI, it feels a bit painful to write scripts in devbox.json. I do appreciate that Devbox uses an array of strings for each script, that already makes it a lot nicer than a single string.

drewgingerich avatar May 01 '25 22:05 drewgingerich

Yeah, so I have had this concern for a while, too. Here's a workaround that GitHub likes. I have yet to test this locally with the devbox CLI, but I'll report back when I do.

TLDR: The JSONC Spec says that you give it a JSONC file a .json file extension can if you put this comment at the first line:

// -*- mode: jsonc -*-

https://gist.github.com/CourteousCoder/450e23de1792350efe570868f7a1193d#file-jsonc-modespec-plain-json-extension-devbox-json-L1

See if that works for you in VSCode @gjoseph92

CourteousCoder avatar May 31 '25 09:05 CourteousCoder

Related to https://github.com/jetify-com/devbox/issues/1464#issuecomment-1714171955 & https://github.com/jetify-com/devbox/issues/2169

pinage404 avatar May 31 '25 10:05 pinage404

[...] I have yet to test this locally with the devbox CLI, but I'll report back when I do.

Seems that devbox has no problem with it.

Here's how I did it:

  1. Include the mode: jsonc directive at the top of devbox.json (that's enough for github diffs)
  2. If needed, configure your IDE jsonc parser to look for *.json files. Or configure its json parser to suppress errors/warnings about comments.
  3. If required, configure it to ignore errors/warnings about trailing commas at the last element of an array.

It worked for me in all the JetBrains IDEs I use, and in neovim, and I am sure vscode has those configuration options too. In any case, adding that comment to the first line of devbox.json was enough to make GitHub happy

CourteousCoder avatar Jun 01 '25 21:06 CourteousCoder