Skip to content

将 Biome 与你的 VCS 集成

VCS(版本控制系统)集成旨在利用只有 VCS 才能提供的附加功能。目前,Biome 仅支持 Git。集成是可选的*。你必须在 Biome 配置文件中启用 vcs.enabled 并设置 vcs.clientKind

¥The VCS (Version Control System) integration is meant to take advantage of additional features that only a VCS can provide. At the moment, Biome only supports Git. The integration is opt-in*. You have to enable vcs.enabled and set vcs.clientKind in the Biome configuration file:

biome.json
{
"vcs": {
"enabled": true,
"clientKind": "git"
}
}

此配置本身不执行任何操作。你需要选择所需的功能。

¥This configuration doesn’t do anything per se. You need to opt-in the features you want.

¥Use the ignore file

启用 vcs.useIgnoreFile,以允许 Biome 忽略 VCS 忽略文件中列出的所有文件和目录。目前,Biome 仅考虑工作目录中的忽略文件。

¥Enable vcs.useIgnoreFile, to allow Biome to ignore all the files and directories listed in your VCS ignore file. For now, Biome only takes the ignore file in the working directory into account.

biome.json
{
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
}
}

¥Process only changed files

此功能仅通过 CLI 提供,并且仅允许处理从一个修订版更改为另一个修订版的文件。

¥This is a feature that is available only via CLI, and allows processing only the files that have changed from one revision to another.

首先,你必须更新配置文件并通过 vcs.defaultBranch 字段告诉 Biome 默认分支是什么:

¥First, you have to update your configuration file and tell Biome what’s the default branch via the vcs.defaultBranch field:

biome.json
{
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true,
"defaultBranch": "main"
}
}

然后,将 --changed 选项添加到你的命令中,以仅处理你的 VCS 确认为 “changed” 的那些文件。Biome 在 VCS 的帮助下,将从分支 main 和当前修订版中确定已更改的文件:

¥Then, add the --changed option to your command, to process only those files that your VCS acknowledged as “changed”. Biome, with the help of the VCS, will determine the changed file from the branch main and your current revision:

Terminal window
biome check --changed

或者,你可以使用选项 --since 指定任意分支。此选项优先于选项 vcs.defaultBranch。例如,你可能希望根据 next 分支检查你的更改:

¥Alternatively, you can use the option --since to specify an arbitrary branch. This option takes precedence over the option vcs.defaultBranch. For example, you might want to check your changes against the next branch:

Terminal window
biome check --changed --since=next

¥Process only staged files

在提交更改之前,你可能需要检查已添加到索引中的格式和 lint 文件(也称为暂存文件)。将 --staged 选项添加到你的命令,以仅处理这些文件:

¥Before committing your changes, you may want to check the formatting and lints files that have been added to the index, also known as staged files. Add the --staged option to your command, to process only those files:

Terminal window
biome check --staged

--staged 选项在 ci 命令上不可用,因为你不需要在 CI 环境中提交更改。

¥The --staged option is not available on the ci command because you are not expected to commit changes in a CI environment.