jpskill.com
🛠️ 開発・MCP コミュニティ

eslint

ESLintはJavaScript/TypeScriptのコードを静的に解析し、問題点やコーディング規約違反を検出し、バグを未然に防ぐための標準的なツールであり、ReactやTypeScriptなど豊富なプラグインで現代的なWeb開発の品質を支えるSkill。

📜 元の英語説明(参考)

ESLint is the standard linting tool for JavaScript and TypeScript projects. It statically analyzes your code to find problems, enforce coding conventions, and catch bugs before they reach production. ESLint 9 introduced the flat config format, replacing the legacy `.eslintrc` system with a simpler, more composable `eslint.config.js` file. With a rich plugin ecosystem covering React, TypeScript, accessibility, and import ordering, ESLint is the backbone of code quality in modern web development.

🇯🇵 日本人クリエイター向け解説

一言でいうと

ESLintはJavaScript/TypeScriptのコードを静的に解析し、問題点やコーディング規約違反を検出し、バグを未然に防ぐための標準的なツールであり、ReactやTypeScriptなど豊富なプラグインで現代的なWeb開発の品質を支えるSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o eslint.zip https://jpskill.com/download/14872.zip && unzip -o eslint.zip && rm eslint.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/14872.zip -OutFile "$d\eslint.zip"; Expand-Archive "$d\eslint.zip" -DestinationPath $d -Force; ri "$d\eslint.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して eslint.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → eslint フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

ESLint — JavaScript および TypeScript の Linting

ESLint はソースコードを読み込み、一連のルールを適用し、スタイルの不整合から真のバグまで、さまざまな問題を報告します。未使用の変数、欠落した return 文、一貫性のない命名、アクセシビリティ違反、そして注意深いコードレビューでも見過ごされる可能性のある数百ものその他の問題を検出します。

このスキルでは、最新のフラット構成形式を使用した ESLint 9+ について説明します。新しいプロジェクトを開始する場合、または従来の .eslintrc 形式から移行する場合は、フラット構成が最適です。

ESLint のインストール

ESLint 9 は単一のパッケージとして提供されます。TypeScript と React のサポートは、コンパニオンプラグインから提供されます。

# TypeScript React プロジェクト用の ESLint および一般的なプラグインをインストールします
npm install --save-dev eslint @eslint/js typescript-eslint eslint-plugin-react eslint-plugin-react-hooks

フラット構成の基本

フラット構成は、プロジェクトのルートにある eslint.config.js (または .mjs.ts) に存在します。extends および overrides を使用した深くネストされた JSON の代わりに、フラット構成では構成オブジェクトの配列を使用します。各オブジェクトは、その files グロブパターンに一致するファイルに適用されます。

// eslint.config.js — TypeScript プロジェクトのフラット構成
import js from '@eslint/js';
import tseslint from 'typescript-eslint';

export default [
  // 基本的な JavaScript の推奨ルール
  js.configs.recommended,

  // TypeScript の推奨ルール (型認識)
  ...tseslint.configs.recommended,

  // ソースファイルのカスタム構成
  {
    files: ['src/**/*.ts', 'src/**/*.tsx'],
    languageOptions: {
      parserOptions: {
        project: './tsconfig.json',
      },
    },
    rules: {
      // コードに残された console.log に対して警告します
      'no-console': ['warn', { allow: ['warn', 'error'] }],

      // 一貫した戻り値の型を強制します
      '@typescript-eslint/explicit-function-return-type': 'off',

      // 未使用の変数を防止します (アンダースコアプレフィックスを無視します)
      '@typescript-eslint/no-unused-vars': ['error', {
        argsIgnorePattern: '^_',
        varsIgnorePattern: '^_',
      }],
    },
  },

  // ビルド出力と依存関係を無視します
  {
    ignores: ['dist/', 'node_modules/', 'coverage/', '*.config.js'],
  },
];

フラット構成は純粋な JavaScript です。条件文、スプレッド演算子、およびファクトリ関数を使用して構成を構成できます。魔法はありません — 各配列要素は、順番にマージされる構成オブジェクトです。

React サポートの追加

React プロジェクトには、JSX の解析とフックのルールが必要です。フラット構成を使用すると、これらのルールを基本構成の上に簡単に重ねることができます。

// eslint.config.js — React TypeScript プロジェクトの完全な構成
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';

export default [
  js.configs.recommended,
  ...tseslint.configs.recommended,

  // React プラグインの構成
  {
    files: ['src/**/*.tsx', 'src/**/*.jsx'],
    plugins: {
      react,
      'react-hooks': reactHooks,
    },
    languageOptions: {
      parserOptions: {
        ecmaFeatures: { jsx: true },
      },
    },
    settings: {
      react: { version: 'detect' },
    },
    rules: {
      // React ルール
      'react/react-in-jsx-scope': 'off', // React 17+ JSX 変換では不要
      'react/prop-types': 'off', // prop の検証に TypeScript を使用
      'react/jsx-no-target-blank': 'error',

      // フックのルール — これらは実際のバグを検出します
      'react-hooks/rules-of-hooks': 'error',
      'react-hooks/exhaustive-deps': 'warn',
    },
  },

  { ignores: ['dist/', 'node_modules/', '.next/'] },
];

ルールの理解

すべての ESLint ルールには、'off' (0)、'warn' (1)、および 'error' (2) の 3 つの重大度レベルがあります。警告はエディターに表示されますが、CI は失敗しません。エラーはビルドを中断します。

ルールは、2 番目の配列要素としてオプションを受け取ることもできます。パターンは常に [severity, ...options] です。

// eslint.config.js — ルール構成パターンの例
export default [
  {
    files: ['src/**/*.ts'],
    rules: {
      // 単純なオン/オフ
      'no-debugger': 'error',

      // オプション付きのルール
      'no-restricted-imports': ['error', {
        patterns: [{
          group: ['../../*'],
          message: '2 レベルを超える相対インポートの代わりに、パスエイリアス (@/) を使用してください。',
        }],
      }],

      // TypeScript プラグインによる命名規則
      '@typescript-eslint/naming-convention': ['error',
        { selector: 'interface', format: ['PascalCase'] },
        { selector: 'typeAlias', format: ['PascalCase'] },
        { selector: 'enum', format: ['PascalCase'] },
        { selector: 'enumMember', format: ['UPPER_CASE'] },
      ],

      // 複雑さの制限
      'max-depth': ['warn', 4],
      'max-lines-per-function': ['warn', { max: 100, skipBlankLines: true, skipComments: true }],
    },
  },
];

カスタムルールの作成

組み込みのルールとプラグインがチーム固有の規則をカバーしていない場合は、カスタムルールを作成できます。ESLint ルールは、AST ノードを受け取り、問題を報告する関数です。

// eslint-rules/no-hardcoded-urls.js — ハードコードされた API URL を防止するカスタムルール
export default {
  meta: {
    type: 'problem',
    docs: {
      description: 'ソースファイル内のハードコードされた API URL を禁止します',
    },
    messages: {
      hardcodedUrl: 'ハードコードされた URL の代わりに環境変数を使用してください。見つかりました: "{{url}}"',
    },
  },
  create(context) {
    const urlPattern = /^https?:\/\/(api|staging|prod)\./;

    return {
      Literal(node) {
        if (typeof node.value === 'string' && urlPattern.test(node.value)) {
          context.report({
            node,
            messageId: 'hardcodedUrl',
            data: { url: node.value },
          });
        }
      },
    };
  },
};

plugins フィールドを使用して、フラット構成にカスタムルールを登録します。


// eslint.config.js — カスタムルールの登録
import noHardcodedUrls from './eslint-rules/no-hardcoded-

(原文がここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

ESLint — JavaScript and TypeScript Linting

ESLint reads your source code, applies a set of rules, and reports problems ranging from stylistic inconsistencies to genuine bugs. It catches unused variables, missing return statements, inconsistent naming, accessibility violations, and hundreds of other issues that slip past even careful code review.

This skill covers ESLint 9+ with the modern flat config format. If you're starting a new project or migrating from the legacy .eslintrc format, flat config is the way forward.

Installing ESLint

ESLint 9 ships as a single package. TypeScript and React support come from companion plugins.

# Install ESLint and common plugins for a TypeScript React project
npm install --save-dev eslint @eslint/js typescript-eslint eslint-plugin-react eslint-plugin-react-hooks

Flat Config Basics

The flat config lives in eslint.config.js (or .mjs, .ts) at your project root. Instead of deeply nested JSON with extends and overrides, flat config uses an array of configuration objects. Each object applies to files matching its files glob pattern.

// eslint.config.js — Flat config for a TypeScript project
import js from '@eslint/js';
import tseslint from 'typescript-eslint';

export default [
  // Base JavaScript recommended rules
  js.configs.recommended,

  // TypeScript recommended rules (type-aware)
  ...tseslint.configs.recommended,

  // Custom configuration for source files
  {
    files: ['src/**/*.ts', 'src/**/*.tsx'],
    languageOptions: {
      parserOptions: {
        project: './tsconfig.json',
      },
    },
    rules: {
      // Warn on console.log left in code
      'no-console': ['warn', { allow: ['warn', 'error'] }],

      // Enforce consistent return types
      '@typescript-eslint/explicit-function-return-type': 'off',

      // Prevent unused variables (ignore underscore-prefixed)
      '@typescript-eslint/no-unused-vars': ['error', {
        argsIgnorePattern: '^_',
        varsIgnorePattern: '^_',
      }],
    },
  },

  // Ignore build output and dependencies
  {
    ignores: ['dist/', 'node_modules/', 'coverage/', '*.config.js'],
  },
];

The flat config is pure JavaScript. You can use conditionals, spread operators, and factory functions to compose configurations. There's no magic — each array element is a config object that gets merged in order.

Adding React Support

React projects need JSX parsing and rules for hooks. The flat config makes it straightforward to layer these on top of your base configuration.

// eslint.config.js — Full config for a React TypeScript project
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';

export default [
  js.configs.recommended,
  ...tseslint.configs.recommended,

  // React plugin configuration
  {
    files: ['src/**/*.tsx', 'src/**/*.jsx'],
    plugins: {
      react,
      'react-hooks': reactHooks,
    },
    languageOptions: {
      parserOptions: {
        ecmaFeatures: { jsx: true },
      },
    },
    settings: {
      react: { version: 'detect' },
    },
    rules: {
      // React rules
      'react/react-in-jsx-scope': 'off', // Not needed with React 17+ JSX transform
      'react/prop-types': 'off', // Using TypeScript for prop validation
      'react/jsx-no-target-blank': 'error',

      // Hooks rules — these catch real bugs
      'react-hooks/rules-of-hooks': 'error',
      'react-hooks/exhaustive-deps': 'warn',
    },
  },

  { ignores: ['dist/', 'node_modules/', '.next/'] },
];

Understanding Rules

Every ESLint rule has three severity levels: 'off' (0), 'warn' (1), and 'error' (2). Warnings appear in your editor but don't fail CI. Errors break the build.

Rules can also take options as a second array element. The pattern is always [severity, ...options].

// eslint.config.js — Examples of rule configuration patterns
export default [
  {
    files: ['src/**/*.ts'],
    rules: {
      // Simple on/off
      'no-debugger': 'error',

      // Rule with options
      'no-restricted-imports': ['error', {
        patterns: [{
          group: ['../../*'],
          message: 'Use path aliases (@/) instead of relative imports above two levels.',
        }],
      }],

      // Naming conventions via TypeScript plugin
      '@typescript-eslint/naming-convention': ['error',
        { selector: 'interface', format: ['PascalCase'] },
        { selector: 'typeAlias', format: ['PascalCase'] },
        { selector: 'enum', format: ['PascalCase'] },
        { selector: 'enumMember', format: ['UPPER_CASE'] },
      ],

      // Complexity limits
      'max-depth': ['warn', 4],
      'max-lines-per-function': ['warn', { max: 100, skipBlankLines: true, skipComments: true }],
    },
  },
];

Writing Custom Rules

When the built-in rules and plugins don't cover your team's specific conventions, you can write custom rules. ESLint rules are functions that receive an AST node and report problems.

// eslint-rules/no-hardcoded-urls.js — Custom rule to prevent hardcoded API URLs
export default {
  meta: {
    type: 'problem',
    docs: {
      description: 'Disallow hardcoded API URLs in source files',
    },
    messages: {
      hardcodedUrl: 'Use environment variables instead of hardcoded URLs. Found: "{{url}}"',
    },
  },
  create(context) {
    const urlPattern = /^https?:\/\/(api|staging|prod)\./;

    return {
      Literal(node) {
        if (typeof node.value === 'string' && urlPattern.test(node.value)) {
          context.report({
            node,
            messageId: 'hardcodedUrl',
            data: { url: node.value },
          });
        }
      },
    };
  },
};

Register the custom rule in your flat config using the plugins field.

// eslint.config.js — Registering a custom rule
import noHardcodedUrls from './eslint-rules/no-hardcoded-urls.js';

export default [
  {
    files: ['src/**/*.ts'],
    plugins: {
      custom: {
        rules: {
          'no-hardcoded-urls': noHardcodedUrls,
        },
      },
    },
    rules: {
      'custom/no-hardcoded-urls': 'error',
    },
  },
];

Auto-Fix

Many ESLint rules support automatic fixing. The --fix flag rewrites your source files to resolve fixable violations — things like adding missing semicolons, removing unused imports, or reordering object keys.

# Fix all auto-fixable issues
npx eslint --fix src/

# Preview what would change without writing files
npx eslint --fix-dry-run src/

# Fix only specific rules
npx eslint --fix --rule '{"import/order": "error"}' src/

In your editor, configure ESLint to fix on save for a seamless experience.

// .vscode/settings.json — Auto-fix ESLint issues on save
{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": "explicit"
  },
  "eslint.validate": [
    "javascript",
    "typescript",
    "javascriptreact",
    "typescriptreact"
  ]
}

Running ESLint in CI

In continuous integration, ESLint should run as a blocking check. Any error-level violation fails the pipeline, preventing the code from being merged.

# .github/workflows/lint.yml — ESLint as a required CI check
name: Lint
on: [push, pull_request]

jobs:
  eslint:
    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 eslint src/ --max-warnings 0

The --max-warnings 0 flag treats warnings as errors in CI. This prevents warning count from growing unbounded while still letting developers see warnings in their editors during development.