Qodanaを試す

JetBrains製の静的解析ツールが出ていたので、試してみました。

今の所、以下の言語に対応しているみたいです。Java以外はEAPなんですね。

今回はJavaで試します。

Qodana for JVM

Qodana for JVM はサーバーサイドKotlinかJavaを解析できるようです。Scalaは近日公開とのこと。

手元のKotlinのプロジェクトで試してみます。

Dockerで動かします。

Qodana for JVM Docker image | Qodana

docker run --rm -it -p 8080:8080 \
  -v <source-directory>/:/data/project/ \
  -v <output-directory>/:/data/results/ \
  jetbrains/qodana-jvm-community --show-report

実際に動かしてみます。

docker run --rm -it -p 8080:8080 \
  -v "$(pwd)"/direct/:/data/project/ \
  -v "$(pwd)"/report/:/data/results/ \
  jetbrains/qodana-jvm-community --show-report

/data/project/ にプロジェクトを配置すれば、解析されます。結果は /data/results/ に吐き出されます。

解析には少し(四分程度)かかりました。時間はプロジェクトの規模に関係しているかもしれません。また、解析にはメモリを大量に消費するようです。問題があればDockerのメモリ割り当てを増やす必要があるかもしれません。

By using this Docker image, you agree to the Qodana Community Linters Agreement (https://www.jetbrains.com/legal/docs/agreements/qodana/community-linters/) and JetBrains privacy policy (https://www.jetbrains.com/legal/docs/privacy/privacy/).
                                        
     QQQQQQQ      DDDDDDDDDDD           Qodana for JVM Community linter
   QQ:::::::QQ    D::::::::::DDD        Analyze project written in Java and Kot
 QQ:::::::::::QQ  D:::::::::::::DD      lin
Q::::::QQQ::::::Q DDD::::DDDDD::::D     To see the complete list of supported t
Q:::::O   Q:::::Q   D::::D    D::::D    echnologies and languages,
Q::::O     Q::::Q   D::::D     D::::D   visit the Qodana (https://www.jetbrains
Q::::O     Q::::Q   D::::D     D::::D   .com/qodana) documentation.
Q::::O   QQQ::::Q   D::::D     D::::D   Contact us at
Q:::::O  Q::::::Q   D::::D    D:::DD    qodana-support@jetbrains.com
 QQ::::QQ::::::Q  DDD::::DDDDD::DD      Or via our issue tracker:
   QQ:::::::::Q   D::::::::::DDD        https://jb.gg/qodana-issue
     QQQQQQQ:::QQ DDDDDDDDDDD           Or share your feedback in our Slack:
            QQQQQQ                      https://jb.gg/qodana-slack!
                                        
Starting up IntelliJ IDEA 2021.2.3 (build QDJVMC-212.5672.90) ...done.
Preparing for the Project opening stage ...
(Project opening) done.                                                         
The Project opening stage completed in 4 s 198 ms
Initializing project...Inspecting with the 'qodana.starter' profile
Loaded the 'qodana.sanity' shared project profile
The 'qodana.sanity' profile is configured for sanity checks
The 'qodana.recommended' profile is configured for promo checks
 0%
Preparing for the Project configuration stage ...
(Project configuration) Keep running Project configuration ... so far 4 m 0 s 9 
The Project configuration stage completed in 4 m 24 s 211 ms
Preparing for the Project analysis stage ...
(Project analysis) Analyzing code 94% [QuestionApplicationService.kt]           
The Project analysis stage completed in 4 s 608 ms
---- Qodana - Detailed summary ----

Analysis results: 1 problems detected

Grouping problems by severity: Note - 1
Name                     Severity Count problems
Implicit `Nothing?` type note     1      
-----------------------------------
2021/12/18 03:26:32 IDEA exit code: 0
2021/12/18 03:26:32 Generating html report ...
Generating final reports...
The project doesn't contain qodana.yaml config file
Done
2021/12/18 03:26:33 Serving report on http://localhost:8080 ...

今回は予め意図的に問題のあるコードを忍ばせておきました。結果、その箇所が検出されたようです。

--show-report 引数をつけたので、ブラウザからレポートを確認できます。

f:id:bau1537:20211218123150p:plain

どのような問題が何件あるのか、問題の箇所はどこか、画面で確認できます。

「Open file in」からIntelliJで該当箇所を直接開けます。便利ですね。

レポート画面は /data/results/ に生成されたHTMLからでも確認できるのでDockerコンテナを終了した後でも確認できます。CIに組み込む場合はこのファイルをアーカイブすると、結果を保存できますね。