biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.
https://biomejs.dev
Apache License 2.0
15.19k stars 473 forks source link

🐛 <VSCode> When saving tsconfig.json, biome extension reports an error msg. #1055

Closed zhoujian-official closed 9 months ago

zhoujian-official commented 11 months ago

Environment information

CLI:
  Version:                      1.4.1
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

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

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

Workspace:
  Open Documents:               0

What happened?

  1. Enable editor.formatOnSave.
  2. Open tsconfig.json in vscode.
  3. Edit it and save.
  4. Biome extension shows an error message: Format with errors is disabled.

image

I think it is related to #933

Expected result

  1. don't show this error
  2. treat tsconfig.json as a "json with comments" file like vscode did, and format it.

Code of Conduct

ematipico commented 11 months ago

If you have the chance, could you try the latest nightly release? Just to confirm that it's fixed

zhoujian-official commented 11 months ago

If you have the chance, could you try the latest nightly release? Just to confirm that it's fixed

The latest nightly(1.4.1-nightly.bc772a3) seems have problems in dependencies. Here is package-lock's diff.

image

image

Conaclos commented 9 months ago

Is the bug still present in the latest release (1.5.2)?

zhoujian-official commented 9 months ago

Is the bug still present in the latest release (1.5.2)?

The error message is gone, but tsconfig.json is not formatted, is this expected?

ematipico commented 9 months ago

Is the bug still present in the latest release (1.5.2)?

The error message is gone, but tsconfig.json is not formatted, is this expected?

That's expected. It's a protected file: https://biomejs.dev/guides/how-biome-works/#protected-files

kevinwolfcr commented 8 months ago

@ematipico Is there any specific reason Biome can not format tsconfig.json files? I would love to apply my formatter rules to that file, so it follows the same style as the rest of the json files on my projects. I see that the latest nightly release allows formatting package.json.

ematipico commented 8 months ago

@ematipico Is there any specific reason Biome can not format tsconfig.json files? I would love to apply my formatter rules to that file, so it follows the same style as the rest of the json files on my projects. I see that the latest nightly release allows formatting package.json.

Because it requires special formatting. Would you like to help and remove the restrictions?

kevinwolfcr commented 8 months ago

Because it requires special formatting. Would you like to help and remove the restrictions?

Sure I can help. I asume that it is just allowing TSconfig to be linted and formatted, right? This will be my first time doing something in rust, but I will take a look at the PR enabling package.json.

What is the special formatting you mean?

ematipico commented 8 months ago

Because it requires special formatting. Would you like to help and remove the restrictions?

Sure I can help. I asume that it is just allowing TSconfig to be linted and formatted, right? This will be my first time doing something in rust, but I will take a look at the PR enabling package.json.

What is the special formatting you mean?

tsconfig.json and jsconfig.json must be parsed as JSONC files, because that's why tsc and VSCode parse these files. I order to opt-in this, you'll have to add these files in this array:

https://github.com/biomejs/biome/blob/6560177be8d5c89ca1b84c2cbdbba6cc05f8de57/crates/biome_service/src/file_handlers/mod.rs#L65-L78