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

📝 json files with trailing commas aren't formatted #1662

Closed
1 task done
juliusmarminge opened this issue Jan 25, 2024 · 5 comments · Fixed by #1944
Closed
1 task done

📝 json files with trailing commas aren't formatted #1662

juliusmarminge opened this issue Jan 25, 2024 · 5 comments · Fixed by #1944

Comments

@juliusmarminge
Copy link

juliusmarminge commented Jan 25, 2024

Environment information

CLI:
  Version:                      1.1.2
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v20.11.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/10.2.4"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 true

Workspace:
  Open Documents:               0

Discovering running Biome servers...

Configuration

{
    "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
    "formatter": {
        "enabled": true,
        "formatWithErrors": true
    }
}

Additional info

Similar to #1659 but jsonc files are allowed to have trailing commas so it's still a different issue I think. Maybe this even falls under the category of non-goals, but it's a very nice-to-have feature when editing JSON files.

Playground link

https://codesandbox.io/p/devbox/gallant-black-skhrkn?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clrt0gimx00053b6erpr5mq4g%2522%252C%2522sizes%2522%253A%255B47.880897138437746%252C52.119102861562254%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clrt0gimx00023b6eaofkd6ee%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clrt0gimx00033b6e8e78mfxc%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clrt0gimx00043b6ego92wpb3%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B86.2709277212127%252C13.7290722787873%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clrt0gimx00023b6eaofkd6ee%2522%253A%257B%2522id%2522%253A%2522clrt0gimx00023b6eaofkd6ee%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clrt0gimw00013b6ewh0j3lid%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252F.codesandbox%252FDockerfile%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%255D%252C%2522activeTabId%2522%253A%2522clrt0gimw00013b6ewh0j3lid%2522%257D%252C%2522clrt0gimx00043b6ego92wpb3%2522%253A%257B%2522tabs%2522%253A%255B%255D%252C%2522id%2522%253A%2522clrt0gimx00043b6ego92wpb3%2522%257D%252C%2522clrt0gimx00033b6e8e78mfxc%2522%253A%257B%2522id%2522%253A%2522clrt0gimx00033b6e8e78mfxc%2522%252C%2522activeTabId%2522%253A%2522clrt0hsbh00ac3b6eu7p0eb8y%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clrt0hsbh00ac3b6eu7p0eb8y%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522clrt0hsgq001hefipejt2az06%2522%257D%255D%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@juliusmarminge juliusmarminge changed the title 📝 <TITLE> 📝 json files with trailing commas aren't formatted Jan 25, 2024
@ematipico
Copy link
Member

Have you tried to enable the trailing comma option?

https://biomejs.dev/reference/configuration/#jsonparserallowtrailingcommas

@juliusmarminge
Copy link
Author

Just tried and doesn't seem to help:

CleanShot 2024-01-25 at 11 34 27

@Sec-ant
Copy link
Member

Sec-ant commented Jan 25, 2024

If I understand correctly, Biome doesn't have a language setting block for jsonc, so the correct way to parse/format a .jsonc file is by setting json.parser.allowTrailingCommas and json.parser.allowComments these two options, whether in a overrides block or globally. So that makes this issue and #1659 the same IMO.

And despite that sameness, I think another thing that @juliusmarminge wants to ask here is that whether Biome will consider supporting formatting invalid syntaxes (like trailing commas) in a standard json file when it is being edited, in which case formatting on the fly can give better dev experience?

@ematipico
Copy link
Member

ematipico commented Jan 31, 2024

And despite that sameness, I think another thing that @juliusmarminge wants to ask here is that whether Biome will consider supporting formatting invalid syntaxes (like trailing commas) in a standard json file when it is being edited, in which case formatting on the fly can give better dev experience?

This is already possible nowadays by using formatter.formatWithErrors. With overrides, you can decide to enable this behaviour only to .jsonc files.

{
	"overrides": [
		{
			"include": ["*.jsonc"],
				"formatter": {
					"formatWithErrors": true
				}
		}
	]
}

@Sec-ant
Copy link
Member

Sec-ant commented Jan 31, 2024

This is already possible nowadays by using formatter.formatWithErrors. With overrides, you can decide to enable this behaviour only to .jsonc files.

I wasn't aware of the formatWithErrors option when I left that comment, thanks for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants