Prettier.js Method Arguments on newline formatting

Viewed 15968

I'm running Prettier.js (VSCode plugin)/prettier-eslint-cli. It formats method arguments that go over the 80 character limit as the following (putting each argument on a new line).

someMethod(
  argumentOne,
  argumentTwo,
  argumentThree,
  argumentFour,
  argumentFive, // Hits 80 character word wrap here
  argumentSix,
  argumentSeven
) {
  // Some codes
}

Is there a way to modify the options so it formats the arguments to try to fit 80 characters on each row? Instead of just adding them to a new line each time.

someMethod(argumentOne, argumentTwo, argumentThree, argumentFour,
  argumentFive, argumentSix, argumentSeven) {
  // Some codes
}
3 Answers

As far as I know, for now, there isn't an option for doing so. When your arguments get over the printWidth ( default 80), prettier will break each argument into a separate line.

One way could be to increase the printWidth option so that your arguments stay on the same line. The prettier documentation mentions maximum line length rules are often set to 100 or 120 (https://prettier.io/docs/en/options.html)

  • In User Settings for Prettier:
    • Set Print Width option to 100 or more

Right click in the VSC window and select "command palette". Search "prettier" and select "create configuration file", its will open u select folder window (select the folder u want to save the prettier configuration file in), then open the configuration file and add the options you want to change . Example:

{
    "printWidth":"150"
}
Related