0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VSCode:SonarLintでtsconfig.jsonが見つからずエラーとなる場合の対応

Posted at

Visual Studio CodeでAngularのTypeScriptファイルを開いたらSonarLintのエラーが出て困っていましたが、対応方法がわかったので記録しておきます。

発生したエラーと原因

Screenshot from 2021-02-10 11-24-15_2.png

ポップアップの表示は

JS/TS analysis failed. Please check the SonarLint Output for more details.

で、SonarLintの出力結果を見ると、

[Error - 11:23:32.979] org.sonarsource.nodejs.NodeCommandException: No tsconfig.json file found, analysis will be stopped.

と出力されていて、tsconfig.jsonファイルが見つからないとのこと。
Angularプロジェクトの中ではtsconfig.jsonはプロジェクトディレクトリ直下にあって、srcディレクトリ内の
.tsファイルを開いている場合にはSonarLintがtsconfig.jsonを見つけられないようです。

とりあえずの対応方法・・・

settings.jsonに以下の設定を加えることでエラーなく動くようになりました。

    "sonarlint.analyzerProperties": {
        "sonar.typescript.tsconfigPath": "../tsconfig.json"
    }

・・・これで一応エラーはでなくなりましたが、実態としてはsrcディレクトリ直下にあるファイルを開いた場合しかチェックされておらず、それより深い階層の.tsファイルの場合はtsconfig.jsonが見つけられずにスキップされているだけみたいでした。(プラグインのデバッグ出力からの推測ですが、指定している相対パスから考えてそりゃそうだという感じではあります)

恐らく正しい対応方法

Angularのプロジェクトディレクトリを「フォルダを開く」機能で開いた上で、対象の.tsファイルを開く。
・・・わかっていれば至極当たり前のようにも思えて来ますが、この対応を見つけるまでに結構な時間がかかってしまいました。

何かの参考になれば幸いです。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?