biomejs/biome-vscode

๐Ÿ› Trailing comma on `*.jsonc` warns with correct rules

Closed this issue ยท 2 comments

VS Code version

1.86.0

Extension version

v2024.3.70509

Biome version

1.7.3

Operating system

  • Windows
  • macOS
  • Linux

Description

When using jsonc as the format for any *.jsonc file with the appropriate rules (below), the linter still warns about trailing commas.

I did try with a bare minimal reproduction repo and the error persists.

image

Steps to reproduce

  • Initialize a minimal reproduction repository (with bun for example):
    mkdir biome-test
    cd biome-test
    bun init .
  • add and initialize biome
    bun add --dev --exact @biomejs/biome
    bunx @biomejs/biome init --jsonc
  • add the rules for allowing trailing commas to biome.jsonc
    {
    	"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
    	"organizeImports": {
    		"enabled": true,
    	},
    	"linter": {
    		"enabled": true,
    		"rules": {
    			"recommended": true,
    		},
    	},
    	"json": {
    		"formatter": {
    			"trailingCommas": "all",
    		},
    		"parser": {
    			"allowTrailingCommas": true,
    		},
    	},
    }
  • format the document so it adds the trailing commas
    bunx @biomejs/biome format --write biome.jsonc
  • at this point vscode will be warning about trailing commas on the Problems view
  • note that running lint via biome won't warn
    bunx @biomejs/biome lint biome.jsonc

[EDIT]

Just tried with a test.jsonc file and the error seems to propagate to other files as well:

  • add a test.jsonc file to the repo
    echo '{\n"hello": "world"\n}' > test.jsonc
  • format it:
    bunx @biomejs/biome format --write test.jsonc
  • same behavior occurs
    image

Expected behavior

We should not see any warning for trailing commas on *.jsonc while the rules allow for it.
The same behavior should occur if the overrides section contains an include for a pattern that targets **/*.jsonc.

Does this issue occur when using the CLI directly?

No

Logs

Logs
[Trace - 11:34:57 PM] Sending request 'textDocument/codeAction - (1849)'.
Params: {
    "textDocument": {
        "uri": "file:///Volumes/dev/biome-test/biome.jsonc"
    },
    "range": {
        "start": {
            "line": 13,
            "character": 26
        },
        "end": {
            "line": 13,
            "character": 26
        }
    },
    "context": {
        "diagnostics": [],
        "triggerKind": 2
    }
}

[Trace - 11:34:57 PM] Received response 'textDocument/codeAction - (1849)' in 1ms.
Result: []

[Trace - 11:35:01 PM] Sending request 'textDocument/codeAction - (1850)'.
Params: {
"textDocument": {
"uri": "file:///Volumes/dev/biome-test/biome.jsonc"
},
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 20,
"character": 0
}
},
"context": {
"diagnostics": [],
"only": [
"source.fixAll"
],
"triggerKind": 2
}
}

[Trace - 11:35:01 PM] Received response 'textDocument/codeAction - (1850)' in 3ms.
Result: []

[Trace - 11:35:01 PM] Sending request 'textDocument/codeAction - (1851)'.
Params: {
"textDocument": {
"uri": "file:///Volumes/dev/biome-test/biome.jsonc"
},
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 20,
"character": 0
}
},
"context": {
"diagnostics": [],
"only": [
"source.organizeImports"
],
"triggerKind": 2
}
}

[Trace - 11:35:01 PM] Received response 'textDocument/codeAction - (1851)' in 1ms.
Result: []

[Trace - 11:35:01 PM] Sending request 'textDocument/formatting - (1852)'.
Params: {
"textDocument": {
"uri": "file:///Volumes/dev/biome-test/biome.jsonc"
},
"options": {
"tabSize": 2,
"insertSpaces": false,
"trimFinalNewlines": true,
"insertFinalNewline": true
}
}

[Trace - 11:35:01 PM] Received response 'textDocument/formatting - (1852)' in 0ms.
Result: [
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 21,
"character": 0
}
},
"newText": "{\n\t"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",\n\t"organizeImports": {\n\t\t"enabled": true,\n\t},\n\t"linter": {\n\t\t"enabled": true,\n\t\t"rules": {\n\t\t\t"recommended": true,\n\t\t},\n\t},\n\t"json": {\n\t\t"formatter": {\n\t\t\t"trailingCommas": "all",\n\t\t},\n\t\t"parser": {\n\t\t\t"allowTrailingCommas": true,\n\t\t},\n\t},\n}\n"
}
]

[Trace - 11:35:01 PM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"uri": "file:///Volumes/dev/biome-test/biome.jsonc",
"version": 76
},
"contentChanges": [
{
"range": {
"start": {
"line": 18,
"character": 2
},
"end": {
"line": 18,
"character": 2
}
},
"rangeLength": 0,
"text": ","
},
{
"range": {
"start": {
"line": 17,
"character": 3
},
"end": {
"line": 17,
"character": 3
}
},
"rangeLength": 0,
"text": ","
},
{
"range": {
"start": {
"line": 16,
"character": 30
},
"end": {
"line": 16,
"character": 30
}
},
"rangeLength": 0,
"text": ","
},
{
"range": {
"start": {
"line": 13,
"character": 26
},
"end": {
"line": 13,
"character": 26
}
},
"rangeLength": 0,
"text": ","
},
{
"range": {
"start": {
"line": 9,
"character": 3
},
"end": {
"line": 9,
"character": 3
}
},
"rangeLength": 0,
"text": ","
},
{
"range": {
"start": {
"line": 8,
"character": 22
},
"end": {
"line": 8,
"character": 22
}
},
"rangeLength": 0,
"text": ","
},
{
"range": {
"start": {
"line": 3,
"character": 17
},
"end": {
"line": 3,
"character": 17
}
},
"rangeLength": 0,
"text": ","
}
]
}

[Trace - 11:35:01 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
"uri": "file:///Volumes/dev/biome-test/biome.jsonc",
"diagnostics": [],
"version": 76
}

[Trace - 11:35:01 PM] Sending notification 'textDocument/didSave'.
Params: {
"textDocument": {
"uri": "file:///Volumes/dev/biome-test/biome.jsonc"
}
}

[Trace - 11:35:01 PM] Sending request 'textDocument/codeAction - (1853)'.
Params: {
"textDocument": {
"uri": "file:///Volumes/dev/biome-test/biome.jsonc"
},
"range": {
"start": {
"line": 13,
"character": 27
},
"end": {
"line": 13,
"character": 27
}
},
"context": {
"diagnostics": [
{
"range": {
"start": {
"line": 13,
"character": 26
},
"end": {
"line": 13,
"character": 27
}
},
"message": "Trailing comma",
"code": 519,
"severity": 2,
"source": "jsonc"
}
],
"triggerKind": 2
}
}

[Trace - 11:35:01 PM] Received response 'textDocument/codeAction - (1853)' in 1ms.
Result: []

[Trace - 11:35:01 PM] Sending notification 'workspace/didChangeWatchedFiles'.
Params: {
"changes": [
{
"uri": "file:///Volumes/dev/biome-test/biome.jsonc",
"type": 2
}
]
}

[Trace - 11:35:01 PM] Received request 'client/unregisterCapability - (39)'.
Params: {
"unregisterations": [
{
"id": "biome_did_change_extension_settings",
"method": "workspace/didChangeConfiguration"
},
{
"id": "biome_range_formatting",
"method": "textDocument/rangeFormatting"
},
{
"id": "biome_on_type_formatting",
"method": "textDocument/onTypeFormatting"
},
{
"id": "biome_rename",
"method": "textDocument/rename"
},
{
"id": "biome_formatting",
"method": "textDocument/formatting"
},
{
"id": "biome_did_change_workspace_settings",
"method": "workspace/didChangeWatchedFiles"
}
]
}

[Trace - 11:35:01 PM] Sending response 'client/unregisterCapability - (39)'. Processing request took 0ms
No result returned.

[Trace - 11:35:01 PM] Received request 'client/registerCapability - (40)'.
Params: {
"registrations": [
{
"id": "biome_did_change_extension_settings",
"method": "workspace/didChangeConfiguration"
},
{
"id": "biome_range_formatting",
"method": "textDocument/rangeFormatting"
},
{
"id": "biome_on_type_formatting",
"method": "textDocument/onTypeFormatting",
"registerOptions": {
"documentSelector": null,
"firstTriggerCharacter": "}",
"moreTriggerCharacter": [
"]",
")"
]
}
},
{
"id": "biome_rename",
"method": "textDocument/rename"
},
{
"id": "biome_formatting",
"method": "textDocument/formatting"
},
{
"id": "biome_did_change_workspace_settings",
"method": "workspace/didChangeWatchedFiles",
"registerOptions": {
"watchers": [
{
"globPattern": "/Volumes/dev/biome-test/biome.json",
"kind": 7
},
{
"globPattern": "/Volumes/dev/biome-test/biome.jsonc",
"kind": 7
},
{
"globPattern": "/Volumes/dev/biome-test/rome.json",
"kind": 7
}
]
}
}
]
}

[Trace - 11:35:01 PM] Sending response 'client/registerCapability - (40)'. Processing request took 0ms
No result returned.

[Trace - 11:35:01 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
"uri": "file:///Volumes/dev/biome-test/biome.jsonc",
"diagnostics": [],
"version": 76
}

[Trace - 11:35:01 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
"uri": "file:///Volumes/dev/biome-test/package.json",
"diagnostics": [],
"version": 2
}

Those warnings aren't emitted by Biome. They are probably emitted by another language server running in your VSCode, which doesn't support trailing commas. That's probably the built-in language server.

If you hover with your mouse on the diagnostic, it might tell you which language server is emitting the diagnostic.

You are 90% right @ematipico, this was very helpful, thanks.

This must be indeed the vscode built-in json language server.

I could fix the warning for other *.jsonc files by adding this to my vscode settings:

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

But this doesn't affect the biome.jsonc, neither with "fileMatch": ["biome.jsonc"].
image

I'll be researching it more until the weekend and coming back here if I find a solution, if not I'll just deny trailing commas for biome.jsonc in the rules.
For now I'm happy to close the issue as it most certainly is not a fault on this extension.

Thank you so much again, this is now very usable.