33

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
}
Audwin Oyong
  • 2,247
  • 3
  • 15
  • 32
Jordan
  • 469
  • 1
  • 4
  • 5
  • 1
    It doesn't look very customizable: https://prettier.io/docs/en/options.html. Also in its description: "Prettier is an **opinionated** code formatter" – yuriy636 Aug 08 '17 at 10:23
  • Yeah I've seen that. But I know there are some commands (that they obviously list) that can be overridden. – Jordan Aug 08 '17 at 11:45
  • If this is just a problem in one file, you can put a .prettierignore file in your root, and write the file path (like w/ a .gitignore) to ignore that file – Maiya Jul 09 '20 at 02:01
  • Just add `// prettier-ignore` before the function. – vaughan Sep 26 '21 at 00:54

3 Answers3

11

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)

Binh
  • 346
  • 2
  • 14
10
  • In User Settings for Prettier:
    • Set Print Width option to 100 or more
Sebastian T F
  • 117
  • 1
  • 4
9

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
}
Marc
  • 13,011
  • 11
  • 78
  • 98
Feiga Lubow
  • 194
  • 3
  • 12
  • 2
    Might depend on the prettier version, but this one should probably be an integer instead (So `"printWidth":150`). Otherwise you will get `Invalid printWidth value. Expected an integer, but received "150".` – Daan Klijn Nov 27 '22 at 20:08