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

🐛 Parse error for jsonc files #3696

Closed
1 of 3 tasks
unional opened this issue Jul 26, 2024 · 14 comments · Fixed by #3729 or Ramyromel/mesc#11
Closed
1 of 3 tasks

🐛 Parse error for jsonc files #3696

unional opened this issue Jul 26, 2024 · 14 comments · Fixed by #3729 or Ramyromel/mesc#11
Assignees
Labels
A-Core Area: core A-Parser Area: parser S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@unional
Copy link

unional commented Jul 26, 2024

VS Code version

1.90.2

Extension version

2.3.0

Biome version

1.8.3

Operating system

  • Windows
  • macOS
  • Linux

Description

image

It seems like the extension is trying to parse jsonc files as json files.

Steps to reproduce

update biome from 1.7.3 to 1.8.3

Expected behavior

should work

Does this issue occur when using the CLI directly?

No

Logs

`Biome Trace` is empty
@ematipico
Copy link
Member

It's very difficult to triage the issue without information.

Can you please at least share the contents of the file? Can you check if you can replicate the issue in the playground?

@unional
Copy link
Author

unional commented Jul 26, 2024

Hi, since this is related to extension, probably can't repro it in the playground.

I think any repo using biome with jsonc file should able to repro it.
e.g. https://github.com/repobuddy/repobuddy/tree/biome-jsonc

pnpm i and open a jsonc file should be sufficient.

@nhedger
Copy link
Member

nhedger commented Jul 26, 2024

What does your editor detect the file as? Are you sure that you don't have some kind of mapping that tells VS Code that the .jsonc extension is a JSON file? I can't reproduce the issue when opening the recommended.jsonc file from your repo.

@unional
Copy link
Author

unional commented Jul 27, 2024

What does your editor detect the file as? Are you sure that you don't have some kind of mapping that tells VS Code that the .jsonc extension is a JSON file? I can't reproduce the issue when opening the recommended.jsonc file from your repo.

That's strange. Are you on MacOS, and the extension shows that it is using biome 1.8.3?

I don't have setting that map jsonc to json.
It is detected as jsonc
image

@unional
Copy link
Author

unional commented Jul 27, 2024

I confirmed the issue also occurs in linux (wsl, ubuntu) and Windows 11.

I can repro it to other repo using biome. Only need to update it to 1.8.3 and reload vscode.

@ematipico
Copy link
Member

I am sorry @unional, I tried it myself and I can't replicate the issue. So it's possible is something in your internal settings (probably in settings.json). Please provide a minimal reproduction.

@unional
Copy link
Author

unional commented Aug 2, 2024

It is really weird. Another repo in the same system, same biome 1.8.3.
And that works fine.

Will need to look deeper on what's causing it.

Pasting an image here for reference:
image

@ematipico
Copy link
Member

I am going to close this, as we can't replicate it.

Again, I advise you to check your settings.json (project, workspace and user).

Feel free to open it again once you manage to provide a reproduction and some logs from the Daemon (instructions are attached to the template when you create the issue)

@ematipico ematipico closed this as not planned Won't fix, can't repro, duplicate, stale Aug 2, 2024
@unional
Copy link
Author

unional commented Aug 3, 2024

I found out what the problem is.

biome parses json as jsonc by default.

Since that would causes false positives,
my presets disable that by default:

{
  "json": {
    // `biome` treat `json` as `jsonc` by default.
    // That causes false positives and should be avoided.
    "parser": {
      "allowComments": false,
      "allowTrailingCommas": false
  }
}

https://github.com/repobuddy/repobuddy/blob/main/packages/biome/recommended.jsonc#L16-L20

Now the problem is,
biome is not parsing json as jsonc by default.
It is actually using the same parser to parse json and jsonc.

i.e. by doing "allowComments": false at the top level,
I actually also turn off comment support for jsonc files.

IMO this is a bug.

As for why you don't get the error,
it is because my top level biome.json is doing extends like this:

{
  "extends": ["@repobuddy/biome/recommended"]
}

You need to run pnpm install first to hook up the node_modules.

@ematipico
Copy link
Member

Biome doesn't parse JSON files as JSONC files. Did you read this somewhere in our docs? However, some files get a particular treatment, which we document here: https://biomejs.dev/guides/configure-biome/#well-known-files

As for why you don't get the error,
it is because my top level biome.json is doing extends like this

And that's why it's important to provide a reproduction.

Can you please provide a minimal reproduction? It's possible it is a bug, I haven't understood yet what's the issue and where it is.

@unional
Copy link
Author

unional commented Aug 3, 2024

https://github.com/repobuddy/repobuddy/tree/biome-jsonc

here is the minimal repro. The top level biome.jsonc only has:

{
	"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
	"json": {
		// `biome` treat `json` as `jsonc` by default.
		// That causes false positives and should be avoided.
		"parser": {
			"allowComments": false,
			"allowTrailingCommas": false
		}
	}
}

and it fails by itself:

image

@ematipico
Copy link
Member

That's not a minimal reproduction, that's a project. The reason why we ask for a minimal reproduction is because we can remove all the noise from a project, and make sure that there aren't other factors at play.

@unional
Copy link
Author

unional commented Aug 3, 2024

@ematipico ematipico reopened this Aug 3, 2024
@nhedger
Copy link
Member

nhedger commented Aug 22, 2024

I can reproduce the issue seen in the screenshot using the reproduction repo, however I'm moving this to the main repo as it's not an issue with the extension.

@nhedger nhedger transferred this issue from biomejs/biome-vscode Aug 22, 2024
@ematipico ematipico added A-Core Area: core A-Parser Area: parser S-Bug-confirmed Status: report has been confirmed as a valid bug labels Aug 22, 2024
@ematipico ematipico self-assigned this Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Core Area: core A-Parser Area: parser S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
3 participants