SuperAPI AI 工具集

biome

编程与开发

查看项目

更新于 10-15 20:07

技能介绍

用途:在 JavaScript/TypeScript 项目中用 Biome 完成代码检查(lint)、格式化(format)和导入整理(organize imports)。Biome 是单一 Rust 二进制,用一份 biome.json 取代 ESLint + Prettier 组合,概念上类似 Python 的 ruff。

主要能力:支持 JS、TS、JSX、JSON、CSS、GraphQL;提供格式化、lint 规则、导入排序;支持 VCS 忽略文件、overrides、monorepo extends/root;可通过 GritQL 插件编写自定义规则(目前仅支持 JS 和 CSS)。

使用方式:安装并初始化:npm install --save-dev --save-exact @biomejs/biome,然后 npx biome init 生成 biome.json。常用命令:npx biome check --write .(lint + 格式化 + 导入整理,应用安全修复)、npx biome check --write --unsafe .(含不安全修复)、npx biome format --write .(仅格式化)、npx biome lint .(仅 lint)。CI 中使用只读门禁:npx biome ci .,不要用会修改文件的 check --write。从 ESLint/Prettier 迁移:npx biome migrate eslint --write 和 npx biome migrate prettier --write。

配置要点:biome.json 中可设置 vcs.useIgnoreFile 以遵循 .gitignore,formatter.indentStyle 与 lineWidth,linter.rules.recommended,以及 assist.actions.source.organizeImports。

限制与注意:v2 已移除 v1 的 --apply/--apply-unsafe,改用 --write/--write --unsafe;导入整理从顶层 organizeImports 移到 assist.actions.source.organizeImports;files.includes 取代 include/ignore;格式化默认使用制表符,若需空格要显式设置 indentStyle: "space"。不要同时运行 ESLint/Prettier 与 Biome 处理相同文件。Turborepo/pnpm 任务编排不属于本技能范围。具体当前版本请在安装时确认。