Support `devbox.jsonc` for better editor & diff highlighting
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.
Yes, this would be one less rough spot for new users. I'd also vote for just using YAML.
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.
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
Related to https://github.com/jetify-com/devbox/issues/1464#issuecomment-1714171955 & https://github.com/jetify-com/devbox/issues/2169
[...] 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:
- Include the
mode: jsoncdirective at the top ofdevbox.json(that's enough for github diffs) - If needed, configure your IDE jsonc parser to look for
*.jsonfiles. Or configure its json parser to suppress errors/warnings about comments. - 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