选项哲学
由于历史原因,Prettier 有一些选项。但我们不会添加更多。
¥Prettier has a few options because of history. But we won’t add more of them.
请继续阅读以了解更多信息。
¥Read on to learn more.
Prettier 不是一个厨房水槽代码格式化程序,它试图以你希望的任何方式打印你的代码。这是有态度的。引用 为什么 Prettier? 页面:
¥Prettier is not a kitchen-sink code formatter that attempts to print your code in any way you wish. It is opinionated. Quoting the Why Prettier? page:
到目前为止,采用 Prettier 的最大原因是为了停止所有正在进行的关于风格的争论。
¥By far the biggest reason for adopting Prettier is to stop all the ongoing debates over styles.
然而 Prettier 的选项越多,它离上述目标就越远。关于风格的争论只会变成关于使用哪个 Prettier 选项的争论。格式化战争以新的活力爆发:“哪个选项值更好?为什么?我们的选择正确吗?”
¥Yet the more options Prettier has, the further from the above goal it gets. The debates over styles just turn into debates over which Prettier options to use. Formatting wars break out with renewed vigour: “Which option values are better? Why? Did we make the right choices?”
这不是唯一的成本选择。要详细了解它们的缺点,请参阅 关于拒绝添加配置的问题,它比任何选项请求问题都有更多的 👍。
¥And it’s not the only cost options have. To learn more about their downsides, see the issue about resisting adding configuration, which has more 👍s than any option request issue.
那么为什么还有选项呢?
¥So why are there any options at all?
在 Prettier 的初期添加了一些以使其起飞。🚀
¥A few were added during Prettier’s infancy to make it take off at all. 🚀
在“需求很大”后添加了一些。 🤔
¥A couple were added after “great demand.” 🤔
出于兼容性原因添加了一些。👍
¥Some were added for compatibility reasons. 👍
更容易促进的选项包括:
¥Options that are easier to motivate include:
--trailing-comma es5
允许你在大多数环境中使用尾随逗号而无需转译(ES2017 中添加了尾随函数逗号)。¥
--trailing-comma es5
lets you use trailing commas in most environments without having to transpile (trailing function commas were added in ES2017).--prose-wrap
对于在野支持所有古怪的 Markdown 渲染器很重要。¥
--prose-wrap
is important to support all quirky Markdown renderers in the wild.--html-whitespace-sensitivity
是需要的,因为不幸的 HTML 空白规则。¥
--html-whitespace-sensitivity
is needed due to the unfortunate whitespace rules of HTML.--end-of-line
使团队更容易将 CRLF 排除在他们的 git 存储库之外。¥
--end-of-line
makes it easier for teams to keep CRLFs out of their git repositories.--quote-props
对于 Google Closure Compiler 的高级使用很重要。¥
--quote-props
is important for advanced usage of the Google Closure Compiler.
但事后看来,其他选项更难促进:--arrow-parens
、--jsx-single-quote
、--bracket-same-line
和 --no-bracket-spacing
不是我们乐于拥有的选项类型。他们在团队中造成了很多 浪费时间和精力讨论无意义的或意义不大的技术问题,我们对此感到抱歉。现在很难删除,这些选项作为历史工件存在,不应该激励添加更多选项(“如果这些选项存在,为什么这个不能?”)。
¥But other options are harder to motivate in hindsight: --arrow-parens
, --jsx-single-quote
, --bracket-same-line
and --no-bracket-spacing
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 的使用量增长了很多。过去的“巨大需求”如今已不复存在。GitHub 反应和 Twitter 民意调查变得不具代表性。所有沉默的用户呢?添加“再一个”选项看起来很容易。但是我们应该在哪里停下来呢?什么时候太多了?即使添加了“最后一个选项”后,问题跟踪器中仍然会出现“首要问题”。
¥For a long time, we left option requests open in order to let discussions play out and collect feedback. What we’ve learned during those years is that it’s really hard to measure demand. Prettier has grown a lot in usage. What was “great demand” back in the day is not as much today. GitHub reactions and Twitter polls became unrepresentative. What about all silent users? It looked easy to add “just one more” option. But where should we have stopped? When is one too many? Even after adding “that one final option”, there would always be a “top issue” in the issue tracker.
然而,停止的时候到了。现在 Prettier 已经足够成熟,我们看到它被许多组织和项目采用,研究阶段已经结束。我们有足够的信心得出这样的结论:Prettier 已经达到了应该“冻结”选项集的地步。不再接受选项请求。我们感谢所有参与这一艰难旅程的人。
¥However, the time to stop has come. Now that Prettier is mature enough and we see it adopted by so many organizations and projects, the research phase is over. We have enough confidence to conclude that Prettier reached a point where the set of options should be “frozen”. Option requests aren’t accepted anymore. We’re thankful to everyone who participated in this difficult journey.
请注意,由于选项请求超出了 Prettier 的范围,因此它们将在没有讨论的情况下关闭。这同样适用于保留输入格式元素(例如换行符)的请求,因为这只不过是一个伪装的选项,具有“真实”选项的所有缺点。可能存在由于技术需要(例如兼容性)而无法避免添加选项的情况,但对于与格式相关的选项,这是最终的。
¥Please note that as option requests are out of scope for Prettier, they will be closed without discussion. The same applies to requests to preserve elements of input formatting (e.g. line breaks) since that’s nothing else but an option in disguise with all the downsides of “real” options. There may be situations where adding an option can’t be avoided because of technical necessity (e.g. compatibility), but for formatting-related options, this is final.