Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable printWidth on prettier

Tags:

Is there a way to disable the printWidth rule warning in prettier?

I want to be able to determine my own line length for readability. In certain cases I want a line break, and in other cases I don't.

I tried this in my .prettierrc file :

{
  "singleQuote": true,
  "printWidth" : "off"
}

But this does not work.

like image 582
Oliver Watkins Avatar asked Jan 23 '19 11:01

Oliver Watkins


People also ask

How do I disable prettier in Vscode?

prettier-vscode", If you want to disable Prettier for a specific language, you can set the editor. defaultFormatter to null .


Video Answer


1 Answers

The short answer is no, you cannot disable it entirely.

There are, however, a few workarounds, but they have caveats.

To quote an answer from this issue on github: https://github.com/prettier/prettier/issues/3468. printWidth is not a rule but an input into the algorithm they use to generate their output. Meaning, it is required to be there.

One workaround is to set printWidth to a really high number, but although this will prevent lines from breaking, changing this property will affect your entire codebase, causing other lines throughout it to combine into a single line, which is most likely not desired.

Your second option is to disable prettier for a block of code with the // prettier-ignore syntax. The downside to this is that you'll disable all prettier features for this section of the code. Also, I personally don't find it very "clean" to have comments like that all over your code. You can read about how to use the ignore functionality here: https://prettier.io/docs/en/ignore.html

like image 165
Jakob S. Rames Avatar answered Sep 22 '22 09:09

Jakob S. Rames