Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Webstorm use single quotes for prettier

I am looking for a way to change the double quotes (default behavior) to single quotes. I've read the docs and tried to search online but the normal way of doing it does not seem to work.

I've adapted the package.json in various ways, none have worked and this is my latest try:

"prettier": {
    "singleQuote": true
},

I don't know how to do it. The documentation is pretty bad on this one. They mention configs as well but I wouldn't know how to place them either.

Someone with a similar question: WebStorm: configure Prettier to use tabs?

like image 514
Spurious Avatar asked Mar 31 '18 09:03

Spurious


People also ask

How do I change my pretty settings on WebStorm?

From the main menu, select File | New Projects Setup | Settings/Preferences for New Projects. In the dialog that opens, go to Languages & Frameworks | JavaScript | Prettier. Use the On code reformatting and On save checkboxes to specify the actions that will trigger Prettier.

How do you change single quotes to double quotes in WebStorm?

Go to File -> Settings | Preferences. Choose Editor -> Code Style -> TypeScript. Select 'Punctuation' tab. Change: Use 'double' quotes to Use 'single' quotes .

How do I make the Prettier default formatter WebStorm?

You can also configure WebStorm to run Prettier on save (Cmd+S/Ctrl+S) or use it as the default formatter (Opt+Cmd+L/Ctrl+Alt+L). For this, open Preferences / Settings | Languages & Frameworks | JavaScript | Prettier and tick the corresponding checkbox: On save and/or On 'Reformat Code' action.


1 Answers

WebStorm allows importing code style preferences from prettier. For example:

enter image description here

press Yes to get settings applied - they will be used when you reformat your code with Code | Reformat code, as well as when running Reformat with Prettier action

Edit: Due to https://github.com/prettier/prettier/pull/2434 fix, Prettier (even global!) uses configuration file nearest to current file (up the directory tree) when formatting.

So, you can install it globally and configure it in your project, by adding the corresponding .prettierrc file or "prettier" section in project package.json.

like image 153
lena Avatar answered Oct 03 '22 08:10

lena