{"id":2779,"date":"2025-02-11T12:37:32","date_gmt":"2025-02-11T17:37:32","guid":{"rendered":"https:\/\/csimmons.dev\/blog\/?p=2779"},"modified":"2025-02-11T12:50:23","modified_gmt":"2025-02-11T17:50:23","slug":"prettier-with-a-sample-prettierrc-and-explanation-of-options","status":"publish","type":"post","link":"https:\/\/csimmons.dev\/blog\/2025\/02\/prettier-with-a-sample-prettierrc-and-explanation-of-options\/","title":{"rendered":"Prettier with a sample .prettierrc and explanation of options"},"content":{"rendered":"<figure id=\"attachment_2781\" aria-describedby=\"caption-attachment-2781\" style=\"width: 290px\" class=\"wp-caption alignnone\"><img width=\"300\" height=\"199\" data-public-id=\"shutterstock_552454006\/shutterstock_552454006.jpg\" loading=\"lazy\" decoding=\"async\" class=\"wp-post-2779 wp-image-2781 size-medium\" src=\"https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_300,h_199,c_scale\/f_auto,q_auto\/v1739292822\/shutterstock_552454006\/shutterstock_552454006.jpg?_i=AA\" alt=\"A cute and smart dog wearing glasses\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1739292822\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_300,h_199,c_scale\/f_auto,q_auto\/v1739292822\/shutterstock_552454006\/shutterstock_552454006.jpg?_i=AA 300w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_1024,h_678,c_scale\/f_auto,q_auto\/v1739292822\/shutterstock_552454006\/shutterstock_552454006.jpg?_i=AA 1024w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_768,h_509,c_scale\/f_auto,q_auto\/v1739292822\/shutterstock_552454006\/shutterstock_552454006.jpg?_i=AA 768w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_1536,h_1017,c_scale\/f_auto,q_auto\/v1739292822\/shutterstock_552454006\/shutterstock_552454006.jpg?_i=AA 1536w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_2048,h_1356,c_scale\/f_auto,q_auto\/v1739292822\/shutterstock_552454006\/shutterstock_552454006.jpg?_i=AA 2048w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-2781\" class=\"wp-caption-text\">A dog with glasses ready to do new tricks<\/figcaption><\/figure>\n<p>I&#8217;ve worked on a team of one for a very long time. I appreciate the level of autonomy that I have, but I&#8217;ve noticed now more than ever that it can facilitate bad habits and laziness. Luckily, in the modern era of coding there are tools that can help encourage (or flat out enforce) good habits in code formatting and style. My latest attempt to start cleaning up some bad habits is to use <a href=\"https:\/\/prettier.io\/\" target=\"_blank\" rel=\"noopener\">Prettier<\/a> (an opinionated code formatter) in all my projects rather than selectively.<\/p>\n<p>Rather than me going deep into the how and the why for using Prettier I&#8217;d recommend reading this <a href=\"https:\/\/prettier.io\/docs\/why-prettier\" target=\"_blank\" rel=\"noopener\">explanation<\/a>.<\/p>\n<p>If you use VSCode like I do then you first need to install the Prettier extension.\u00a0 Once you have done that you can try out the sample .prettierrc file below by placing it in the root of your project(s).\u00a0 The .prettierrc file is the configuration file that will allow you to set the Prettier options in a way that makes sense for your project. I&#8217;m trying to mostly use defaults (i.e. good habits), but there are a few options I prefer, or they are so engrained in legacy code that I maintain that changing them would be a Herculean effort.<\/p>\n<p>Once the .prettierrc file is in place&#8230;<\/p>\n<p>To format a document in VSCode:<\/p>\n<ol>\n<li>Use a Shortcut:\n<ul>\n<li>Windows\/Linux: Press <code>Shift + Alt + F<\/code><\/li>\n<li>Mac: Press <code>Shift + Option + F<\/code><\/li>\n<\/ul>\n<\/li>\n<li>Use the Command Palette:\n<ul>\n<li>Open the Command Palette with <code>Ctrl + Shift + P<\/code> (Windows\/Linux) or <code>Cmd + Shift + P<\/code> (Mac).<\/li>\n<li>Type <code>\"Format Document\"<\/code> and press Enter.<\/li>\n<\/ul>\n<\/li>\n<li>Auto-format on Save (optional):\n<ul>\n<li>Go to <strong>Settings<\/strong> (<code>Ctrl + ,<\/code> or <code>Cmd + ,<\/code>), search for <code>\"format on save\"<\/code>, and enable it by checking <strong>Editor: Format On Save<\/strong>.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>Below is a gist containing two files. The first file is the sample .prettierrc.\u00a0 The second file is a README which actually includes the contents of the .prettierrc file and explains the options.<\/p>\n<h2>The gist:<\/h2>\n<p><script src=\"https:\/\/gist.github.com\/ccsimmons\/7daf8ec72d296bdf74b9369bc6b61313.js\"><\/script><\/p>\n<p>You don&#8217;t have to use a .prettierrc file. You can set up your options directly in the Prettier extension&#8217;s settings. However, I&#8217;m using the .prettierrc file so it is clear what options are being enforced on any given project.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve worked on a team of one for a very long time. I appreciate the level of autonomy that I have, but I&#8217;ve noticed now more than ever that it can facilitate bad habits and laziness. Luckily, in the modern era of coding there are tools that can help encourage (or flat out enforce) good &#8230; <a title=\"Prettier with a sample .prettierrc and explanation of options\" class=\"read-more\" href=\"https:\/\/csimmons.dev\/blog\/2025\/02\/prettier-with-a-sample-prettierrc-and-explanation-of-options\/\" aria-label=\"Read more about Prettier with a sample .prettierrc and explanation of options\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_cloudinary_featured_overwrite":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[68],"tags":[74],"class_list":["post-2779","post","type-post","status-publish","format-standard","hentry","category-developer","tag-prettier"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pbVg43-IP","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts\/2779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/comments?post=2779"}],"version-history":[{"count":0,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts\/2779\/revisions"}],"wp:attachment":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/media?parent=2779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/categories?post=2779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/tags?post=2779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}