Skip to content

Latest commit

 

History

History
181 lines (136 loc) · 5.6 KB

File metadata and controls

181 lines (136 loc) · 5.6 KB

🌽 @codecorn/prettier-guide-community 🌍

🪶 Minimal, reliable Prettier setup for VSCode + npm + CI + Git hooks.
Predictable formatting, zero noise, team-friendly and community-driven.
Avoid conflicts, ignore only what’s necessary, and standardize across repos.


CODECORN - PRETTIER GUIDE GitHub Stars Issues License Prettier VSCode

If this guide helps you, please leave a ⭐ star and/or open a PR!

TL;DR

npm i -D prettier
npm set-script format "prettier --write ."
npm set-script "format:check" "prettier --check ."

.prettierrc.json

{
  "$schema": "https://json.schemastore.org/prettierrc",
  "tabWidth": 2,
  "useTabs": false,
  "printWidth": 100,
  "singleQuote": false,
  "trailingComma": "es5",
  "semi": true,
  "endOfLine": "lf"
}

.prettierignore

node_modules
dist
build
coverage
.vscode
.DS_Store

.vscode/settings.json

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "prettier.requireConfig": true,
  "files.eol": "\n"
}

Properly ignoring

  • Single line

    // prettier-ignore
    const x={a:1,b:2}
  • Block

    // prettier-ignore-start
    function demo() {
      return 1;
    }
    const x = { a: 1, b: 2 };
    // prettier-ignore-end
  • Whole file (must be first line)

    // prettier-ignore-file

For JS/TS use // (not /* */). Avoid Format Selection if you rely on ignores: prefer Format on Save / Format Document.

ESLint (optional)

npm i -D eslint-config-prettier eslint-plugin-prettier

Minimal .eslintrc:

{
  "extends": ["eslint:recommended", "plugin:prettier/recommended"]
}

CI (GitHub Actions, optional)

.github/workflows/prettier.yml

name: Prettier
on: { pull_request: {}, push: { branches: [main] } }
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 20 }
      - run: npm ci || npm i
      - run: npm run format:check

Quick troubleshooting

  1. Status bar should show Prettier as the formatter.
  2. With prettier.requireConfig: true you need a nearby .prettierrc.
  3. .editorconfig may override EOL/indent — align or remove it.
  4. Disable competing formatters (Beautify, Biome/Rome, ESLint formatter).
  5. Parsers are auto-detected (JS/TS → babel/babel-ts; HTML/CSS/JSON/MD built-in).
  6. Don’t format files outside workspace or in subfolders with different configs.

Happy formatting! 🚀

🌍 Languages

🌐 🇮🇹 IT — 🇬🇧 EN Want to add more languages? Contributions are welcome!

📝 License

MIT © CodeCorn™ — Distributed under the MIT license.

⭐ Support

If this was useful, star the repo and share it with your team.

🤝 Contribute

PRs welcome. Open an issue for proposals/bugs. Thanks!


⭐ Support the Project

If this guide helped you, leave a star ⭐ on GitHub and help us grow the CodeCorn community!

GitHub Stars Forks


🧭 Maintainer

👨‍💻 Federico Girolami

Full Stack Developer | System Integrator | Digital Solution Architect 🚀

📫 Get in Touch

🌐 Website: codecorn.it *(Under Construction)*

📧 Email: f.girolami@codecorn.it

🐙 GitHub: github.com/fgirolami29