更漂亮的是不纠正某些代码行的 printWidth

prettier not correcting for printWidth for certain lines of code

有一些代码行 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 的一个已知问题,其中某些代码行必须手动更正吗?

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

This is actually intended. We have a special case for import and require with single elements where we keep them in a single line. You don't get much more information when they are in two lines and they look worse with a series of imports. This was done due to common request from people using prettier.