格式化程序选项理念
💡 Biome 遵循相同的 选项哲学为 Prettier。现有的格式化选项集被认为是稳定的,不太可能考虑新的选项。
¥💡 Biome follows the same Option Philosophy as Prettier. The existing set of options for formatting is considered stable, and new options are not likely to be considered.
本文档解释了 Biome 如何以及为何发展到今天这一步的历史,以及对未来的展望。
¥This document explains some history about how and why Biome got to where it is today, and an outlook for the future.
Biome 是一个有态度的格式化程序。在理想情况下,这意味着 Biome 假设只有一种正确的格式化方式,并将始终强制执行该样式。无论是什么项目,无论设置如何,Biome 格式化的代码总是看起来一样。从另一个角度来看,Biome 是它自己的自动样式指南,而不是实现其他样式指南的工具。
¥Biome is an opinionated formatter. In an ideal world, that means Biome assumes there is only one correct way to format things and will enforce that style at all times. No matter the project, no matter the setup, code formatted by Biome will always look the same. From another perspective, Biome is its own automatic style guide, not a tool for implementing other style guides.
对格式有如此强烈的意见似乎有些过分,但采用后,好处很快就会显现出来。关于空格应该放在哪里、是否应该分行、是否应该缩进行等讨论都消失了。琐碎的、自行车棚讨论 不再分散对重要事项的关注。代码格式化程序(例如 prettier 和 Biome)始终在参数或箭头函数的主体周围添加括号。只需相信 Biome 会尽最大努力干净、清晰和一致地格式化代码。
¥Having such a strong opinion on formatting may seem heavy-handed, but the benefits quickly become clear after adoption. All of the discussions about where spaces should go, whether a line should be broken out, whether a line should be indented, and so many more simply vanish. Trivial, bike-shedding discussions no longer distract from focusing on what matters. Code reviews become free of re-formatting requests and cyclical debates. All it takes is trust that Biome does its best to format code cleanly, legibly, and consistently.
除了在各个团队和组织中的好处之外,在整个 Web 生态系统中采用一致的格式化程序对每个人都有好处,使得在项目之间移动时更容易保持熟悉,并帮助新手更直观地学习和识别模式而不会分心。
¥Beyond the benefits within individual teams and organizations, the adoption of consistent formatters across the whole web ecosystem benefits everyone, making it easier to retain familiarity when moving between projects and helping newcomers learn and recognize patterns more intuitively without distractions.
在当今的网络生态系统中,Prettier 是迄今为止最受欢迎的代码格式化程序,并且它具有强烈的主观性,带有 添加选项的严格理念。Biome 旨在成为 与 Prettier 基本兼容,因此,它采纳了 Prettier 实现的许多意见,配置也不例外。
¥In the web ecosystem today, Prettier is by far the most popular code formatter, and it is also strongly opinionated, with a strict philosophy on adding options. Biome aims to be largely compatible with Prettier, and as such, has adopted many of the opinions that Prettier implements, and configuration is no exception to that.
Biome 很自豪能够与 Prettier 达到如此高的兼容性,并使用户的迁移路径尽可能轻松,但这也伴随着类似的警告。
¥Biome is proud to have reached such high compatibility with Prettier and make the migration path for users as painless as possible, but this also comes with similar caveats.
¥Existing Options
Biome 从一个严格的配置选项子集开始,针对 JavaScript 生态系统中最常见和最有争议的样式指南:缩进样式(制表符与空格)、缩进宽度(2 个空格等于 1 个制表符,还是 4 个?)和强制分号。添加这些点的选项被认为足以满足大多数人的需求,并且没有强烈考虑添加任何其他选项。
¥Biome started out with a strict subset of configuration options, targeting the most common and contentious style guidelines in the JavaScript ecosystem: indent styles (tabs vs spaces), indent widths (2 spaces to equal a tab, or 4?), and enforced semicolons. Adding options for these points was considered sufficient enough to address most people’s needs, and there was no strong consideration for adding any others.
依靠 Prettier 选项哲学,Biome 有机会重新开始并避免 Prettier 在其其他现有选项(如 --bracket-same-line
和 --arrow-parens
)中陷入的陷阱:
¥Leaning on the Prettier Option Philosophy, Biome had the chance to start fresh and avoid the pitfalls that Prettier had fallen into with its other existing options, like --bracket-same-line
and --arrow-parens
:
…[这些] 不是我们乐于拥有的选项类型。它们导致团队中出现大量自行车停放问题,我们对此深表歉意。现在很难删除,这些选项作为历史遗留物存在,不应成为添加更多选项的动机(“如果这些选项存在,为什么这个选项不能有?”)。
¥…[these] are not the type of options we’re happy to have. They cause a lot of bike-shedding in teams, and we’re sorry for that. Difficult to remove now, these options exist as a historical artifact and should not motivate adding more options (“If those options exist, why can’t this one?”).
但是,当 Prettier 挑战赛已公布 出现时,Biome 决定接受挑战,这需要实现 Prettier 实现完全兼容所需的所有配置选项。
¥However, when the Prettier Challenge was announced, Biome decided to accept the challenge, which required implementing all of the configuration options that Prettier had to achieve full compatibility.
Biome 仍然分享 Prettier 关于这些选项的理念,并将它们视为兼容性的遗留功能,而不是基线功能集。它们的存在并不表示将添加更多选项,也不应将它们用作支持将来存在其他选项的理由。
¥Biome still shares Prettier’s philosophy about these options and considers them a legacy feature for compatibility rather than a baseline feature set. Their existence does not indicate that more options will be added, nor should they be used as a rationale to support the existence of other options in the future.
¥New Options
与 Prettier 非常相似,Biome 认为当前的选项集是稳定的、足够的,并且不接受添加或其他更改。对其他配置选项的请求不太可能被考虑,可能会在未经讨论的情况下关闭。
¥Much like Prettier, Biome believes the current set of options is stable, sufficient, and not open for additions or other changes. Requests for additional configuration options are not likely to be considered and may be closed without discussion.
尽管如此,即使 Biome 已经确立了自己作为强大而强大的格式化工具的地位,它也仍然相对较新,这意味着有很多机会为新的进步和想法铺平道路,否则这些进步和想法可能看起来不可行。
¥That said, even as Biome has established itself as a capable and robust formatting tool, it is also still relatively new, meaning there is plenty of opportunity to pave the way for new advancements and ideas that may not seem feasible otherwise.
Biome 的格式化样式也被认为是相对稳定的,继续尽可能地与 Prettier 和 一些故意的偏差 匹配。对配置的更改导致不同的格式或更多报告的 lint 错误(添加/删除选项,更改默认值)不过,这些也不太可能成为可配置选项,而是会普遍适用于所有未来版本的 Biome。
¥The formatting style of Biome is also considered relatively stable, continuing to match Prettier as much as possible, with few intentional deviations. Changes to the style of Biome may be considered and implemented. Still, these are also unlikely to become configurable options and would instead be applied universally for all future versions of Biome.