Prettier (.prettierrc)

Notes & Setup

  • Additional Setup:

    • "on save":

      • Cmd+Shift+P > Preferences: Open [Workspace/User/...] Settings (JSON)

{
  "editor.formatOnSave": true
}
{
  // Optionally, specify formatting for specific file types
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[javascriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

Aaron's Personal Preference
{
	"semi": false,
	"singleQuote": true,
	"tabWidth": 2,
	"trailingComma": "es5",
	"jsxBracketSameLine": false,
	"arrowParens": "always",
	"bracketSpacing": true,
	"useTabs": false
}
Additional Options
  1. endOfLine (End of Line):

    • Option: "endOfLine": "lf", "crlf", "cr", or "auto"

    • Use: Ensures a consistent line ending style across various operating systems.

    • Popularity: "lf" (line feed) is commonly used in Unix/Linux/macOS environments, while "crlf" (carriage return and line feed) is often preferred in Windows environments. "auto" maintains existing line endings.

  2. htmlWhitespaceSensitivity (HTML Whitespace Sensitivity):

    • Option: "htmlWhitespaceSensitivity": "css", "strict", or "ignore"

    • Use: Controls how whitespaces in HTML, Vue, Angular, and Handlebars are handled.

    • Popularity: "css" respects the display property in CSS, making it a balanced choice for projects where HTML is styled with CSS.

  3. jsxSingleQuote (Single Quotes in JSX):

    • Option: "jsxSingleQuote": true or false

    • Use: Uses single quotes instead of double quotes in JSX.

    • Popularity: This is useful for developers who prefer single quotes for consistency with JavaScript code, although JSX resembles HTML which typically uses double quotes.

  4. quoteProps (Object Property Quoting):

    • Option: "quoteProps": "as-needed", "consistent", or "preserve"

    • Use: Controls when quotes around object properties are required.

    • Popularity: "as-needed" only adds quotes when necessary, which is cleaner, while "consistent" requires all properties in an object to be quoted if at least one needs it, ensuring uniformity.

  5. requirePragma (Require Prettier Pragma):

    • Option: "requirePragma": true or false

    • Use: Prettier will only format files that contain a special comment, called a pragma, at the top.

    • Popularity: Useful in large codebases where gradually introducing Prettier. It allows developers to mark files that are ready for Prettier formatting.

  6. insertPragma (Insert Prettier Pragma):

    • Option: "insertPragma": true or false

    • Use: When a file is formatted with Prettier, it inserts a pragma at the top of the file.

    • Popularity: Handy for automatically marking files as formatted by Prettier, especially in combination with requirePragma.

  7. proseWrap (Prose Wrapping):

    • Option: "proseWrap": "always", "never", or "preserve"

    • Use: Controls how Markdown and other prose are wrapped.

    • Popularity: "always" ensures consistent line lengths in Markdown, which can be important for readability in certain editors or diff tools.

  8. vueIndentScriptAndStyle (Vue Files Script and Style Tag Indentation):

    • Option: "vueIndentScriptAndStyle": true or false

    • Use: Determines whether <script> and <style> tags in Vue files should be indented.

    • Popularity: Setting this to true can improve readability in Vue single-file components by visually separating the script and style sections from the template.

Last updated