Vscode: Trailing comma in default settings.json when using split JSON editor causes warning that can't be removed.

Created on 5 Sep 2019  路  11Comments  路  Source: microsoft/vscode


  • VSCode Version: 1.38.0
  • OS Version: Windows 10 1803

Steps to Reproduce:

  1. Change your user settings to have workbench.settings.editor = "json" & workbench.settings.useSplitJSON = true
  2. Re-launch VSCode with extensions disabled
  3. Open settings editor
  4. Problems pane will show a trailing comma warning.
  5. (optional) click on the warning to open the file ("/0/settings.json")
  6. Close the editor (and file if done step 5), warning remains in problems pane.


Does this issue occur when all extensions are disabled?: Yes

Only noticed this appear as of 1.38.0.
Copied problem data:

{
    "resource": "/0/settings.json",
    "owner": "_generated_diagnostic_collection_name_#0",
    "code": "519",
    "severity": 4,
    "message": "Trailing comma",
    "source": "jsonc",
    "startLineNumber": 2436,
    "startColumn": 1,
    "endLineNumber": 2436,
    "endColumn": 2
}

On an additional note, it says the source is jsonc language, but I thought jsonc allowed trailing commas?

bug config verified

Most helpful comment

There are several file formats out there that allow comments in JSON but not trailing commas.
(e.g. tslint.json, eslint.json)
So I made a change so that by default jsonc no longer accepts trailing commas.
Trailing commas are only ignored for jsonc files if they have a schema associated that specifies that trailing commas are allowed.

That's done with a property in the schema root: allowTrailingCommas: true

(note that I just changed from allowsTrailingCommas to allowTrailingCommas, please only use allowTrailingCommas)

I added that to the schemas of our settings files. Note that the schemas of our settings files are dynamically generated, so it's all in code

It looks like the error is coming from the default settings 'editor', which has no schema associated.
@sandy081 Can you associate a schema there, or just generate code without trailing comma?

I'll make a fix for tsconfig.json

All 11 comments

I have the same problem.

Same here on Mac. I also have prettier as the default formatter:

"[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },

Turning it off doesn't help though.

My tsconfig.json files recently started showing errors when there is a trailing comma in them. TSC allows trailing commas and I would rather not remove them as it makes editing easier. What changed that is causing jsonc checker to start erroring on trailing comma? How can I go back to the old behavior?

Same issue here. Happened after I updated to 1.38, and edited user setting.

I'm also using split json config:

  "workbench.settings.editor": "json",
  "workbench.settings.useSplitJSON": true,

and using prettier as the default formatter

this is happening to me -- every time i open or close the settings.json split viewer, a new problem is created.

Same here.

@aeschli Is this new with jsonc that showing a warning with trailing comma?

["a",]

There are several file formats out there that allow comments in JSON but not trailing commas.
(e.g. tslint.json, eslint.json)
So I made a change so that by default jsonc no longer accepts trailing commas.
Trailing commas are only ignored for jsonc files if they have a schema associated that specifies that trailing commas are allowed.

That's done with a property in the schema root: allowTrailingCommas: true

(note that I just changed from allowsTrailingCommas to allowTrailingCommas, please only use allowTrailingCommas)

I added that to the schemas of our settings files. Note that the schemas of our settings files are dynamically generated, so it's all in code

It looks like the error is coming from the default settings 'editor', which has no schema associated.
@sandy081 Can you associate a schema there, or just generate code without trailing comma?

I'll make a fix for tsconfig.json

Thanks @aeschli, I can see if I can avoid trailing comma.

So this is closed as in fixed? I just got referred here after opening #81920. Is the fix in the nightly build?

Yes, in the insiders ('nightly') build.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

trstringer picture trstringer  路  3Comments

villiv picture villiv  路  3Comments

DovydasNavickas picture DovydasNavickas  路  3Comments

philipgiuliani picture philipgiuliani  路  3Comments

mrkiley picture mrkiley  路  3Comments