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

jsonc: Should not allow invalid JSON syntax (trailing commas) #43825

Closed
perlun opened this issue Feb 16, 2018 · 5 comments
Closed

jsonc: Should not allow invalid JSON syntax (trailing commas) #43825

perlun opened this issue Feb 16, 2018 · 5 comments
Assignees
Labels
json JSON support issues

Comments

@perlun
Copy link

perlun commented Feb 16, 2018

  • VSCode Version: Insiders build, 135d4a5
  • OS Version: macOS 10.13.3 (17D47)

Steps to Reproduce:

  1. Open a file with jsonc (JSON with Comments)
  2. Write a trailing comma.

Trailing commas are not valid JSON. However, they are valid JavaScript nowadays.

I had a tsconfig.json that looked like this:

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "module": "es6",
    "moduleResolution": "node",
    "noEmit": true,
    "noEmitOnError": false,
    "noImplicitAny": true,
    "noImplicitReturns":true,
    "noImplicitThis": true,
    "paths": {
      "notime/tests/*": ["tests/*"],
      "notime/*": [
        "app/*"
      ]
    },
    "sourceMap": true,
    "target": "es2017", // <- here is the error
  },
  "exclude": [
    "tmp",
    "dist",
    "node_modules",
    "bower_components"
  ]
}

When using the regular JSON mode, the syntax checking correctly errors about the trailing comma. However, when using jsonc mode, it does not which is a bit sad because it made me start debugging other things, stepping through the node extension I was using etc. instead of looking carefully at the file. I assumed the file was good since it "looked good" in vscode.

I believe jsonc should generate errors for files like the above. Only comments should be allowed, but not other "invalid JSON" syntax. Are there particularly good reasons for the current behavior?

@vscodebot vscodebot bot added the json JSON support issues label Feb 16, 2018
@perlun
Copy link
Author

perlun commented Feb 16, 2018

@vscodebot Thanks, but these do not cover my particular issue.

@microsoft microsoft deleted a comment from vscodebot bot Feb 16, 2018
@aeschli
Copy link
Contributor

aeschli commented Feb 16, 2018

jsonc is intended to be the format of VSCode's settings files and we've gotten many requests to be tolerant on trailing semicolons.

@aeschli
Copy link
Contributor

aeschli commented Feb 16, 2018

Maybe file a issue against TypeScript to also ignore trailing commas. Wouldn't that be a better solution?

@usernamehw
Copy link
Contributor

Not 100% sure, but I think typescript 2.4+ ignores trailing commas in tsconfig.json.

@perlun
Copy link
Author

perlun commented Feb 17, 2018

The issue wasn't actually with the TypeScript compiler per se, but with ember-cli-typescript 1.0.6 which failed to parse the JSON because of this (it manually parses the file with a JSON-strict parser.)

Upgrading ember-cli-typescript to 1.1.3 solved this issue; it has obviously been changed in this regard. I'll close this issue now, since as you mention, other people have wanted the format to be tolerant on trailing commas. Thanks for your time! 👍

@perlun perlun closed this as completed Feb 17, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Apr 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
json JSON support issues
Projects
None yet
Development

No branches or pull requests

3 participants