typescript-eslintは型情報が必要なルールのためにプロジェクトの場所をparserOptions.project
で指定できる。
monorepo構成の場合かつ相対パスで指定している時、 yarn workspace front eslint ...
のように実行する場合は期待通りtsconfig.jsonを見つけてくれるのだけれど、VS Codeのeslint extensionが実行する時にはtsconfig.jsonを見つけられない。
これは既知のissueでこの記事を書いている現在でもopenのまま:
Make `tsconfigRootDir` relative to the `.eslintrc` file · Issue #251 · typescript-eslint/typescript-eslint · GitHub
workaroundはあって tsconfigRootDir
という相対パスを解決する基準となるパスを指定できるので、これに __dirname
を指定するとVS Codeからも正しく見つけられる。
project: "./tsconfig.json", // tsconfigRootDir: __dirnameを指定しないとVS Codeでmonorepoのtsconfig.jsonを正しく解決できないので.eslintrc.jsにしている // refs. https://github.com/typescript-eslint/typescript-eslint/issues/251 tsconfigRootDir: __dirname,
__dirname
が必要なので .eslintrc.js に書く必要がある。package.jsonや.eslintrc.jsonではだめ。