Skip to content

Biome v1.7

The brand of the project. It says "Biome, toolchain of the web" The brand of the project. It says "Biome, toolchain of the web"

今天,我们激动地宣布 Biome v1.7 正式发布!

¥Today we’re excited to announce the release of Biome v1.7!

此新版本为从 ESLint 和 Prettier 迁移提供了便捷途径。它也为格式化程序和代码检查器引入了实验性的机器可读报告、新的代码检查器规则以及许多修复。

¥This new version provides an easy path to migrate from ESLint and Prettier. It also introduces experimental machine-readable reports for the formatter and the linter, new linter rules, and many fixes.

使用以下命令更新 Biome:

¥Update Biome using the following commands:

npm install --save-dev --save-exact @biomejs/biome@latest
npx @biomejs/biome migrate

¥Migrate from ESLint with a single command

此版本引入了一个名为 biome migrate eslint 的新子命令。此命令将读取你的 ESLint 配置,并尝试将其设置移植到 Biome。

¥This release introduces a new subcommand biome migrate eslint. This command will read your ESLint configuration and attempt to port their settings to Biome.

子命令能够处理旧配置文件和平面配置文件。它支持旧版配置中的 extends 字段,并加载共享配置和插件配置!子命令还迁移了 .eslintignore

¥The subcommand is able to handle both the legacy and the flat configuration files. It supports the extends field of the legacy configuration and loads both shared and plugin configurations! The subcommand also migrates .eslintignore.

给定以下 ESLint 配置:

¥Given the following ESLint configuration:

.eslintrc.json
{
"extends": [
"plugin:unicorn/recommended"
],
"plugins": [
"unicorn"
],
"ignore_patterns": [
"dist/**"
],
"globals": {
"Global1": "readonly"
},
"rules": {
"eqeqeq": "error"
},
"overrides": [
{
"files": [
"tests/**"
],
"rules": {
"eqeqeq": "off"
}
}
]
}

以下 Biome 配置:

¥And the following Biome configuration:

biome.json
{
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
}
}

运行 biome migrate eslint --write 将你的 ESLint 配置迁移到 Biome。该命令会覆盖你的初始 Biome 配置。例如,它禁用了 recommended。这会导致以下 Biome 配置:

¥Run biome migrate eslint --write to migrate your ESLint configuration to Biome. The command overwrites your initial Biome configuration. For example, it disables recommended. This results in the following Biome configuration:

biome.json
{
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"complexity": {
"noForEach": "error",
"noStaticOnlyClass": "error",
"noUselessSwitchCase": "error",
"useFlatMap": "error"
},
"style": {
"noNegationElse": "off",
"useForOf": "error",
"useNodejsImportProtocol": "error",
"useNumberNamespace": "error"
},
"suspicious": {
"noDoubleEquals": "error",
"noThenProperty": "error",
"useIsArray": "error"
}
}
},
"javascript": {
"globals": [
"Global1"
]
},
"overrides": [
{
"include": [
"tests/**"
],
"linter": {
"rules": {
"suspicious": {
"noDoubleEquals": "off"
}
}
}
}
]
}

子命令需要 Node.js 来加载和解析 ESLint 配置文件中配置的所有插件和 extends。目前,biome migrate eslint 不支持以 YAML 编写的配置。

¥The subcommand needs Node.js to load and resolve all the plugins and extends configured in the ESLint configuration file. For now, biome migrate eslint doesn’t support configuration written in YAML.

我们有一个 专用页面 文件,其中列出了给定 ESLint 规则对应的 Biome 规则。我们处理一些 ESLint 插件,例如 TypeScript ESLintESLint JSX A11yESLint ReactESLint Unicorn。某些规则与 ESLint 的对应规则等效,而其他规则则借鉴了 ESLint 的规则。默认情况下,Biome 不会迁移启发规则。你可以使用 CLI 标志 --include-inspired 来迁移它们。

¥We have a dedicated page that lists the equivalent Biome rule of a given ESLint rule. We handle some ESLint plugins such as TypeScript ESLint, ESLint JSX A11y, ESLint React, and ESLint Unicorn. Some rules are equivalent to their ESLint counterparts, while others are inspired. By default, Biome doesn’t migrate inspired rules. You can use the CLI flag --include-inspired to migrate them.

¥Migrate from Prettier with a single command

Biome v1.6 引入了子命令 biome migrate prettier

¥Biome v1.6 introduced the subcommand biome migrate prettier.

在 Biome v1.7 中,我们添加了对 Prettier 的 overrides 的支持,并尝试将 .prettierignore 通配符模式转换为 Biome 支持的通配符模式。

¥In Biome v1.7, we add support of Prettier’s overrides and attempts to convert .prettierignore glob patterns to globs supported by Biome.

在迁移过程中,Prettier 的 overrides 被转换为 Biome 的 overrides。给定以下 .prettierrc.json

¥During the migration, Prettier’s overrides is translated to Biome’s overrides. Given the following .prettierrc.json

.prettierrc.json
{
"useTabs": false,
"singleQuote": true,
"overrides": [
{
"files": [
"*.json"
],
"options": {
"tabWidth": 2
}
}
]
}

运行 biome migrate prettier --write 将你的 Prettier 配置迁移到 Biome。这会导致以下 Biome 配置:

¥Run biome migrate prettier --write to migrate your Prettier configuration to Biome. This results in the following Biome configuration:

biome.json
{
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 80,
"attributePosition": "auto"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingComma": "all",
"semicolons": "asNeeded",
"arrowParentheses": "always",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto"
}
},
"overrides": [
{
"include": [
"*.json"
],
"formatter": {
"indentWidth": 2
}
}
]
}

子命令需要 Node.js 来加载 JavaScript 配置,例如 .prettierrc.jsbiome migrate prettier 不支持用 JSON5、TOML 或 YAML 编写的配置。

¥The subcommand needs Node.js to load JavaScript configurations such as .prettierrc.js. biome migrate prettier doesn’t support configuration written in JSON5, TOML, or YAML.

¥Emit machine-readable reports

Biome 现在能够输出 JSON 报告,详细说明命令发出的诊断信息。

¥Biome is now able to output JSON reports detailing the diagnostics emitted by a command.

例如,你可以在检查代码库时生成报告:

¥For instance, you can emit a report when you lint a codebase:

Terminal window
biome lint --reporter=json-pretty .

目前,我们支持两种报告格式:jsonjson-pretty

¥For now, we support two report formats: json and json-pretty.

请注意,报告格式目前处于实验性阶段,未来可能会有所更改。请尝试此功能,并告知我们是否需要在报告中添加任何信息。

¥Note that the report format is **experimental **, and it might change in the future. Please try this feature and let us know if any information needs to be added to the reports.

¥Check git staged files

Biome v1.5 添加了 --changed,用于格式化和检查 git 跟踪的已更改文件。

¥Biome v1.5 added the --changed to format and lint git tracked files that have been changed.

今天,我们推出新选项 --staged,它允许你仅检查已添加到 Git 索引的文件(暂存文件)。这有助于检查要提交的文件是否已格式化并经过代码检查:

¥Today we are introducing a new option --staged which allows you to check only files added to the Git index (staged files). This is useful for checking that the files you want to commit are formatted and linted:

Terminal window
biome check --staged .

这对于编写你自己的 提交前脚本 非常有用。请注意,已暂存文件上的未暂存更改不会被忽略。因此,我们仍然建议使用 专用提交前工具

¥This is handy for writing your own pre-commit script. Note that unstaged changes on a staged file are not ignored. Thus, we still recommend using a dedicated pre-commit tool.

感谢 @castarco 实现了此功能!

¥Thanks to @castarco for implementing this feature!

¥New nursery rules

自 Biome v1.6 起,我们添加了几个新规则。新规则在 nursery 组中进行孵化。初始规则不受语义版本控制。

¥Since Biome v1.6, we added several new rules. New rules are incubated in the nursery group. Nursery rules are exempt from semantic versioning.

新规则如下:

¥The new rules are:

¥Promoted rules

一旦稳定下来,一个初始规则就会被提升为稳定规则。以下规则已推广:

¥Once stable, a nursery rule is promoted to a stable group. The following rules are promoted:

¥Miscellaneous

  • 默认情况下,如果配置文件不存在,Biome 会在工作目录及其父目录中搜索。Biome 提供了一个 CLI 选项 --config-path 和一个环境变量 BIOME_CONFIG_PATH,可用于覆盖此行为。之前,该规则要求提供一个包含 Biome 配置文件的目录。例如,以下命令使用 ./config/ 中的 Biome 配置文件。

    ¥By default, Biome searches a configuration file in the working directory and parent directories if it doesn’t exist. Biome provides a CLI option --config-path and an environment variable BIOME_CONFIG_PATH that allows which can be used to override this behavior. Previously, they required a directory containing a Biome configuration file. For example, the following command uses the Biome configuration file in ./config/.

    Terminal window
    biome format --config-path=./config/ ./src

    对于许多习惯于直接指定配置文件路径的用户来说,这一点不太容易理解。现在它们接受文件,因此以下命令有效:

    ¥This wasn’t very clear for many users who are used to specifying the configuration file path directly. They now accept a file, so the following command is valid:

    Terminal window
    biome format --config-path=./config/biome.json ./src
  • 现在,你可以通过将 javascript.jsxRuntime 设置为 reactClassic,在规则 noUnusedImportsuseImportType 中忽略 React 导入。

    ¥You can now ignore React imports in the rules noUnusedImports and useImportType by setting javascript.jsxRuntime to reactClassic.

  • Biome 会对 常用文件 应用特定的设置。现在,可以识别更多文件,并区分仅允许注释的 JSON 文件和允许注释及尾随逗号的 JSON 文件。

    ¥Biome applies specific settings to well-known files. It now recognizes more files and distinguishes between JSON files that only allow comments and JSON files that allow both comments and trailing commas.

  • 在 React 生态系统中,允许以 .js 结尾的文件包含 JSX 语法。Biome 扩展现在能够解析与 JavaScript 语言标识符关联的文件中的 JSX 语法。

    ¥In the React ecosystem, files ending in .js are allowed to contain JSX syntax. The Biome extension is now able to parse JSX syntax in files that are associated with the JavaScript language identifier.

  • useExhaustiveDependencies 现在支持 Preact。

    ¥useExhaustiveDependencies now supports Preact.

有关更多详细信息,请参阅 changelog

¥See the changelog for more details.

¥What’s Next?

我们已开始开发 CSS 格式化程序和代码检查器。插件系统 的早期实现工作也在进行中。我们的一些贡献者已经开始为 GraphQLYAML 进行初步工作。欢迎任何帮助!

¥We have started work on the CSS formatter and linter. Early implementation towards a plugin system is also underway. Some of our contributors have started preliminary work for GraphQL and YAML. Any help is welcome!

如果你或你的公司认为 Biome 有价值,请考虑每月捐赠 Open Collective。你也可以 在 GitHub 上赞助我们。这对于项目的可持续性至关重要。

¥If Biome is valuable to you or your company, consider donating monthly to our Open Collective. You can also sponsor us on GitHub. This is important for the sustainability of the project.

请在 我们的 BlueSky 上关注我们,并加入 我们的 Discord 社区

¥Follow us on our BlueSky and join our Discord community.