prettier-compare
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePurpose
用途
Use to inspect any differences between Biome and Prettier formatting (including IR output) before shipping formatter changes.
packages/prettier-compare/在发布格式化工具变更前,使用检查Biome与Prettier的格式化差异(包括IR输出)。
packages/prettier-compare/Prerequisites
前置条件
- Run every command from the repository root so relative paths resolve correctly.
- Use (the CLI is a Bun script) and ensure dependencies have been installed.
bun - Always pass so the Biome WASM bundle matches your current Rust changes.
--rebuild
- 所有命令均需在仓库根目录执行,以确保相对路径解析正确。
- 使用(该CLI是一个Bun脚本),并确保已安装依赖。
bun - 务必添加参数,确保Biome WASM包与当前Rust代码变更匹配。
--rebuild
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.tsxRead 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 jsTips
提示
- Use when formatting code without an extension so both formatters pick the correct parser.
-l/--language - Use for large samples or snapshot tests so you can iterate directly on project fixtures.
-f/--file - Reference for deeper CLI details; mirror any updates here, keeping the hard requirement that commands include
packages/prettier-compare/README.md.--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