Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Configuration for prettier
Dantis Mai
Dantis Mai

Posted on • Edited on

     

Configuration for prettier

prettier

What and Why prettier?

Prettier is a code formatter, which supports many kinds of language from Programming languages (JXS, TS), to Style sheets (CSS, SCSS), and also Serialization languages (YAML).

As we can see in the gif above, it will take a lot of time to arrange those lines, and even more for HTML.Prettier is the light from heaven, just saving the file everything will be in order

Configuration

My configuration

My beloved configuration is below

{  "singleQuote": true,  "trailingComma": "all",  "useTabs": false,  "tabWidth": 2,  "overrides": [    {      "files": "*.yaml",      "options": {        "tadWidth": 2,        "printWidth": 40,        "singleQuote": true      }    }  ]}
Enter fullscreen modeExit fullscreen mode

To use

npm

npm i --save-dev prettier

yarn

yarn add --dev prettier

- Create 2 files `.prettierrc`, `.prettierignore` in our root level, the former is for configuration and the latter is for ignoring directories. Usually, I ignore `build` and `coverage`, which is generated from build production package and test result corresponding.![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a2x74kcrk7v3nl2p6pph.png)- Done!!_Notes:_ Instead of `.prettierrc`, `prettier` also supports a wide range of types. Please take a look at [Configuration File](https://prettier.io/docs/en/configuration.html).##Other optionsYou can find more interesting ways to use it in [prettier documentation](https://prettier.io/docs/en/options.html), such as lint-staged, pre-commit, and so on.I usually due with CloudFormation, so besides a general configuration, I `overrides` it with my favorite style for `.yaml`. You can find your own one while [playing around](https://prettier.io/playground/) with it.![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xbaqumw7c2ykkwgxbfxi.png)[Paypal](https://paypal.me/DantisMai)._I hope this post helps you find your style in your developer journey. I am really happy to receive your feedback on this article. Thanks for your precious time reading this._
Enter fullscreen modeExit fullscreen mode

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
jonrandy profile image
Jon Randy 🎖️
🤖 Artisanal developer - coding with varying degrees of success since 1983
  • Location
    Bangkok 🇹🇭
  • Joined
• Edited on• Edited

Seriously considering dumping 'Prettier' - it breaks code far too often. It shouldn't be necessary to re-test code after running a code formatter

CollapseExpand
 
maithanhdanh profile image
Dantis Mai
I'm currently a Backend engineer and I love it a lot

It will take a lot of effort to clean the code without Prettier. Can you show me your configuration, and which language it breaks

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I'm currently a Backend engineer and I love it a lot
  • Location
    Vietnam
  • Work
    Backend engineer at NAB
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp