メインコンテンツへスキップ

概要

@typescript-eslint/eslint-plugin には、TypeScript コードに特有のベストプラクティス違反、バグ、および/またはスタイル上の問題を検出する 100 を超えるルールが含まれています。すべてのルールを以下に示します。

ヒント

ルールを 1 つずつ有効にする代わりに、定義済みの設定のいずれかを使用して、推奨されるルールをまとめて有効にすることをお勧めします。

ルール

ルールはアルファベット順にリストされています。オプションで、これらのカテゴリに基づいてフィルタリングできます。

構成グループ (⚙️)
メタデータ

(これらのカテゴリの説明は 以下で詳しく説明します).)

ルール
⚙️
🔧
💭
🧱
📐
💀
@typescript-eslint/adjacent-overload-signatures
関数のオーバーロードシグネチャが連続していることを要求します
🎨
@typescript-eslint/array-type
配列に T[] または Array<T> のいずれかを使用することを一貫して要求します
🎨🔧
@typescript-eslint/await-thenable
Thenable でない値の await を禁止します
💡💭
@typescript-eslint/ban-ts-comment
@ts-<ディレクティブ> コメントを禁止するか、ディレクティブの後に説明を必須にします
💡
@typescript-eslint/ban-tslint-comment
// tslint:<rule-flag> コメントを禁止します
🎨🔧
@typescript-eslint/ban-types
特定の型を禁止します
🔧
💡
@typescript-eslint/block-spacing
ブロックを開いた後と閉じる前のブロック内のスペースを禁止または強制します
🔧🧱📐💀
@typescript-eslint/brace-style
ブロックの一貫したブレーススタイルを強制します
🔧🧱📐💀
@typescript-eslint/class-literal-property-style
クラスのリテラルが一貫したスタイルで公開されるように強制します
🎨💡
@typescript-eslint/class-methods-use-this
クラスメソッドが this を利用することを強制します
🧱
@typescript-eslint/comma-dangle
末尾のコンマを必須または禁止します
🔧🧱📐💀
@typescript-eslint/comma-spacing
コンマの前後のスペースを統一します
🔧🧱📐💀
@typescript-eslint/consistent-generic-constructors
コンストラクタ呼び出しの型アノテーションまたはコンストラクタ名にジェネリック型引数を指定することを強制します
🎨🔧
@typescript-eslint/consistent-indexed-object-style
Record 型を必須または禁止します
🎨🔧
@typescript-eslint/consistent-return
return ステートメントが常に値を指定するか、値を指定しないことを要求します
💭🧱
@typescript-eslint/consistent-type-assertions
型アサーションの一貫した使用法を強制します
🎨🔧
💡
@typescript-eslint/consistent-type-definitions
型定義が interface または type のいずれかを一貫して使用することを強制します
🎨🔧
@typescript-eslint/consistent-type-exports
型エクスポートの一貫した使用法を強制します
🔧💭
@typescript-eslint/consistent-type-imports
型インポートの一貫した使用法を強制します
🔧
@typescript-eslint/default-param-last
デフォルトパラメータを最後にするように強制します
🧱
@typescript-eslint/dot-notation
可能な限りドット表記を強制します
🎨🔧💭🧱
@typescript-eslint/explicit-function-return-type
関数とクラスメソッドに明示的な戻り値の型を要求します
@typescript-eslint/explicit-member-accessibility
クラスプロパティとメソッドに明示的なアクセシビリティ修飾子を要求します
🔧
💡
@typescript-eslint/explicit-module-boundary-types
エクスポートされた関数とクラスのパブリッククラスメソッドに明示的な戻り値と引数の型を要求します
@typescript-eslint/func-call-spacing
関数識別子とその呼び出しの間のスペースを必須または禁止します
🔧🧱📐💀
@typescript-eslint/indent
一貫したインデントを強制します
🔧🧱📐💀
@typescript-eslint/init-declarations
変数宣言での初期化を必須または禁止します
🧱
@typescript-eslint/key-spacing
型とインターフェイスにおけるプロパティ名と型注釈の間の一貫したスペースを強制します
🔧🧱📐💀
@typescript-eslint/keyword-spacing
キーワードの前後のスペースを統一します
🔧🧱📐💀
@typescript-eslint/lines-around-comment
コメントの周りに空行を必須にします
🔧🧱📐💀
@typescript-eslint/lines-between-class-members
クラスメンバー間の空行を必須または禁止します
🔧🧱📐💀
@typescript-eslint/max-params
関数定義の最大パラメータ数を強制します
🧱
@typescript-eslint/member-delimiter-style
インターフェイスと型リテラルに特定のメンバー区切りスタイルを要求します
🔧📐💀
@typescript-eslint/member-ordering
一貫したメンバー宣言順序を要求します
@typescript-eslint/method-signature-style
特定のメソッドシグネチャ構文の使用を強制します
🔧
@typescript-eslint/naming-convention
コードベース全体ですべての命名規則を強制します
💭
@typescript-eslint/no-array-constructor
ジェネリック Array コンストラクタを禁止します
🔧🧱
@typescript-eslint/no-array-delete
配列の値に delete 演算子を使用することを禁止します
🔒💡💭
@typescript-eslint/no-base-to-string
文字列化されたときに役立つ情報を提供するオブジェクトでのみ .toString() が呼び出されるように要求します
💭
@typescript-eslint/no-confusing-non-null-assertion
混乱を招く可能性がある場所での非 null アサーションを禁止します
🎨💡
@typescript-eslint/no-confusing-void-expression
void 型の式がステートメントの位置に表示されるように要求します
🔒🔧
💡
💭
@typescript-eslint/no-dupe-class-members
重複したクラスメンバーを禁止します
🧱
@typescript-eslint/no-duplicate-enum-values
重複した enum メンバー値を禁止します
@typescript-eslint/no-duplicate-type-constituents
ユニオンまたはインターセクション型の重複した構成要素を禁止します
🔧💭
@typescript-eslint/no-dynamic-delete
計算されたキー式で delete 演算子を使用することを禁止します
🔒🔧
@typescript-eslint/no-empty-function
空の関数を禁止します
🎨🧱
@typescript-eslint/no-empty-interface
空のインターフェイスの宣言を禁止します
🎨🔧
💡
@typescript-eslint/no-explicit-any
any 型を禁止します
🔧
💡
@typescript-eslint/no-extra-non-null-assertion
余分な非 null アサーションを禁止します
🔧
@typescript-eslint/no-extra-parens
不要な括弧を禁止します
🔧🧱📐💀
@typescript-eslint/no-extra-semi
不要なセミコロンを禁止します
🔧🧱💀
@typescript-eslint/no-extraneous-class
名前空間として使用されるクラスを禁止します
🔒
@typescript-eslint/no-floating-promises
Promise のようなステートメントを適切に処理することを要求します
💡💭
@typescript-eslint/no-for-in-array
for-in ループを使用した配列の反復を禁止します
💭
@typescript-eslint/no-implied-eval
eval() のようなメソッドの使用を禁止します
💭🧱
@typescript-eslint/no-import-type-side-effects
インポートにインライン型修飾子を持つ指定子のみがある場合、トップレベルのインポート型修飾子の使用を強制します
🔧
@typescript-eslint/no-inferrable-types
数値、文字列、またはブール値に初期化された変数またはパラメータの明示的な型宣言を禁止します
🎨🔧
@typescript-eslint/no-invalid-this
クラスまたはクラスのようなオブジェクトの外部での this キーワードを禁止します
🧱
@typescript-eslint/no-invalid-void-type
ジェネリックまたは戻り値の型の外部での void 型を禁止します
🔒
@typescript-eslint/no-loop-func
ループステートメント内に安全でない参照を含む関数宣言を禁止します
🧱
@typescript-eslint/no-loss-of-precision
精度が失われるリテラル数値を禁止します
🧱
@typescript-eslint/no-magic-numbers
マジックナンバーを禁止します
🧱
@typescript-eslint/no-meaningless-void-operator
値の破棄に使用する場合を除き、void 演算子を許可しない
🔒🔧
💡
💭
@typescript-eslint/no-misused-new
newconstructor の有効な定義を強制する
@typescript-eslint/no-misused-promises
Promise を処理するように設計されていない場所での使用を許可しない
💭
@typescript-eslint/no-mixed-enums
数値と文字列の両方のメンバーを持つ enum を許可しない
🔒💭
@typescript-eslint/no-namespace
TypeScript 名前空間を許可しない
@typescript-eslint/no-non-null-asserted-nullish-coalescing
nullish coalescing 演算子の左オペランドで non-null アサーションを許可しない
🔒💡
@typescript-eslint/no-non-null-asserted-optional-chain
オプションチェーン式の後に non-null アサーションを許可しない
💡
@typescript-eslint/no-non-null-assertion
! 接尾辞演算子を使用した non-null アサーションを許可しない
🔒💡
@typescript-eslint/no-redeclare
変数の再宣言を許可しない
🧱
@typescript-eslint/no-redundant-type-constituents
何もしない、または型情報を上書きする union および intersection のメンバーを許可しない
💭
@typescript-eslint/no-require-imports
require() の呼び出しを許可しない
@typescript-eslint/no-restricted-imports
import によってロードされたときに、指定されたモジュールを許可しない
🧱
@typescript-eslint/no-shadow
外側のスコープで宣言された変数をシャドウイングする変数宣言を許可しない
🧱
@typescript-eslint/no-this-alias
this のエイリアスを許可しない
@typescript-eslint/no-throw-literal
リテラルを例外としてスローすることを許可しない
💭🧱💀
@typescript-eslint/no-type-alias
型エイリアスを許可しない
💀
@typescript-eslint/no-unnecessary-boolean-literal-compare
ブールリテラルに対する不要な等価比較を許可しない
🔒🔧💭
@typescript-eslint/no-unnecessary-condition
型が常に truthy または常に falsy になる条件を許可しない
🔒🔧💭
@typescript-eslint/no-unnecessary-qualifier
不要な名前空間修飾子を許可しない
🔧💭
@typescript-eslint/no-unnecessary-template-expression
不要なテンプレート式を許可しない
🔒🔧💭
@typescript-eslint/no-unnecessary-type-arguments
デフォルトと等しい型引数を許可しない
🔒🔧💭
@typescript-eslint/no-unnecessary-type-assertion
式の型を変更しない型アサーションを許可しない
🔧💭
@typescript-eslint/no-unnecessary-type-constraint
ジェネリック型の不要な制約を許可しない
💡
@typescript-eslint/no-unsafe-argument
型が any の値で関数を呼び出すことを許可しない
💭
@typescript-eslint/no-unsafe-assignment
型が any の値を変数およびプロパティに代入することを許可しない
💭
@typescript-eslint/no-unsafe-call
型が any の値を呼び出すことを許可しない
💭
@typescript-eslint/no-unsafe-declaration-merging
安全でない宣言のマージを許可しない
@typescript-eslint/no-unsafe-enum-comparison
enum 値と non-enum 値の比較を許可しない
💡💭
@typescript-eslint/no-unsafe-member-access
型が any の値に対するメンバーアクセスを許可しない
💭
@typescript-eslint/no-unsafe-return
関数から型が any の値を返すことを許可しない
💭
@typescript-eslint/no-unsafe-unary-minus
単項否定が数値を取ることを要求する
💭
@typescript-eslint/no-unused-expressions
未使用の式を許可しない
🧱
@typescript-eslint/no-unused-vars
未使用の変数を許可しない
🧱
@typescript-eslint/no-use-before-define
変数が定義される前に使用することを許可しない
🧱
@typescript-eslint/no-useless-constructor
不要なコンストラクタを許可しない
🔒🧱
@typescript-eslint/no-useless-empty-export
モジュールファイルで何も変更しない空のエクスポートを許可しない
🔧
@typescript-eslint/no-useless-template-literals
不要なテンプレート式を許可しない
🔧💭💀
@typescript-eslint/no-var-requires
import ステートメントを除く require ステートメントを許可しない
@typescript-eslint/non-nullable-type-assertion-style
明示的な型キャストよりも non-null アサーションを強制する
🎨🔧💭
@typescript-eslint/object-curly-spacing
中括弧内のスペースの一貫性を強制する
🔧🧱📐💀
@typescript-eslint/only-throw-error
Error 値を例外としてスローすることを許可しない
🔒💭🧱
@typescript-eslint/padding-line-between-statements
ステートメント間のパディング行を要求または許可しない
🔧🧱📐💀
@typescript-eslint/parameter-properties
クラスコンストラクタのパラメータープロパティを要求または許可しない
@typescript-eslint/prefer-as-const
リテラル型よりも as const の使用を強制する
🔧
💡
@typescript-eslint/prefer-destructuring
配列および/またはオブジェクトからの分割代入を要求する
🔧💭🧱
@typescript-eslint/prefer-enum-initializers
各 enum メンバー値が明示的に初期化されることを要求する
💡
@typescript-eslint/prefer-find
単一の結果を探す場合、Array.prototype.filter() の後に [0] を続けるのではなく、Array.prototype.find() の使用を強制する
💡💭
@typescript-eslint/prefer-for-of
可能な場合は、標準の for ループよりも for-of ループの使用を強制する
🎨
@typescript-eslint/prefer-function-type
呼び出しシグネチャを持つインターフェイスではなく、関数型を使用することを強制する
🎨🔧
@typescript-eslint/prefer-includes
indexOf メソッドよりも includes メソッドを強制する
🔒🔧💭
@typescript-eslint/prefer-literal-enum-member
すべての enum メンバーがリテラル値であることを要求する
🔒
@typescript-eslint/prefer-namespace-keyword
カスタム TypeScript モジュールを宣言するために、module キーワードよりも namespace キーワードを使用することを要求する
🎨🔧
@typescript-eslint/prefer-nullish-coalescing
論理代入またはチェーンの代わりに、nullish coalescing 演算子を使用することを強制する
🎨💡💭
@typescript-eslint/prefer-optional-chain
チェーンされた論理 AND、否定された論理 OR、または空のオブジェクトの代わりに、簡潔なオプションチェーン式を使用することを強制する
🎨🔧
💡
💭
@typescript-eslint/prefer-promise-reject-errors
Promise の拒否理由として Error オブジェクトを使用することを要求する
🔒💭🧱
@typescript-eslint/prefer-readonly
コンストラクタ外で変更されないプライベートメンバーは、readonly としてマークすることを要求する
🔧💭
@typescript-eslint/prefer-readonly-parameter-types
入力の偶発的な変更を防ぐために、関数パラメーターを readonly として型指定することを強制する
💭
@typescript-eslint/prefer-reduce-type-parameter
キャストの代わりに、Array#reduce を呼び出すときに型パラメーターを使用することを強制する
🔒🔧💭
@typescript-eslint/prefer-regexp-exec
グローバルフラグが指定されていない場合、String#match よりも RegExp#exec を強制する
🔧💭
@typescript-eslint/prefer-return-this-type
this 型のみが返される場合は、this が使用されることを強制する
🔒🔧💭
@typescript-eslint/prefer-string-starts-ends-with
部分文字列をチェックする他の同等のメソッドよりも、String#startsWithString#endsWith を使用することを強制する
🎨🔧💭
@typescript-eslint/prefer-ts-expect-error
@ts-ignore よりも @ts-expect-error を使用することを強制する
🔧💀
@typescript-eslint/promise-function-async
Promise を返す関数またはメソッドは、async としてマークすることを要求する
🔧💭
@typescript-eslint/quotes
バッククォート、ダブルクォート、またはシングルクォートの一貫した使用を強制する
🔧🧱📐💀
@typescript-eslint/require-array-sort-compare
Array#sort および Array#toSorted の呼び出しで常に compareFunction を提供することを要求する
💭
@typescript-eslint/require-await
Promise を返さず、await 式を持たない async 関数を許可しない
💭🧱
@typescript-eslint/restrict-plus-operands
加算の両方のオペランドが同じ型であり、bigintnumber、または string であることを要求する
💭
@typescript-eslint/restrict-template-expressions
テンプレートリテラル式が string 型であることを強制する
💭
@typescript-eslint/return-await
返された Promise の一貫した待機を強制する
🔧
💡
💭🧱
@typescript-eslint/semi
ASI の代わりにセミコロンを要求または許可しない
🔧🧱📐💀
@typescript-eslint/sort-type-constituents
型 union/intersection の構成要素をアルファベット順にソートすることを強制する
🔧
💡
💀
@typescript-eslint/space-before-blocks
ブロック前のスペースの一貫性を強制する
🔧🧱📐💀
@typescript-eslint/space-before-function-paren
関数括弧の前のスペースの一貫性を強制する
🔧🧱📐💀
@typescript-eslint/space-infix-ops
infix 演算子の周りのスペースを要求する
🔧🧱📐💀
@typescript-eslint/strict-boolean-expressions
ブール式で特定の型を許可しない
🔧
💡
💭
@typescript-eslint/switch-exhaustiveness-check
switch-case ステートメントが網羅的であることを要求する
💡💭
@typescript-eslint/triple-slash-reference
ES6 スタイルの import 宣言を優先して、特定のトリプルスラッシュディレクティブを許可しない
@typescript-eslint/type-annotation-spacing
型注釈の周りのスペースの一貫性を要求する
🔧📐💀
@typescript-eslint/typedef
特定の場所で型注釈を要求する
@typescript-eslint/unbound-method
バインドされていないメソッドが期待されるスコープで呼び出されることを強制する
💭
@typescript-eslint/unified-signatures
union またはオプション/rest パラメーターを使用して 1 つに統合できる 2 つのオーバーロードを許可しない
🔒
@typescript-eslint/use-unknown-in-catch-callback-variable
.catch() コールバックの引数を unknown として型指定することを強制する
🔒🔧
💡
💭

フィルタリング

構成グループ (⚙️)

「構成グループ」とは、ルールを含む事前定義された構成を指します。構成プリセットから拡張すると、推奨されるルールの大きなセットを一度に有効にできます。

メタデータ

  • 🔧 fixable は、ルールにESLint --fix 自動修正機能が含まれているかどうかを示します。
  • 💡 has suggestions は、ルールに ESLint サジェスチョン修正機能が含まれているかどうかを示します。
    • 自動修正機能でコードを自動的に修正することが安全でない場合があります。しかし、このような場合でも、正しい修正が何であるかについて良い推測があることが多く、開発者への提案として提供できます。
  • 💭 requires type information は、ルールに型付きリンティングが必要かどうかを示します。
  • 🧱 extension rule は、ルールがコア ESLint ルールの拡張であることを意味します(拡張ルールを参照)。
  • 📐 formatting rule は、ルールがフォーマットに関係していることを意味します。
  • 💀 deprecated rule は、ルールが今後使用されるべきではなく、将来のバージョンでプラグインから削除されることを意味します。

拡張ルール

一部のコア ESLint ルールは TypeScript 構文をサポートしていません。クラッシュするか、構文を無視するか、誤って報告します。これらの場合、私たちは「拡張ルール」と呼ぶものを作成します。これは、同じ機能を持つが TypeScript もサポートするプラグイン内のルールです。

拡張ルールは通常、ESLint コアからの基本ルールを完全に置き換えます。拡張する構成で基本ルールが有効になっている場合は、基本ルールを無効にする必要があります

module.exports = {
extends: ['eslint:recommended'],
rules: {
// Note: you must disable the base rule as it can report incorrect errors
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
},
};

このページで🧱 extension rule を検索して、すべての拡張ルールを表示してください。