migrate-oxfmt
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseThis skill guides you through migrating a JavaScript/TypeScript project from Prettier or Biome to Oxfmt.
本技能将指导你完成将JavaScript/TypeScript项目从Prettier或Biome迁移至Oxfmt的流程。
Overview
概述
Oxfmt is a high-performance, Prettier-compatible code formatter. Most Prettier options are supported directly.
An automated migration tool is built into oxfmt, supporting both Prettier and Biome as migration sources.
Oxfmt是一款高性能、兼容Prettier的代码格式化工具。大多数Prettier选项都直接受支持。
Oxfmt内置了自动化迁移工具,支持将Prettier和Biome作为迁移来源。
Step 1: Run Automated Migration
步骤1:运行自动化迁移
From Prettier
从Prettier迁移
bash
npx oxfmt@latest --migrate prettierThis will:
- Find and read your Prettier config (any format Prettier supports)
- Create with migrated options
.oxfmtrc.json - Migrate patterns to
.prettierignoreignorePatterns - Migrate options to
prettier-plugin-tailwindcsssortTailwindcss - Detect and enable
prettier-plugin-packagejsonsortPackageJson
bash
npx oxfmt@latest --migrate prettier此命令将:
- 查找并读取你的Prettier配置(支持Prettier的任何格式)
- 创建包含迁移后选项的文件
.oxfmtrc.json - 将中的规则迁移至
.prettierignoreignorePatterns - 将的选项迁移至
prettier-plugin-tailwindcsssortTailwindcss - 检测并启用
prettier-plugin-packagejsonsortPackageJson
From Biome
从Biome迁移
bash
npx oxfmt@latest --migrate biomeThis will:
- Find and read or
biome.jsonbiome.jsonc - Create with migrated options
.oxfmtrc.json - Migrate negated patterns from to
files.includesignorePatterns - Map Biome's two-level config (and
formatter.*) to oxfmt optionsjavascript.formatter.*
Biome option mapping:
| Biome | oxfmt |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
Notes (both sources):
- Fails if already exists. Delete it first if you want to re-run.
.oxfmtrc.json - If no source config is found, creates a blank instead.
.oxfmtrc.json - cannot be auto-migrated for either source and must be converted manually.
overrides
bash
npx oxfmt@latest --migrate biome此命令将:
- 查找并读取或
biome.jsonbiome.jsonc - 创建包含迁移后选项的文件
.oxfmtrc.json - 将中的否定规则迁移至
files.includesignorePatterns - 将Biome的两级配置(和
formatter.*)映射为oxfmt选项javascript.formatter.*
Biome选项映射:
| Biome | oxfmt |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
注意事项(两种迁移来源通用):
- 如果已存在,迁移会失败。若需重新运行,请先删除该文件。
.oxfmtrc.json - 如果未找到来源配置,将创建一个空白的文件。
.oxfmtrc.json - 无法从任何来源自动迁移,必须手动转换。
overrides
Step 2: Review Generated Config
步骤2:检查生成的配置
After migration, review the generated for these key differences:
.oxfmtrc.json迁移完成后,检查生成的,注意以下关键差异:
.oxfmtrc.jsonprintWidth
printWidth
Prettier and Biome default is 80, oxfmt default is 100. The migration tool sets if not specified in your source config. Decide whether to keep 80 or adopt 100.
printWidth: 80Prettier和Biome的默认值为80,oxfmt的默认值为100。如果来源配置中未指定该选项,迁移工具会设置。请决定是保留80还是改用100。
printWidth: 80Unsupported Options (Prettier only)
不支持的选项(仅Prettier)
These Prettier options are skipped during migration:
| Option | Status |
|---|---|
| Not supported. Use |
| Not supported in JS/TS files yet |
| Not supported in JS/TS files yet |
以下Prettier选项在迁移时会被跳过:
| 选项 | 状态 |
|---|---|
| 不支持。请显式使用 |
| 暂不支持在JS/TS文件中使用 |
| 暂不支持在JS/TS文件中使用 |
sortPackageJson (Prettier only)
sortPackageJson(仅Prettier)
Enabled by default in oxfmt, but the migration tool disables it unless was detected. Review whether you want this enabled.
prettier-plugin-packagejsonNote: Oxfmt's sorting algorithm differs from .
prettier-plugin-packagejsonoxfmt默认启用该选项,但迁移工具仅在检测到时才会启用它。请检查是否需要启用该选项。
prettier-plugin-packagejson注意:Oxfmt的排序算法与不同。
prettier-plugin-packagejsonembeddedLanguageFormatting (Prettier only)
embeddedLanguageFormatting(仅Prettier)
Embedded language formatting (e.g., CSS-in-JS) generally works, but some formatting may differ from Prettier.
嵌入式语言格式化(如CSS-in-JS)通常可以正常工作,但某些格式化结果可能与Prettier不同。
overrides
overrides
The field cannot be auto-migrated from either Prettier or Biome. Convert manually:
overridesjson
{
"overrides": [
{
"files": ["*.md"],
"options": { "tabWidth": 4 }
}
]
}overridesjson
{
"overrides": [
{
"files": ["*.md"],
"options": { "tabWidth": 4 }
}
]
}Nested Config
嵌套配置
Oxfmt does not support nested configuration files (e.g., a separate in a subdirectory). If your project used per-directory Prettier or Biome configs, consolidate them using with file glob patterns, or run oxfmt separately per directory with different working directories.
.oxfmtrc.jsonoverridesOxfmt不支持嵌套配置文件(例如子目录中的独立)。如果你的项目使用了按目录划分的Prettier或Biome配置,请使用带有文件通配符的合并它们,或者在不同目录中分别运行oxfmt并指定不同的工作目录。
.oxfmtrc.jsonoverridesPrettier-Compatible Options
兼容Prettier的选项
These options transfer directly with the same behavior:
, , , , , , , , , , , , , ,
tabWidthuseTabssemisingleQuotejsxSingleQuotequotePropstrailingCommaarrowParensbracketSpacingbracketSameLineendOfLineproseWraphtmlWhitespaceSensitivitysingleAttributePerLinevueIndentScriptAndStyle以下选项可直接迁移,且行为一致:
, , , , , , , , , , , , , ,
tabWidthuseTabssemisingleQuotejsxSingleQuotequotePropstrailingCommaarrowParensbracketSpacingbracketSameLineendOfLineproseWraphtmlWhitespaceSensitivitysingleAttributePerLinevueIndentScriptAndStyleStep 3: Configure Oxfmt Extensions
步骤3:配置Oxfmt扩展功能
Oxfmt offers features not available in Prettier:
Oxfmt提供了Prettier没有的功能:
sortImports
sortImports
Sort import statements, inspired by (disabled by default):
eslint-plugin-perfectionist/sort-importsjson
{
"sortImports": {
"partitionByNewline": true,
"newlinesBetween": false
}
}对导入语句进行排序,灵感来自(默认禁用):
eslint-plugin-perfectionist/sort-importsjson
{
"sortImports": {
"partitionByNewline": true,
"newlinesBetween": false
}
}sortTailwindcss
sortTailwindcss
Replaces . Auto-migrated with renamed options:
prettier-plugin-tailwindcss| Prettier (top-level) | oxfmt ( |
|---|---|
| |
| |
| |
| |
| |
| |
替代。迁移时会自动重命名选项:
prettier-plugin-tailwindcss| Prettier(顶层) | oxfmt ( |
|---|---|
| |
| |
| |
| |
| |
| |
Other Extensions
其他扩展功能
| Option | Default | Description |
|---|---|---|
| | Whether to add a final newline at end of file |
| | Sort |
| 选项 | 默认值 | 描述 |
|---|---|---|
| | 是否在文件末尾添加最终换行符 |
| | 对 |
Step 4: Update CI and Scripts
步骤4:更新CI和脚本
Replace formatter commands with oxfmt:
bash
undefined将格式化工具命令替换为oxfmt:
bash
undefinedBefore (Prettier)
之前(Prettier)
npx prettier --write .
npx prettier --check .
npx prettier --write .
npx prettier --check .
Before (Biome)
之前(Biome)
npx biome format --write .
npx biome check .
npx biome format --write .
npx biome check .
After
之后
npx oxfmt@latest
npx oxfmt@latest --check
undefinednpx oxfmt@latest
npx oxfmt@latest --check
undefinedCommon CLI Options
常见CLI选项
| Prettier / Biome | oxfmt |
|---|---|
| |
| |
| |
| |
| |
| |
| Prettier / Biome | oxfmt |
|---|---|
| |
| |
| |
| |
| |
| |
File Type Coverage
文件类型支持
- JS/TS: Formatted natively by oxfmt
- TOML: Formatted natively (via taplo)
- CSS, HTML, YAML, Markdown, GraphQL, etc.: Delegated to Prettier internally (when using )
npx oxfmt
- JS/TS:由oxfmt原生格式化
- TOML:由oxfmt原生格式化(通过taplo)
- CSS、HTML、YAML、Markdown、GraphQL等:内部委托给Prettier处理(使用时)
npx oxfmt
Tips
小贴士
- EditorConfig: Oxfmt reads automatically for
.editorconfig,useTabs,tabWidth,endOfLine, andinsertFinalNewline. Options inprintWidthtake precedence..oxfmtrc.json - CI: Use to enforce formatting in CI.
npx oxfmt@latest --check - LSP: Run for editor integration via Language Server Protocol.
oxfmt --lsp - Schema support: Add to
"$schema": "./node_modules/oxfmt/configuration_schema.json"for editor autocompletion..oxfmtrc.json - Init: Run to create a default
npx oxfmt@latest --initwithout migration..oxfmtrc.json
- EditorConfig:Oxfmt会自动读取中的
.editorconfig、useTabs、tabWidth、endOfLine和insertFinalNewline选项。printWidth中的选项优先级更高。.oxfmtrc.json - CI:使用在CI中强制执行格式化规范。
npx oxfmt@latest --check - LSP:运行通过语言服务器协议实现编辑器集成。
oxfmt --lsp - 架构支持:在中添加
.oxfmtrc.json可获得编辑器自动补全功能。"$schema": "./node_modules/oxfmt/configuration_schema.json" - 初始化:运行可创建默认的
npx oxfmt@latest --init文件,无需迁移。.oxfmtrc.json