json 82 lines · 3 tabs

Prettier config for consistent formatting

Shared by codesnips Jan 2026
3 tabs
{
  "printWidth": 100,
  "tabWidth": 2,
  "semi": true,
  "singleQuote": true,
  "quoteProps": "as-needed",
  "trailingComma": "all",
  "bracketSpacing": true,
  "arrowParens": "always",
  "endOfLine": "lf",
  "plugins": ["prettier-plugin-tailwindcss"],
  "overrides": [
    {
      "files": "*.md",
      "options": {
        "tabWidth": 2,
        "proseWrap": "preserve"
      }
    },
    {
      "files": ["*.yml", "*.yaml"],
      "options": {
        "singleQuote": false
      }
    },
    {
      "files": "*.json",
      "options": {
        "printWidth": 80,
        "trailingComma": "none"
      }
    }
  ]
}
3 files · json Explain with highlit

This snippet shows how a shared Prettier setup is wired into a JavaScript/TypeScript monorepo so that every package formats code the same way, with a few well-justified per-language exceptions. The core idea is to make formatting a non-negotiable, machine-enforced concern: developers stop debating quote style and trailing commas because a single config decides, and a pre-commit hook guarantees the rules are applied before anything lands in version control.

The .prettierrc.json tab is the single source of truth. Base options like singleQuote, trailingComma: "all", and printWidth: 100 set the house style, while the overrides array narrows behavior by file glob. Markdown gets proseWrap: "preserve" so hand-wrapped prose is not reflowed, and .md files use two-space tabs; YAML sets singleQuote: false because YAML string quoting rules differ from JS and double quotes are safer. The plugins entry pulls in prettier-plugin-tailwindcss, which reorders utility classes deterministically. Using overrides rather than multiple config files keeps everything discoverable in one place.

Because a formatter and a linter can disagree, .eslintrc.json disables stylistic ESLint rules and delegates them to Prettier. Extending "prettier" last turns off conflicting rules, and "plugin:prettier/recommended" surfaces formatting drift as a single prettier/prettier lint error. This separation of concerns lets ESLint focus on correctness while Prettier owns layout.

The package.json tab connects the config to actual workflows. The format and format:check scripts run Prettier over the tree, the latter used in CI to fail builds on unformatted code. The prepare script installs Husky, and lint-staged runs Prettier only on staged files matching each glob, so commits are fast and touch only what changed. A .prettierignore (referenced implicitly) would exclude build output.

A common pitfall is letting editors reformat entire files and creating noisy diffs; scoping lint-staged to changed files avoids that. Another is forgetting to pin the Prettier version, since output can shift between majors — pinning keeps formatting reproducible across machines and CI. This layout is the pragmatic default for teams that want zero formatting bikeshedding.


Related snips

Share this code

Here's the card — post it anywhere.

Prettier config for consistent formatting — share card
Link copied