eslint-config-airbnb vs eslint-config-google vs eslint-config-prettier vs eslint-config-standard
JavaScript プロジェクトのための ESLint 共有設定パッケージ比較
eslint-config-airbnbeslint-config-googleeslint-config-prettiereslint-config-standard類似パッケージ:

JavaScript プロジェクトのための ESLint 共有設定パッケージ比較

eslint-config-airbnbeslint-config-googleeslint-config-prettiereslint-config-standard は、JavaScript プロジェクトにおけるコード品質とスタイルの一貫性を保つための ESLint 共有設定パッケージです。これらのパッケージは、それぞれ異なるコーディング規約や哲学に基づいており、プロジェクトの要件やチームの好みに応じて選択されます。eslint-config-airbnb は Airbnb 社の厳格な React 向け規約を提供し、eslint-config-google は Google のシンプルで一貫性のあるスタイルガイドを実装します。一方、eslint-config-prettier は Prettier との競合を解消するためにフォーマット関連の ESLint ルールを無効化する補助的な役割を持ち、eslint-config-standard は最小限のルールセットで「設定不要」を謳う StandardJS の規約を提供します。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
eslint-config-airbnb0148,11581.7 kB189-MIT
eslint-config-google01,774-157年前Apache-2.0
eslint-config-prettier05,87259 kB209ヶ月前MIT
eslint-config-standard02,65116.1 kB293年前MIT

ESLint 共有設定パッケージ徹底比較:Airbnb、Google、Prettier、Standard

ESLint の共有設定(shareable config)は、チーム開発やプロジェクト間で一貫したコードスタイルを維持するための強力な手段です。eslint-config-airbnbeslint-config-googleeslint-config-prettiereslint-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-airbnb

Airbnb 設定は eslint-plugin-reacteslint-plugin-importeslint-plugin-jsx-a11y などのプラグインに依存しています。そのため、インストール時には追加パッケージも必要です。

# 正しいインストール方法(公式推奨)
npx install-peerdeps --dev eslint-config-airbnb

.eslintrc.js:

module.exports = {
  extends: ['airbnb']
};

eslint-config-google

Google 設定は依存が少なく、シンプルに導入できます。

npm install --save-dev eslint-config-google

.eslintrc.js:

module.exports = {
  extends: ['google']
};

eslint-config-prettier

Prettier 設定は常に他の設定と併用します。通常は extends 配列の最後に指定することで、それまでのルールで有効化されたフォーマット系ルールを無効化します。

npm install --save-dev eslint-config-prettier

.eslintrc.js(例:Airbnb + Prettier):

module.exports = {
  extends: ['airbnb', 'prettier']
};

eslint-config-standard

Standard 設定も依存が少なく、すぐに使えます。

npm install --save-dev eslint-config-standard

.eslintrc.js:

module.exports = {
  extends: ['standard']
};

🛑 ルールの厳しさと柔軟性

各設定がどのようなコードを許容するか、具体例で見ていきましょう。

セミコロンの有無

  • Airbnb: 必須(semi: ["error", "always"]
  • Google: 必須(semi: ["error", "always"]
  • Standard: 禁止(semi: ["error", "never"]
  • Prettier: 無効化(他の設定に従う)
// Airbnb / Google → OK
const name = 'Alice';

// Standard → OK
const name = 'Alice'

インデントスタイル

  • Airbnb: 2スペース(indent: ["error", 2]
  • Google: 2スペース(indent: ["error", 2]
  • Standard: 2スペース(indent: ["error", 2]
  • Prettier: 無効化
// 全ての設定で以下がOK
function greet() {
  console.log('Hello');
}

React に関するルール

  • Airbnb: react/react-in-jsx-scope など React 専用ルール多数
  • Google: React 未対応(JSX を使うとエラー)
  • Standard: React 未対応(JSX を使うとエラー)
  • Prettier: JSX 対応(ただしルール自体は無効化)
// Airbnb → OK
import React from 'react';
const App = () => <div>Hello</div>;

// Google / Standard → エラー(JSX not allowed in files with extension '.js' など)

🔄 Prettier との共存戦略

多くのチームが 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 が必要です。

🧪 実際のプロジェクトでの選定基準

大規模 React アプリケーション

  • 推奨: eslint-config-airbnb + eslint-config-prettier
  • 理由: React に特化した包括的なルールセットがあり、アクセシビリティやベストプラクティスも網羅。Prettier と組み合わせることでフォーマット競合を回避。

シンプルな Node.js スクリプトやライブラリ

  • 推奨: eslint-config-standard + eslint-config-prettier
  • 理由: 設定が最小限で、過度な制約がない。セミコロン不要派にも対応。

Google スタイルを強制したい企業内プロジェクト

  • 推奨: eslint-config-google + eslint-config-prettier
  • 理由: Google の公式スタイルガイドに準拠しており、社内規約との整合性が取りやすい。

既存のカスタム ESLint 設定に Prettier を追加したい場合

  • 推奨: 既存設定 + eslint-config-prettier
  • 理由: eslint-config-prettier は他の設定と組み合わせるためだけに存在するので、このケースが本来の使い方。

📌 まとめ:各パッケージの特徴と用途

パッケージ主な用途React 対応セミコロン特徴
eslint-config-airbnb大規模 React アプリ必須厳格で包括的、アクセシビリティ重視
eslint-config-googleGoogle スタイル準拠プロジェクト必須シンプルで一貫性重視、古めの環境対応
eslint-config-prettier他の設定との併用⚠️(無効化のみ)無効化フォーマット競合解消専用
eslint-config-standard設定不要の軽量プロジェクト禁止最小限のルール、宗教論争回避

💡 最終的なアドバイス

  • React プロジェクトなら Airbnb 設定が無難 — ただし、Prettier と併用する場合は必ず eslint-config-prettier を追加してください。
  • シンプルさを求めるなら Standard — 設定ファイルすら不要なほど軽量ですが、JSX は使えません。
  • Prettier を使っているなら eslint-config-prettier は必須 — これは単体では使わず、他の設定と組み合わせてください。
  • Google 設定は特定のニーズ向け — 一般的なフロントエンド開発ではあまり使われません。

ESLint の共有設定は「正しい答え」ではなく「チームの合意」に基づいて選ぶべきものです。上記の比較を参考に、あなたのプロジェクトに最も合うものを選んでください。

選び方: eslint-config-airbnb vs eslint-config-google vs eslint-config-prettier vs eslint-config-standard

  • eslint-config-airbnb:

    eslint-config-airbnb は、大規模な React プロジェクトで厳格かつ包括的なコーディング規約を適用したい場合に最適です。アクセシビリティやベストプラクティスに関する詳細なルールが含まれており、チーム全体で高品質なコードを維持するのに役立ちます。ただし、依存パッケージが多く、Prettier と併用する場合は eslint-config-prettier を追加する必要があります。

  • eslint-config-google:

    eslint-config-google は、Google の公式 JavaScript スタイルガイドに準拠したいプロジェクトや、シンプルで一貫性のあるコードベースを求める場合に適しています。React や JSX には対応していないため、主に Node.js やプレーン JavaScript プロジェクトでの利用が想定されています。

  • eslint-config-prettier:

    eslint-config-prettier は、Prettier と ESLint を併用する際に必須となる補助パッケージです。このパッケージ単体では意味がなく、他の ESLint 設定(例: Airbnb や Standard)と組み合わせて使用し、フォーマット関連のルール競合を解消します。Prettier を採用しているプロジェクトでは、必ず他の設定の後に追加してください。

  • eslint-config-standard:

    eslint-config-standard は、最小限の設定で素早くプロジェクトを始めたい場合や、セミコロン不要・過度な制約を避けたいチームに適しています。設定ファイルが不要なほどシンプルですが、React や JSX には対応していないため、フロントエンドフレームワークを使用しないプロジェクトでの利用が推奨されます。

eslint-config-airbnb のREADME

eslint-config-airbnb

npm version

This package provides Airbnb's .eslintrc as an extensible shared config.

Usage

We export three ESLint configurations for your usage.

eslint-config-airbnb

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.

  1. Install the correct versions of each package, which are listed by the command:
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@^#.#.#
  1. Add "extends": "airbnb" to your .eslintrc

eslint-config-airbnb/hooks

This entry point enables the linting rules for React hooks (requires v16.8+). To use, add "extends": ["airbnb", "airbnb/hooks"] to your .eslintrc.

eslint-config-airbnb/whitespace

This entry point only errors on whitespace rules and sets all other rules to warnings. View the list of whitespace rules here.

eslint-config-airbnb/base

This entry point is deprecated. See eslint-config-airbnb-base.

eslint-config-airbnb/legacy

This entry point is deprecated. See eslint-config-airbnb-base.

See Airbnb's JavaScript styleguide and the ESlint config docs for more information.

Improving this config

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.