prettier
Prettierは、JavaScriptやHTMLなどの様々な言語に対応し、コードのスタイルを自動で統一して、チーム開発における無駄な議論を減らし、本質的な作業に集中できるようにするSkill。
📜 元の英語説明(参考)
Prettier is an opinionated code formatter that enforces a consistent style across your entire codebase. Unlike linters that flag problems for you to fix, Prettier rewrites your code automatically. It supports JavaScript, TypeScript, HTML, CSS, JSON, Markdown, YAML, and many other languages. By removing style debates from code review, Prettier lets teams focus on logic and architecture instead of arguing about tabs versus spaces or trailing commas.
🇯🇵 日本人クリエイター向け解説
Prettierは、JavaScriptやHTMLなどの様々な言語に対応し、コードのスタイルを自動で統一して、チーム開発における無駄な議論を減らし、本質的な作業に集中できるようにするSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o prettier.zip https://jpskill.com/download/15284.zip && unzip -o prettier.zip && rm prettier.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15284.zip -OutFile "$d\prettier.zip"; Expand-Archive "$d\prettier.zip" -DestinationPath $d -Force; ri "$d\prettier.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
prettier.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
prettierフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Prettier — コードフォーマット
Prettier はあなたのコードを受け取り、固定された一連のルールに従って最初から再出力します。ソースを AST に解析し、元のフォーマットをすべて破棄し、一貫したスタイルで整形されたバージョンを出力します。その結果、チームのすべての開発者が、エディターや個人の好みに左右されず、同じようにフォーマットされたコードを作成できます。
このスキルでは、Prettier の設定、ESLint との統合、エディターサポートの設定、CI でのフォーマットの強制について説明します。
Prettier のインストールと設定
Prettier は設定なしでも動作しますが、ほとんどのチームは好みに合わせていくつかのオプションをカスタマイズします。
# Prettier を開発依存関係としてインストール
npm install --save-dev prettier
プロジェクトのルートに設定ファイルを作成します。Prettier はいくつかの形式をサポートしていますが、.prettierrc.json が最も一般的です。
// .prettierrc.json — TypeScript プロジェクトの Prettier 設定
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf",
"jsxSingleQuote": false
}
各オプションは、特定のフォーマットの決定を制御します。Prettier は意図的にオプションの数を少なく保っています。全部でおよそ 20 個のオプションしかありません。これは設計によるものです。オプションが少ないほど、議論が少なくなります。
最も影響力のあるオプションは、printWidth (折り返す前の行の長さ)、singleQuote (引用符のスタイル)、trailingComma ("all" に設定すると、よりクリーンな git の差分に役立ちます) です。
ファイルの無視
すべてのファイルをフォーマットする必要はありません。ビルド出力、生成されたコード、および特定の設定ファイルは、除外する必要があることがよくあります。.prettierignore ファイルを .gitignore と同じ構文で作成します。
# .prettierignore — Prettier がスキップするファイルとディレクトリ
dist/
build/
coverage/
node_modules/
.next/
# 生成されたファイル
src/generated/
*.min.js
*.min.css
# ロックファイル
package-lock.json
pnpm-lock.yaml
エディターとの統合
Prettier の真の力は、保存するたびに実行されることにあります。エディターを保存時にフォーマットするように設定すると、フォーマットについて二度と考える必要はありません。コードを書くだけで、自動的に整形されます。
// .vscode/settings.json — Prettier の format-on-save のための VS Code 設定
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
これをプロジェクトの .vscode/settings.json に含めて、リポジトリにコミットします。これにより、VS Code でプロジェクトを開くすべての開発者が、手動で設定しなくても自動的に format-on-save を利用できるようになります。
Prettier と ESLint の統合
Prettier と ESLint は、フォーマットルールで重複しています。調整せずに両方を実行すると、競合が発生します。ESLint がセミコロンを要求する一方で、Prettier がそれらを削除し、無限ループが発生する可能性があります。
解決策は eslint-config-prettier で、Prettier と競合するすべての ESLint ルールを無効にします。これにより、ESLint はコード品質ルールを処理し、Prettier はフォーマットのみを排他的に処理できます。
# ESLint-Prettier 統合をインストール
npm install --save-dev eslint-config-prettier
// eslint.config.js — Prettier 互換性のあるフラットな設定
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import prettierConfig from 'eslint-config-prettier';
export default [
js.configs.recommended,
...tseslint.configs.recommended,
// プロジェクト固有のルール
{
files: ['src/**/*.ts', 'src/**/*.tsx'],
rules: {
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'no-console': 'warn',
},
},
// Prettier 設定は最後に記述する必要があります — 競合するルールを無効にするため
prettierConfig,
{ ignores: ['dist/', 'node_modules/'] },
];
順序が重要です。prettierConfig は配列の最後に記述する必要があります。これにより、以前の設定で設定されたフォーマットルールがオーバーライドされます。
コマンドラインからの Prettier の実行
Prettier は、ファイルのフォーマット、ファイルがすでにフォーマットされているかどうかの確認、および変更されるファイルのリスト表示のためのコマンドを提供します。
# プロジェクト内のサポートされているすべてのファイルをフォーマット
npx prettier --write .
# ファイルがフォーマットされているかどうかを確認します (フォーマットされていない場合はエラーコードで終了します) — CI で使用します
npx prettier --check .
# 特定のファイルタイプをフォーマット
npx prettier --write "src/**/*.{ts,tsx,css,json}"
# ファイルを書き込まずに変更内容を確認
npx prettier --list-different .
これらをチーム全体で一貫性を持たせるために、npm スクリプトとして追加します。
// package.json — チームで使用するための Prettier スクリプト
{
"scripts": {
"format": "prettier --write .",
"format:check": "prettier --check ."
}
}
CI での強制
フォーマットは、CI パイプラインで必須のチェックである必要があります。--check フラグは、すべてのファイルがすでにフォーマットされていることを確認し、変更が必要なファイルがある場合はゼロ以外のコードで終了します。これにより、開発者が Prettier の実行を忘れた PR を検出できます。
# .github/workflows/format.yml — CI ゲートとしての Prettier チェック
name: Format
on: [push, pull_request]
jobs:
prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npx prettier --check .
このチェックが失敗した場合、修正は簡単です。ローカルで npx prettier --write . を実行し、変更をコミットしてプッシュします。一部のチームは、husky と lint-staged を使用して pre-commit hook を追加し、フォーマットされていないコードがコミットされるのをそもそも防ぎます。
# pre-commit ツールをインストール
npm install --save-dev husky lint-staged
npx 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Prettier — Code Formatting
Prettier takes your code and reprints it from scratch according to a fixed set of rules. It parses your source into an AST, discards all original formatting, and outputs a consistently styled version. The result is that every developer on the team produces identically formatted code regardless of their editor or personal preferences.
This skill covers configuring Prettier, integrating it with ESLint, setting up editor support, and enforcing formatting in CI.
Installing and Configuring Prettier
Prettier works with zero configuration, but most teams customize a few options to match their preferences.
# Install Prettier as a dev dependency
npm install --save-dev prettier
Create a configuration file at the project root. Prettier supports several formats — .prettierrc.json is the most common.
// .prettierrc.json — Prettier configuration for a TypeScript project
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf",
"jsxSingleQuote": false
}
Each option controls a specific formatting decision. Prettier intentionally keeps the option count small — there are roughly 20 options total. This is by design. Fewer options means fewer debates.
The most impactful options are printWidth (line length before wrapping), singleQuote (quote style), and trailingComma (helps with cleaner git diffs when set to "all").
Ignoring Files
Not every file should be formatted. Build output, generated code, and certain configuration files often need to be excluded. Create a .prettierignore file using the same syntax as .gitignore.
# .prettierignore — Files and directories Prettier should skip
dist/
build/
coverage/
node_modules/
.next/
# Generated files
src/generated/
*.min.js
*.min.css
# Lock files
package-lock.json
pnpm-lock.yaml
Editor Integration
Prettier's real power comes from running on every save. When you configure your editor to format on save, you never think about formatting again — you just write code and it snaps into shape.
// .vscode/settings.json — VS Code settings for Prettier format-on-save
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
Include this in your project's .vscode/settings.json and commit it to the repository. This way every developer who opens the project in VS Code automatically gets format-on-save without manual setup.
Integrating Prettier with ESLint
Prettier and ESLint overlap on formatting rules. Running both without coordination causes conflicts — ESLint might demand semicolons while Prettier removes them, creating an endless loop.
The solution is eslint-config-prettier, which disables all ESLint rules that conflict with Prettier. This lets ESLint handle code quality rules while Prettier handles formatting exclusively.
# Install the ESLint-Prettier integration
npm install --save-dev eslint-config-prettier
// eslint.config.js — Flat config with Prettier compatibility
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import prettierConfig from 'eslint-config-prettier';
export default [
js.configs.recommended,
...tseslint.configs.recommended,
// Project-specific rules
{
files: ['src/**/*.ts', 'src/**/*.tsx'],
rules: {
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'no-console': 'warn',
},
},
// Prettier config MUST be last — it disables conflicting rules
prettierConfig,
{ ignores: ['dist/', 'node_modules/'] },
];
The order matters. prettierConfig must come last in the array so it overrides any formatting rules set by earlier configs.
Running Prettier from the Command Line
Prettier provides commands for formatting files, checking if files are already formatted, and listing files that would change.
# Format all supported files in the project
npx prettier --write .
# Check if files are formatted (exits with error code if not) — use this in CI
npx prettier --check .
# Format specific file types
npx prettier --write "src/**/*.{ts,tsx,css,json}"
# See what would change without writing files
npx prettier --list-different .
Add these as npm scripts for consistency across the team.
// package.json — Prettier scripts for team usage
{
"scripts": {
"format": "prettier --write .",
"format:check": "prettier --check ."
}
}
CI Enforcement
Formatting should be a required check in your CI pipeline. The --check flag verifies that all files are already formatted and exits with a non-zero code if any file needs changes. This catches PRs where the developer forgot to run Prettier.
# .github/workflows/format.yml — Prettier check as a CI gate
name: Format
on: [push, pull_request]
jobs:
prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npx prettier --check .
When this check fails, the fix is simple: run npx prettier --write . locally, commit the changes, and push. Some teams add a pre-commit hook with husky and lint-staged to prevent unformatted code from being committed in the first place.
# Install pre-commit tooling
npm install --save-dev husky lint-staged
npx husky init
// package.json — lint-staged configuration for pre-commit formatting
{
"lint-staged": {
"*.{ts,tsx,js,jsx,json,css,md}": "prettier --write"
}
}
This runs Prettier on every staged file before each commit, ensuring that formatting violations never reach the remote repository.