【问题标题】:prettier not correcting for printWidth for certain lines of code更漂亮的不纠正某些代码行的 printWidth
【发布时间】:2021-03-06 15:59:36
【问题描述】:

有些代码行 Prettier(我们使用的是 2.2.1)不会自动更正 printWidth

例如,如果printWidth 减少到 70,则此行:

const DeckList = loadable(() => import('../components/Decks/DeckList'), {});

转换为:

const DeckList = loadable(
  () => import('../components/Decks/DeckList'),
  {}
);

但无论我将printWidth 值设置得有多低,这条线都不会自动更正:

import {openNotificationWithIcon} from 'Components/Notifications/Notification.js';

这是 prettier 的一个已知问题,必须手动更正某些代码行吗?

【问题讨论】:

    标签: javascript prettier


    【解决方案1】:

    在我发布这个问题之后,我发现this comment on the Prettier GitHub repo 这表明它是设计上更漂亮的优先考虑将导入语句保持在一行的规则:

    这实际上是有意的。我们有一个特殊的导入案例,并且需要单个元素,我们将它们保存在一行中。当它们在两行中时,您不会获得更多信息,并且它们在一系列导入时看起来更糟。这样做是因为使用 prettier 的人的共同要求。

    【讨论】:

      猜你喜欢
      • 2020-08-10
      • 2019-06-16
      • 2019-08-24
      • 2018-04-22
      • 2013-07-28
      • 1970-01-01
      • 1970-01-01
      • 2023-02-19
      • 1970-01-01
      相关资源
      最近更新 更多