Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prettier.js Method Arguments on newline formatting

Tags:

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 } 
like image 593
Jordan Avatar asked Aug 08 '17 10:08

Jordan


People also ask

Should I use Prettier with ESLint?

Benefits of using Prettier and ESLint As mentioned earlier, whereas Prettier takes care of your code formatting, ESLint takes care of your code style. The former does everything automatically for you. If you have set up Prettier, you can configure it to format your file on saving it.

What is Prettier printWidth?

The printWidth option is more of a guideline to Prettier than a hard rule. It is not the upper allowed line length limit. It is a way to say to Prettier roughly how long you'd like lines to be. Prettier will make both shorter and longer lines, but generally strive to meet the specified print width.

Why You Should Use Prettier?

Prettier enforces a consistent code style (i.e. code formatting that won't affect the AST) across your entire codebase because it disregards the original styling* by parsing it away and re-printing the parsed AST with its own rules that take the maximum line length into account, wrapping code when necessary.


1 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)

like image 193
Binh Avatar answered Sep 17 '22 19:09

Binh