Skip to content

入门指南

Biome 最好作为项目的开发依赖安装,但它也提供无需 Node.js 的 独立可执行文件 版本。

¥Biome is best installed as a development dependency of your projects, but it is also available as a standalone executable that doesn’t require Node.js.

npm i -D -E @biomejs/biome

¥Configuration

虽然 Biome 可以零配置运行,但你可能需要根据项目需求调整一些设置。在这种情况下,你可以运行以下命令生成 biome.json 配置文件。

¥Although Biome can run with zero configuration, you’ll likely want to tweak some settings to suit your project’s needs, in which case you can run the following command to generate a biome.json configuration file.

npx @biomejs/biome init

¥Usage

让我们快速了解一下如何在项目中使用 Biome。

¥Lets get a quick overview of how to use Biome in your project.

¥Command-line interface

Biome 提供了一个 命令行接口 来格式化、检查和检查你的代码。

¥Biome provides a command-line interface to format, lint, and check your code.

# Format all files
npx @biomejs/biome format --write
# Format specific files
npx @biomejs/biome format --write <files>
# Lint files and apply safe fixes to all files
npx @biomejs/biome lint --write
# Lint files and apply safe fixes to specific files
npx @biomejs/biome lint --write <files>
# Format, lint, and organize imports of all files
npx @biomejs/biome check --write
# Format, lint, and organize imports of specific files
npx @biomejs/biome check --write <files>

¥Editor integrations

Biome 可作为你常用编辑器的官方扩展使用。

¥Biome is available as a first-party extension in your favorite editors.

社区扩展 也支持其他编辑器,例如 Vim、Neovim 和 Sublime Text 等。

¥There are also community extensions for other editors, such as Vim, Neovim, and Sublime Text, to name a few.

¥Continuous Integration

在你的 CI 流水线中运行 biome ci,以确保团队代码质量和一致性。它的工作方式与 biome check 命令完全相同,但针对 CI 环境进行了优化。

¥Run biome ci as part of your CI pipeline to enforce code quality and consistency across your team. It works just like the biome check command, but is optimized for CI environments.

请参阅 持续集成 示例以获取更多示例。

¥See the Continuous Integration recipes for more examples.

¥Next Steps

成功!你现在可以开始使用 Biome 了。🥳

¥Success! You’re now ready to use Biome. 🥳