Checkstyle Javaルール

CheckstyleのJavaルールについて1つずつまとめます

AvoidInlineConditionals

CheckStyle公式ドキュメント

検証環境

Checkstyleバージョン:10.3.3
Javaバージョン:17


チェック概要

チェック追加バージョン
Checkstyle 3.1

インライン条件文を検出する。
〇 インライン条件文のサンプル

String a = getParameter("a");  
String b = (a == null || a.length() < 1) ? null : a.substring(1);

設定+チェック実行結果

設定ファイル記述方法

<module name="Checker">
    <module name="TreeWalker">
        <module name="AvoidInlineConditionals"/>
    </module>
</module>

チェック実行例

// OK
int x = 5;
boolean foobar = (x == 5);

// NG インライン条件文は使用しない
String text;
text = (text == null) ? "" : text;