agentleFS
dallaydallay/agents-skills/skills/prettier-formatting/SKILL.md

prettier-formatting

Skill2 starsChanged 4 months agoMITView on GitHub

Prettier code formatting setup, configuration, editor integration, ESLint coordination, and pre-commit hook automation for consistent codebases. Use when the task involves `Prettier`, `code formatting`, `.prettierrc`, `Prettier configuration`, or `auto-formatting`.

  • Installs packages

The file

Show its rules and text

We split this skill into the rules it gives an agent

15 rules. About 0 are common, 5 are distinctive, and 10 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 10

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    ESLint Separation: Use eslint-config-prettier to disable ESLint formatting rules.

    line 26
  2. Very specific:

    Ignore Correctly: Always create .prettierignore to skip generated files, build output, and lock files.

    line 29
  3. Distinctive:

    Format All or Nothing: When adding Prettier to an existing project, do one full format commit.

    line 33
  4. Distinctive:

    Never mix formatting changes with logic changes in the same commit.

    line 34
  5. Very specific:

    Pre-Commit Enforcement: Use lint-staged + husky (or lefthook) to format only staged files.

    line 35
  6. Very specific:

    Create a .prettierrc.json (or .prettierrc) at the project root — explicit config prevents editor-level settings from causing inconsistency.

    line 207
  7. Very specific:

    Run prettier --check . in CI to catch unformatted code before merge.

    line 209
  8. Very specific:

    Use overrides for file types that need different settings (Markdown prose, YAML indentation).

    line 210
  9. Very specific:

    Add .vscode/settings.json with formatOnSave: true to the repo so all contributors get it.

    line 211
  10. Distinctive:

    Do one big "format the world" commit when onboarding Prettier, then enforce from that point.

    line 212
  11. Very specific:

    Don't install eslint-plugin-prettier — it runs Prettier inside ESLint, doubling execution time and mixing formatting with linting concerns.

    line 216
  12. Very specific:

    Don't format lock files (pnpm-lock.yaml, package-lock.json) — it breaks integrity checksums.

    line 218
  13. Distinctive:

    Don't customize every option — Prettier's defaults are battle-tested.

    line 219
  14. Very specific:

    Don't skip .prettierignore — without it, Prettier will try to format generated files, SVGs, and build output, causing noise and errors.

    line 221
  15. Distinctive:

    Don't mix formatting changes with logic changes in pull requests — reviewers can't distinguish what actually changed.

    line 223

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

When to Use

  • Setting up Prettier in a new or existing project for consistent formatting.
  • Configuring .prettierrc options to match team style preferences.
  • Integrating Prettier with ESLint without rule conflicts.
  • Adding format-on-save in VS Code, JetBrains, or other editors.
  • Setting up pre-commit hooks to enforce formatting before code is committed.
  • Adding file-type-specific overrides (e.g., different printWidth for Markdown vs TypeScript).

Critical Patterns

  • Prettier Decides, You Don't Argue: Prettier is intentionally opinionated. Configure only the options it exposes — do NOT fight its AST-based formatting decisions with hacks.
  • ESLint Separation: Use eslint-config-prettier to disable ESLint formatting rules. Do NOT use eslint-plugin-prettier — it's slow and mixes concerns. Run Prettier and ESLint as separate steps.
  • Ignore Correctly: Always create .prettierignore to skip generated files, build output, and lock files. Prettier reads .gitignore by default, but explicit ignores prevent accidents.
  • Pin the Version: Lock the Prettier version in package.json to avoid formatting churn across developer machines and CI.
  • Format All or Nothing: When adding Prettier to an existing project, do one full format commit. Never mix formatting changes with logic changes in the same commit.
  • Pre-Commit Enforcement: Use lint-staged + husky (or lefthook) to format only staged files. Running Prettier on the entire repo per commit is wasteful.

Code Examples

Configuration (.prettierrc.json)

{
  "printWidth": 100,
  "tabWidth": 2,
  "useTabs": false,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "all",
  "bracketSpacing": true,
  "arrowParens": "always",
  "endOfLine": "lf",
  "proseWrap": "preserve",
  "htmlWhitespaceSensitivity": "css",
  "singleAttributePerLine": false
}

File-Type Overrides

{
  "printWidth": 100,
  "singleQuote": true,
  "trailingComma": "all",
  "overrides": [
    {
      "files": "*.md",
      "options": {
        "printWidth": 80,
        "proseWrap": "always"
      }
    },
    {
      "files": ["*.json", "*.jsonc"],
      "options": {
        "tabWidth": 2,
        "trailingComma": "none"
      }
    },
    {
      "files": "*.yaml",
      "options": {
        "tabWidth": 2,
        "singleQuote": false
      }
    }
  ]
}

.prettierignore

# Build output
dist/
build/
.next/
out/

# Dependencies
node_modules/

# Lock files (formatting breaks checksums)
pnpm-lock.yaml
package-lock.json
yarn.lock

# Generated
coverage/
*.generated.*
*.min.js
*.min.css

# Assets
*.svg
*.png
*.ico

ESLint Integration (Conflict-Free)

# Install only the config disabler — NOT the plugin
npm install -D eslint-config-prettier
// eslint.config.js
import prettier from "eslint-config-prettier";

export default [
  // ... your other configs
  prettier, // MUST be last — disables ESLint rules that conflict with Prettier
];

Pre-Commit Hook with lint-staged

// package.json
{
  "lint-staged": {
    "*.{js,ts,tsx,jsx,json,css,md,yaml}": "prettier --write"
  }
}
# Setup with Husky
npm install -D husky lint-staged
npx husky init
echo "npx lint-staged" > .husky/pre-commit
# Or with Lefthook (lefthook.yml)
pre-commit:
  commands:
    prettier:
      glob: "*.{js,ts,tsx,jsx,json,css,md,yaml}"
      run: npx prettier --write {staged_files} && git add {staged_files}

VS Code Settings

// .vscode/settings.json
{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "[markdown]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[json]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

Commands

# Format all files
npx prettier --write .

# Check without writing (for CI)
npx prettier --check .

# Format specific file types
npx prettier --write "src/**/*.{ts,tsx}"

# Show what would change
npx prettier --list-different .

# Debug: show resolved config for a file
npx prettier --find-config-path src/index.ts

# Debug: show which parser Prettier uses
npx prettier --file-info src/index.ts

Best Practices

DO

  • Create a .prettierrc.json (or .prettierrc) at the project root — explicit config prevents editor-level settings from causing inconsistency.
  • Run prettier --check . in CI to catch unformatted code before merge.
  • Use overrides for file types that need different settings (Markdown prose, YAML indentation).
  • Add .vscode/settings.json with formatOnSave: true to the repo so all contributors get it.
  • Do one big "format the world" commit when onboarding Prettier, then enforce from that point.

DON'T

  • Don't install eslint-plugin-prettier — it runs Prettier inside ESLint, doubling execution time and mixing formatting with linting concerns.
  • Don't format lock files (pnpm-lock.yaml, package-lock.json) — it breaks integrity checksums.
  • Don't customize every option — Prettier's defaults are battle-tested. Only change what your team truly needs.
  • Don't skip .prettierignore — without it, Prettier will try to format generated files, SVGs, and build output, causing noise and errors.
  • Don't mix formatting changes with logic changes in pull requests — reviewers can't distinguish what actually changed.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.