eslint-config-airbnb、eslint-config-google、eslint-config-prettier、eslint-config-standard は、JavaScript プロジェクトにおけるコード品質とスタイルの一貫性を保つための ESLint 共有設定パッケージです。これらのパッケージは、それぞれ異なるコーディング規約や哲学に基づいており、プロジェクトの要件やチームの好みに応じて選択されます。eslint-config-airbnb は Airbnb 社の厳格な React 向け規約を提供し、eslint-config-google は Google のシンプルで一貫性のあるスタイルガイドを実装します。一方、eslint-config-prettier は Prettier との競合を解消するためにフォーマット関連の ESLint ルールを無効化する補助的な役割を持ち、eslint-config-standard は最小限のルールセットで「設定不要」を謳う StandardJS の規約を提供します。
ESLint の共有設定(shareable config)は、チーム開発やプロジェクト間で一貫したコードスタイルを維持するための強力な手段です。eslint-config-airbnb、eslint-config-google、eslint-config-prettier、eslint-config-standard はそれぞれ異なる哲学と目的を持ち、適切に選ぶことで開発体験が大きく変わります。この記事では、実際の現場で役立つ観点から、これらのパッケージを深く比較します。
まず、各パッケージが何を目的としているかを理解しましょう。
eslint-config-airbnb は Airbnb 社内で使われている JavaScript/React コーディング規約を公開したもので、細部まで厳密にルールを定めています。特に React プロジェクトでの利用を想定しており、可読性と保守性を最優先にしています。
eslint-config-google は Google の JavaScript スタイルガイドに基づいており、シンプルで一貫性のあるコードを促進します。型安全性やモダンな構文よりも、広い環境での動作保証を重視する傾向があります。
eslint-config-prettier は他の ESLint 設定と併用するために作られた「衝突解消用」パッケージです。Prettier が担当するフォーマット関連のルール(インデント、改行、セミコロンなど)を ESLint から無効化し、ツール間の競合を防ぎます。
eslint-config-standard は「設定不要」を謳う StandardJS プロジェクトの一部で、最小限のルールセットで一貫性を保ちつつ、過度な制約を避けます。半角スペース vs タブ、セミコロンの有無といった宗教論争を避ける設計になっています。
💡 重要なポイント:
eslint-config-prettierは単体では意味がなく、必ず他の ESLint 設定と組み合わせて使用します。
各パッケージの導入方法には大きな違いがあります。特に peer dependency の扱いに注意が必要です。
eslint-config-airbnbAirbnb 設定は eslint-plugin-react、eslint-plugin-import、eslint-plugin-jsx-a11y などのプラグインに依存しています。そのため、インストール時には追加パッケージも必要です。
# 正しいインストール方法(公式推奨)
npx install-peerdeps --dev eslint-config-airbnb
.eslintrc.js:
module.exports = {
extends: ['airbnb']
};
eslint-config-googleGoogle 設定は依存が少なく、シンプルに導入できます。
npm install --save-dev eslint-config-google
.eslintrc.js:
module.exports = {
extends: ['google']
};
eslint-config-prettierPrettier 設定は常に他の設定と併用します。通常は extends 配列の最後に指定することで、それまでのルールで有効化されたフォーマット系ルールを無効化します。
npm install --save-dev eslint-config-prettier
.eslintrc.js(例:Airbnb + Prettier):
module.exports = {
extends: ['airbnb', 'prettier']
};
eslint-config-standardStandard 設定も依存が少なく、すぐに使えます。
npm install --save-dev eslint-config-standard
.eslintrc.js:
module.exports = {
extends: ['standard']
};
各設定がどのようなコードを許容するか、具体例で見ていきましょう。
semi: ["error", "always"])semi: ["error", "always"])semi: ["error", "never"])// Airbnb / Google → OK
const name = 'Alice';
// Standard → OK
const name = 'Alice'
indent: ["error", 2])indent: ["error", 2])indent: ["error", 2])// 全ての設定で以下がOK
function greet() {
console.log('Hello');
}
react/react-in-jsx-scope など React 専用ルール多数// Airbnb → OK
import React from 'react';
const App = () => <div>Hello</div>;
// Google / Standard → エラー(JSX not allowed in files with extension '.js' など)
多くのチームが Prettier(コードフォーマッタ)と ESLint(静的解析)を併用していますが、両者が同じ領域(例:インデント、改行)をカバーすると競合が発生します。ここで eslint-config-prettier の出番です。
// .eslintrc.js
module.exports = {
extends: [
'airbnb', // または 'standard'、'google' など
'prettier' // 必ず最後に!
],
plugins: [
'prettier' // eslint-plugin-prettier が必要な場合
]
};
この設定により、Prettier が担当するフォーマット系ルールが ESLint から無効化され、競合が解消されます。
⚠️ 注意:
eslint-config-prettierだけでは Prettier のルールが ESLint に反映されるわけではありません。Prettier のルールを ESLint でチェックしたい場合は、別途eslint-plugin-prettierが必要です。
eslint-config-airbnb + eslint-config-prettiereslint-config-standard + eslint-config-prettiereslint-config-google + eslint-config-prettiereslint-config-prettiereslint-config-prettier は他の設定と組み合わせるためだけに存在するので、このケースが本来の使い方。| パッケージ | 主な用途 | React 対応 | セミコロン | 特徴 |
|---|---|---|---|---|
eslint-config-airbnb | 大規模 React アプリ | ✅ | 必須 | 厳格で包括的、アクセシビリティ重視 |
eslint-config-google | Google スタイル準拠プロジェクト | ❌ | 必須 | シンプルで一貫性重視、古めの環境対応 |
eslint-config-prettier | 他の設定との併用 | ⚠️(無効化のみ) | 無効化 | フォーマット競合解消専用 |
eslint-config-standard | 設定不要の軽量プロジェクト | ❌ | 禁止 | 最小限のルール、宗教論争回避 |
eslint-config-prettier を追加してください。ESLint の共有設定は「正しい答え」ではなく「チームの合意」に基づいて選ぶべきものです。上記の比較を参考に、あなたのプロジェクトに最も合うものを選んでください。
eslint-config-airbnb は、大規模な React プロジェクトで厳格かつ包括的なコーディング規約を適用したい場合に最適です。アクセシビリティやベストプラクティスに関する詳細なルールが含まれており、チーム全体で高品質なコードを維持するのに役立ちます。ただし、依存パッケージが多く、Prettier と併用する場合は eslint-config-prettier を追加する必要があります。
eslint-config-google は、Google の公式 JavaScript スタイルガイドに準拠したいプロジェクトや、シンプルで一貫性のあるコードベースを求める場合に適しています。React や JSX には対応していないため、主に Node.js やプレーン JavaScript プロジェクトでの利用が想定されています。
eslint-config-prettier は、Prettier と ESLint を併用する際に必須となる補助パッケージです。このパッケージ単体では意味がなく、他の ESLint 設定(例: Airbnb や Standard)と組み合わせて使用し、フォーマット関連のルール競合を解消します。Prettier を採用しているプロジェクトでは、必ず他の設定の後に追加してください。
eslint-config-standard は、最小限の設定で素早くプロジェクトを始めたい場合や、セミコロン不要・過度な制約を避けたいチームに適しています。設定ファイルが不要なほどシンプルですが、React や JSX には対応していないため、フロントエンドフレームワークを使用しないプロジェクトでの利用が推奨されます。
This package provides Airbnb's .eslintrc as an extensible shared config.
We export three ESLint configurations for your usage.
Our default export contains most of our ESLint rules, including ECMAScript 6+ and React. It requires eslint, eslint-plugin-import, eslint-plugin-react, eslint-plugin-react-hooks, and eslint-plugin-jsx-a11y. Note that it does not enable our React Hooks rules. To enable those, see the eslint-config-airbnb/hooks section.
If you don't need React, see eslint-config-airbnb-base.
npm info "eslint-config-airbnb@latest" peerDependencies
If using npm 5+, use this shortcut
npx install-peerdeps --dev eslint-config-airbnb
If using yarn, you can also use the shortcut described above if you have npm 5+ installed on your machine, as the command will detect that you are using yarn and will act accordingly.
Otherwise, run npm info "eslint-config-airbnb@latest" peerDependencies to list the peer dependencies and versions, then run yarn add --dev <dependency>@<version> for each listed peer dependency.
If using npm < 5, Linux/OSX users can run
(
export PKG=eslint-config-airbnb;
npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest"
)
Which produces and runs a command like:
npm install --save-dev eslint-config-airbnb eslint@^#.#.# eslint-plugin-jsx-a11y@^#.#.# eslint-plugin-import@^#.#.# eslint-plugin-react@^#.#.# eslint-plugin-react-hooks@^#.#.#
If using npm < 5, Windows users can either install all the peer dependencies manually, or use the install-peerdeps cli tool.
npm install -g install-peerdeps
install-peerdeps --dev eslint-config-airbnb
The cli will produce and run a command like:
npm install --save-dev eslint-config-airbnb eslint@^#.#.# eslint-plugin-jsx-a11y@^#.#.# eslint-plugin-import@^#.#.# eslint-plugin-react@^#.#.# eslint-plugin-react-hooks@^#.#.#
"extends": "airbnb" to your .eslintrcThis entry point enables the linting rules for React hooks (requires v16.8+). To use, add "extends": ["airbnb", "airbnb/hooks"] to your .eslintrc.
This entry point only errors on whitespace rules and sets all other rules to warnings. View the list of whitespace rules here.
This entry point is deprecated. See eslint-config-airbnb-base.
This entry point is deprecated. See eslint-config-airbnb-base.
See Airbnb's JavaScript styleguide and the ESlint config docs for more information.
Consider adding test cases if you're making complicated rules changes, like anything involving regexes. Perhaps in a distant future, we could use literate programming to structure our README as test cases for our .eslintrc?
You can run tests with npm test.
You can make sure this module lints with itself using npm run lint.