入门
¥Installation
下载 Biome 的最快方法是使用包管理器,例如 npm。这需要 Node.js v14.18 或更新版本。如果你想在不安装 Node.js 的情况下使用 Biome,CLI 也可以作为 独立可执行文件 使用。
¥The fastest way to download Biome is to use a package manager such as npm.
This requires Node.js v14.18 or newer.
The CLI is also available as a standalone executable if you want to use Biome without installing Node.js.
要安装 Biome,请在包含 package.json 文件的目录中运行以下命令。
¥To install Biome, run the following commands in a directory containing a package.json file.
npm install --save-dev --save-exact @biomejs/biomeyarn add --dev --exact @biomejs/biomepnpm add --save-dev --save-exact @biomejs/biomebun add --dev --exact @biomejs/biome¥Configuration
我们建议你为每个项目创建一个 biome.json 或 biome.jsonc 配置文件。这样就无需在每次运行命令时重复 CLI 选项,并确保 Biome 在编辑器中使用相同的配置。某些选项也只能从配置文件中获得。如果你对 Biome 的默认设置感到满意,则无需创建配置文件。要创建 biome.json 文件,请在项目的根文件夹中运行 init 命令:
¥We recommend that you create a biome.json or a biome.jsonc configuration file for each project.
This eliminates the need to repeat the CLI options each time you run a command,
and ensures that Biome uses the same configuration in your editor.
Some options are also only available from a configuration file.
If you are happy with Biome’s defaults, you don’t need to create a configuration file.
To create the biome.json file, run the init command in the root folder of your project:
npx @biomejs/biome inityarn biome initpnpm biome initbunx biome initdeno run -A npm:@biomejs/biome init传递 --jsonc 选项以改为发出 biome.jsonc 文件。
¥Pass the --jsonc option to emit a biome.jsonc file instead.
运行 init 命令后,你的目录中会有一个新的 biome.json 文件:
¥After running the init command, you’ll have a new biome.json file in your directory:
{ "$schema": "https://biomejs.dev/schemas/1.9.0/schema.json", "vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false }, "files": { "ignoreUnknown": false, "ignore": [] }, "formatter": { "enabled": true, "indentStyle": "tab" }, "organizeImports": { "enabled": true }, "linter": { "enabled": true, "rules": { "recommended": true } }, "javascript": { "formatter": { "quoteStyle": "double" } }}linter.enabled: true 启用 linter,rules.recommended: true 启用 推荐规则。这对应于默认设置。
¥The linter.enabled: true enables the linter and rules.recommended: true enables the recommended rules.
This corresponds to the default settings.
格式化默认启用,但你可以通过明确使用 formatter.enabled: false 将其 disable。
¥Formatting is enabled by default, but you can disable it by explicitly using formatter.enabled: false.
¥Usage
Biome CLI 附带许多命令和选项,因此你可以只使用所需的命令和选项。
¥The Biome CLI comes with many commands and options, so you can use only what you need.
你可以使用带有 --write 选项的 format 命令格式化文件和目录:
¥You can format files and directories using the format command with the --write option:
npx @biomejs/biome format --write <files>yarn biome format --write <files>pnpm biome format --write <files>bunx biome format --write <files>deno run -A npm:@biomejs/biome format --write <files>你可以使用带有 --write 选项的 lint 命令对文件和目录进行 lint 和应用 安全修复:
¥You can lint and apply safe fixes to files and directories using the lint command with the --write option:
npx @biomejs/biome lint --write <files>yarn biome lint --write <files>pnpm biome lint --write <files>bunx biome lint --write <files>deno run -A npm:@biomejs/biome lint --write <files>你可以通过利用 check 命令运行它们两个:
¥You can run both of them by leveraging the check command:
npx @biomejs/biome check --write <files>yarn biome check --write <files>pnpm biome check --write <files>bunx biome check --write <files>deno run -A npm:@biomejs/biome check --write <files>check 命令可同时运行多个工具。它格式化、lint 和组织导入。
¥The check command runs multiple tools at once.
It formats, lints, and organizes imports.
安装编辑器插件
Section titled 安装编辑器插件¥Install an editor plugin
我们建议安装编辑器插件以充分利用 Biome。查看 Robin Pokorny 的 编辑器页面 文章。
¥We recommend installing an editor plugin to get the most out of Biome. Check out the editor page to know which editors support Biome.
CI 设置
Section titled CI 设置¥CI Setup
如果你使用的是 Node.js,则在 CI 中运行 Biome 的推荐方法是使用 你首选的包管理器。这可确保你的 CI 管道使用与编辑器内部或运行本地 CLI 命令时相同的 Biome 版本。或者,你可以使用专用的 CI 操作。
¥If you’re using Node.js, the recommended way to run Biome in CI is to use your preferred package manager. This ensures that your CI pipeline uses the same version of Biome as you do inside the editor or when running local CLI commands. Alternatively, you can use a dedicated CI Action.
¥Next Steps
成功!你现在可以开始使用 Biome 了。🥳
¥Success! You’re now ready to use Biome. 🥳
-
了解有关如何使用 配置 Biome 的更多信息
¥Learn more about how to configure Biome
-
了解有关如何使用和配置 formatter 的更多信息
¥Learn more about how to use and configure the formatter
-
了解有关如何使用和配置 linter 的更多信息
¥Learn more about how to use and configure the linter
-
熟悉 CLI 选项
¥Get familiar with the CLI options
-
熟悉 配置选项
¥Get familiar with the configuration options
-
加入我们的 Discord 上的社区
¥Join our community on Discord