LoginSignup
5
5

More than 3 years have passed since last update.

typescript-eslint v2.x.xでパースに失敗する場合の対処法

Last updated at Posted at 2019-09-24

typescript-eslintv2.0.0においてパース処理に変更があり、リント対象のファイルを明示的に指定しなければならなくなりました。
v1.x.xを使用しているプロジェクトでv2.x.xにアップデートすると、パース処理に失敗して正常にリントが行なえない状態になります。
ここでは、そのような状況に陥った際の対処法を示します。

ESLint用のtsconfig.jsonファイルを作成

ESLint用のtsconfig.jsonファイルとして、tsconfig.eslint.jsonファイルを作成します(ファイル名はなんでもいいのですが、ここでは公式ドキュメントの記載に合わせています)。

tsconfig.eslint.json
{
  "extends": "./tsconfig.json",
  "include": [
    "src/**/*.ts",
    "test/**/*.ts"
  ]
}

オリジナルのtsconfig.jsonを継承したうえで、includeでリント対象のファイルを指定しています。

ESLintの設定ファイルでtsconfig.eslint.jsonファイルを使用

ESLintの設定ファイルのparserOptions.projectに、さきほど作成したtsconfig.eslint.jsonを指定します。

例:

.eslintrc.json
{
  "plugins": [
    "@typescript-eslint"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.eslint.json"
  }
}

参考リンク

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5