Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tolerate trailing commas in jsonc format #102061

Closed
alexreg opened this issue Jul 10, 2020 · 5 comments
Closed

Tolerate trailing commas in jsonc format #102061

alexreg opened this issue Jul 10, 2020 · 5 comments
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@alexreg
Copy link

alexreg commented Jul 10, 2020

Would it be possible to add tolerance for trailing commas to the jsonc (JSON With Comments) format? Even as an optional setting that is off by default. While I can understand not adding support to the json (spec-compliant) format, there doesn't seem to be a good reason not to add it (either on automatically or configurable) to jsonc.

In case there's any doubt over what I mean, here's an example.

{
    "foo": 123,
    "bar": [
        "abc",
        "def",
        "ghi", // trailing comma: okay!
    ], // trailing comma: okay!
}
@aeschli
Copy link
Contributor

aeschli commented Jul 10, 2020

We had that, but changed it back to warn about commas. See #43825

JSONC is not a standard, but there are several tools that use JSON with comment such as eslint and tsconfig.
However, some of fhem don't accept the trailing commas. The editor would not complain and users would only find out at runtime that there's a trailing comma.
After multiple complaints we changed the default to warn.

However, in our VSCode settings files, trailing commas are accepted. This knowledge comes in through the JSON schema of the settings files. If the schema says "allowTrailingCommas": true, then it's not warned.

I want to leave this as is is now. Do you have a schema for your file?

@aeschli aeschli added the info-needed Issue requires more information from poster label Jul 10, 2020
@alexreg
Copy link
Author

alexreg commented Jul 10, 2020

Ah, I see, thanks for explaining. I think you're right... many "jsonc" parsers accept trailing commas, while many don't. The Python one that I'm using happily does (and indeed I chose it partly for that reason).

Indeed, I was the one (as far as I'm aware) who requested the allowTrailingCommas feature for settings files, and that's great. :-)

No, I don't have a JSON schema. Maybe a setting like allowTrailingCommas could be added to the [json] language section in VS Code settings? Ideally this would be configurable on a per-directory or even per-file basis, but I suppose that comes down to how VS Code workspace settings work in general. Perhaps support for that has recently been added?

@aeschli
Copy link
Contributor

aeschli commented Jul 11, 2020

We don't have folder/file based settings. I think there's a feature request.
But adding a schema is easy. It can also be done in the user settings:

	"json.schemas": [{
		"fileMatch": ["foo.jsonc"],
		"schema": {
			"allowTrailingCommas": true
		}
	}]

@alexreg
Copy link
Author

alexreg commented Jul 11, 2020

Oh, I thought you meant JSON Schema. That's great, thank you.

@aeschli
Copy link
Contributor

aeschli commented Jul 13, 2020

"schema" is for user defined JSON schemas. allowTrailingCommas is just a (internal) VSCode extension of JSON schema.

@alexreg alexreg closed this as completed Jul 15, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Aug 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants