prettier-compare

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Purpose

用途

Use
packages/prettier-compare/
to inspect any differences between Biome and Prettier formatting (including IR output) before shipping formatter changes.
在发布格式化工具变更前,使用
packages/prettier-compare/
检查Biome与Prettier的格式化差异(包括IR输出)。

Prerequisites

前置条件

  1. Run every command from the repository root so relative paths resolve correctly.
  2. Use
    bun
    (the CLI is a Bun script) and ensure dependencies have been installed.
  3. Always pass
    --rebuild
    so the Biome WASM bundle matches your current Rust changes.
  1. 所有命令均需在仓库根目录执行,以确保相对路径解析正确。
  2. 使用
    bun
    (该CLI是一个Bun脚本),并确保已安装依赖。
  3. 务必添加
    --rebuild
    参数,确保Biome WASM包与当前Rust代码变更匹配。

Common workflows

常见工作流

Snippets passed as CLI args:
bun packages/prettier-compare/bin/prettier-compare.js --rebuild 'const x={a:1,b:2}'
Force a language (useful when the tool cannot infer it from a filename):
bun packages/prettier-compare/bin/prettier-compare.js --rebuild -l ts 'const x: number = 1'
Compare files on disk:
bun packages/prettier-compare/bin/prettier-compare.js --rebuild -f src/example.tsx
Read from stdin (great for piping editor selections):
echo 'const x = 1' | bun packages/prettier-compare/bin/prettier-compare.js --rebuild -l js
通过CLI参数传入代码片段:
bun packages/prettier-compare/bin/prettier-compare.js --rebuild 'const x={a:1,b:2}'
指定语言(当工具无法通过文件名推断语言时非常有用):
bun packages/prettier-compare/bin/prettier-compare.js --rebuild -l ts 'const x: number = 1'
对比本地文件:
bun packages/prettier-compare/bin/prettier-compare.js --rebuild -f src/example.tsx
从标准输入读取(适合配合编辑器选中内容管道输入):
echo 'const x = 1' | bun packages/prettier-compare/bin/prettier-compare.js --rebuild -l js

Tips

提示

  • Use
    -l/--language
    when formatting code without an extension so both formatters pick the correct parser.
  • Use
    -f/--file
    for large samples or snapshot tests so you can iterate directly on project fixtures.
  • Reference
    packages/prettier-compare/README.md
    for deeper CLI details; mirror any updates here, keeping the hard requirement that commands include
    --rebuild
    .
  • Use single quotes for code snippets passed as CLI arguments to avoid shell interpretation issues.
  • "\n" does not get escaped into a newline when passed as a CLI argument. You should write a literal newline or use a file instead.
  • 当格式化无扩展名的代码时,使用
    -l/--language
    参数,确保两个格式化工具都能选择正确的解析器。
  • 对于大样本或快照测试,使用
    -f/--file
    参数,以便直接在项目测试用例上迭代。
  • 如需更详细的CLI说明,请参考
    packages/prettier-compare/README.md
    ;此处内容需与该文档同步更新,且所有命令必须包含
    --rebuild
    参数。
  • 通过CLI参数传入代码片段时,请使用单引号,避免shell解析问题。
  • 作为CLI参数传入时,
    \n
    不会被解析为换行符。你应该直接输入换行,或使用文件传入。