语言支持
图例:
¥Legend:
-
✅ 支持
¥✅: Supported
-
🚫 未进行中
¥🚫: Not in progress
-
⌛️ 进行中
¥⌛️: In progress
-
🟡 实验性功能
¥🟡: Experimental
| 语言 | 解析 | 格式化 | Linting | 插件支持 |
|---|---|---|---|---|
| JavaScript | ✅ | ✅ | ✅ | ✅ |
| TypeScript | ✅ | ✅ | ✅ | ✅ |
| JSX | ✅ | ✅ | ✅ | ✅ |
| TSX | ✅ | ✅ | ✅ | ✅ |
| JSON | ✅ | ✅ | ✅ | 🚫 |
| JSONC | ✅ | ✅ | ✅ | 🚫 |
| HTML* | ✅ | ✅ | ✅ | ✅ |
| Vue | 🟡 | 🟡 | 🟡 | 🟡 |
| Svelte | 🟡 | 🟡 | 🟡 | 🟡 |
| Astro | 🟡 | 🟡 | 🟡 | 🟡 |
| CSS | ✅️ | ✅️ | ✅️ | ✅ |
| YAML | ⌛️ | 🚫 | 🚫 | 🚫 |
| GraphQL | ✅️ | ✅️ | ✅️ | 🚫 |
| Markdown | ⌛️ | 🚫 | 🚫 | 🚫 |
| GritQL | ✅️ | ✅️ | 🚫 | 🚫 |
- 目前需要 显式选择加入
¥** currently requires explicit opt-in*
JavaScript 支持
Section titled “JavaScript 支持”¥JavaScript support
Biome 支持该语言的 ES2024 版本。
¥Biome supports the ES2024 version of the language.
Biome 仅支持官方语法。当提案达到 第 3 阶段 时,团队开始开发新语法。
¥Biome supports only the official syntax. The team starts development of the new syntax when a proposal reaches Stage 3.
TypeScript 支持
Section titled “TypeScript 支持”¥TypeScript support
Biome 支持 TypeScript 版本 5.6。
¥Biome supports TypeScript version 5.6.
JSONC 支持
Section titled “JSONC 支持”¥JSONC support
JSONC 代表 “带注释的 JSON。“。这种格式被 VS Code、TypeScript、Babel 等各种工具广泛使用,因为它允许用户在配置文件中添加注释。但是,由于 JSONC 并不是一个严格定义的标准,因此不同的工具在处理 JSONC 文件中的尾随逗号方面存在一些差异。为了适应这一点,Biome 没有为 JSONC 提供专用的语言配置。相反,我们通过 json.parser.allowComments、json.parser.allowTrailingCommas 和 json.formatter.trailingCommas 等选项增强了 JSON 解析和格式化功能。这种方法使 Biome 能够有效地支持不同变体的 JSON 文件。
¥JSONC stands for “JSON with Comments.” This format is widely used by various tools like VS Code, TypeScript, Babel, etc. because it lets users add comments to configuration files. However, since JSONC isn’t a strictly defined standard, there’s some variation in how different tools handle trailing commas in JSONC files. To accommodate this, Biome doesn’t provide a dedicated language configuration for JSONC. Instead, we’ve enhanced our JSON parsing and formatting capabilities with options like json.parser.allowComments, json.parser.allowTrailingCommas, and json.formatter.trailingCommas. This approach allows Biome to effectively support different variants of JSON files.
对于扩展名为 .jsonc 的文件或根据 语言标识符 标识为 jsonc 的文件,Biome 会自动应用以下默认设置来解析和格式化它们:
¥For files with an extension name of .jsonc or those identified as jsonc according to the language identifier, Biome automatically applies the following default settings for parsing and formatting them:
-
json.parser.allowComments:true -
json.parser.allowTrailingCommas:true -
json.formatter.trailingCommas:none
请注意,一些知名文件(如 tsconfig.json 和 .babelrc)不使用 .jsonc 扩展,但仍允许注释和尾随逗号。而其他的,例如 .eslintrc.json,只允许注释。Biome 能够识别这些文件并相应地调整 json.parser.allowTrailingCommas 选项以确保正确解析它们。
¥Please note, some well-known files like tsconfig.json and .babelrc don’t use the .jsonc extension but still allow comments and trailing commas. While others, such as .eslintrc.json, only allow comments. Biome is able to identify these files and adjusts the json.parser.allowTrailingCommas option accordingly to ensure they are correctly parsed.
本节 提供了 Biome 可以识别的知名文件的完整列表。
¥This section gives the full list of well-known files that Biome can recognize.
HTML 超级语言支持
Section titled “HTML 超级语言支持”¥HTML super languages support
自 v2.3.0 版本起,Biome 开箱即用地支持 Vue、Svelte 和 Astro 文件。这意味着 Biome 能够格式化并检查文件的 HTML、CSS 和 JavaScript 部分。
¥Since version v2.3.0, Biome supports Vue, Svelte and Astro file out of the box. This means that Biome is able to format and lint the HTML, CSS and JavaScript parts of the files.
然而,此支持必须被视为实验性功能,并可能随时更改和改进。在 v2.3.0 中,我们实现了支持此功能的架构,但一些格式和代码检查规则需要调整。
¥However, this support must be considered experimental and subject to changes and improvements. In v2.3.0, we landed the architecture that enables this feature, however some formatting and linting rules must be adjusted.
特别是对于 v2.3.0,Biome 不会针对特定语言的语法进行任何特殊解析,例如 Svelte 的控制流语法(例如 {#if } {/if})。这意味着格式可能不符合预期,并且代码检查规则可能无法检测到某些情况。
¥In particular, as for v2.3.0, Biome doesn’t do any particular parsing for language specific syntax, for example the control-flow syntax of Svelte e.g. {#if } {/if}. This means that formatting might not match the desired expectations, and lint rules might not detect some cases.
目前尚不支持跨嵌入式语言运行的 Lint 规则。
¥Lint rules that work across embedded languages aren’t supported yet.
HTML 类语言的代码检查
Section titled “HTML 类语言的代码检查”¥Linting HTML-ish languages
某些 lint 规则目前还无法跨边界生效。例如,对于以下 .vue 文件,规则 noUnusedVariables 会对 greeting 标记为误报:
¥Some lint rules don’t work across boundaries just yet. For example, the following .vue file, the rule noUnusedVariables will flag a false positive for greeting:
<script setup lang="ts"> const greeting = "hello world"</script>
<template> <h1>{{ greeting }}</h1></template>检查 .svelte、.astro 或 .vue 文件时,建议关闭一些额外的规则,以防止因我们部分支持而导致的误报。为此使用选项 overrides:
¥When linting .svelte, .astro or .vue files, it’s advised to turn off a few additional rules to prevent false positive linting errors caused by our partial support. Use the option overrides for that:
{ "overrides": [ { "includes": ["**/*.svelte", "**/*.astro", "**/*.vue"], "linter": { "rules": { "style": { "useConst": "off", "useImportType": "off" }, "correctness": { "noUnusedVariables": "off", "noUnusedImports": "off" } } } } ]}不同设置下的格式化
Section titled “不同设置下的格式化”¥Formatting with different settings
Biome 支持控制不同语言的格式化。由于 Biome 可以在同一文件中处理多种语言,因此根据你的配置,出现不一致的可能性可能会增加。
¥With Biome, you can control the formatting of different languages. Now that Biome can process multiple languages in the same file, the chances of inconsistencies can grow based on your configuration.
例如,在格式化包含 JavaScript 和 CSS 代码的类 HTML 文件时,你可能会遇到文件混杂制表符和空格的情况,如下例所示(假设已启用完全支持):
¥For example, you could risk having a file mixed with tabs and spaces when formatting a HTML-ish file that contains JavaScript and CSS code, like in the following example (we assume full support is enabled):
{ "javascript": { "format": { "indentStyle": "tab" } }, "css": { "format": { "indentStyle": "space", "indentWidth": 4 } }}我们创建了一个 GitHub 讨论区 文档来解决这个问题,欢迎加入讨论并分享你的想法。
¥We created a GitHub discussion to address the issue, join the discussion and let us know what you think.
Biome v2.1 中文网 - 粤ICP备13048890号