Search code examples
javascriptprettier

prettier not correcting for printWidth for certain lines of code


There are some lines of code where Prettier (we're using 2.2.1) doesn't autocorrect for printWidth.

For example, if printWidth is reduced to 70, this line:

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

gets converted to:

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

But this line is never autocorrected regardless of how low I set the printWidth value:

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

Is this a known issue with prettier where certain lines of code have to be manually corrected?


Solution

  • Right after I posted this question, I found this comment on the Prettier GitHub repo which indicates that it's by design that prettier prioritizes the rule of keeping import statements on a single line:

    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.