Skip to content

Instantly share code, notes, and snippets.

@navix
Last active September 12, 2023 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navix/b2559d93b391f211e08af8be13330fe5 to your computer and use it in GitHub Desktop.
Save navix/b2559d93b391f211e08af8be13330fe5 to your computer and use it in GitHub Desktop.
My Prettier setup for Angular apps
$ npm i prettier prettier-plugin-css-order prettier-plugin-organize-attributes css-declaration-sorter -D

Create .prettierrc file:

{
  "printWidth": 120,
  "tabWidth": 2,
  "useTabs": false,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "all",
  "bracketSpacing": false,
  "arrowParens": "avoid",
  "htmlWhitespaceSensitivity": "ignore",
  "singleAttributePerLine": true,
  "attributeGroups": [
    "$ANGULAR_STRUCTURAL_DIRECTIVE",
    "$ANGULAR_INPUT",
    "$ANGULAR_TWO_WAY_BINDING",
    "$ANGULAR_OUTPUT"
  ],
  "attributeSort": "ACS",
  "cssDeclarationSorterOrder": "alphabetical",
  "plugins": ["prettier-plugin-organize-attributes", "prettier-plugin-css-order"]
}

Create .prettierignore:

.angular
.vscode
dist
node_modules
.*
*.yaml
*.sh
*.json
*.md

Add scripts to package.json:

  "prettier:check": "npx prettier --check .",
  "prettier:write": "npx prettier --write ."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment