æ¢ãã¦è¦ç´ãç ´ãã±ã¼ã¹ï¼Checkstyleã®è¦åæå¶ï¼
å æ¥ã®æ¥çµã½ããã¦ã¨ã¢è¨äºã§ããè¦ç´ã¯å¤§äºã ããå¯èªæ§ãä¿å®æ§ãé«ããããã«ããã¦ä¾å¤çã«è¦ç´ãç ´ãã±ã¼ã¹ããããã¨ãããã¨ã説æãã¾ããã
ããããCheckstyleã¯æ ã容赦ãªããéåãæçºãã¾ãã
æ°ãå°ãªããã¡ã¯è¯ãã®ã§ãããå¤ããªã£ã¦ããã¨ãç¡è¦ããã¨æ±ºããè¦åãã«ã大äºãªè¦åããåããã¦ãæ°ã¥ãã¹ãéåã«æ°ã¥ããªããªã£ã¦ãã¾ãã
ããã§ãcheckstye.xml ãå°ãç·¨éãã¦ã¿ã¾ããããTreeWalkerã¢ã¸ã¥ã¼ã«ã®åã«FileContentsHolderã¢ã¸ã¥ã¼ã«ã追å ãã¾ãã
⦠<module name="Checker"> <property name="severity" value="warning"/> <module name="TreeWalker"> <!-- 追å ãããã⦠--> <module name="FileContentsHolder"/> <!-- â¦è¿½å ããã¾ã§ --> <module name="JavadocMethod"> â¦
ããã¦ãã¡ã¤ã«ã®æå¾ã®æ¹ã«ä»¥ä¸ã®ã¢ã¸ã¥ã¼ã«ã追å ãã¾ãã
⦠<module name="Translation"/> <!-- 追å ãããã⦠--> <module name="SuppressionCommentFilter"/> <module name="SuppressWithNearbyCommentFilter"> <property name="commentFormat" value="CHECKSTYLE IGNORE THIS LINE"/> <property name="checkFormat" value=".*"/> <property name="influenceFormat" value="0"/> </module> <!-- â¦è¿½å ããã¾ã§ --> </module> <!-- [EOF] -->
ããã«ãããã³ã¼ãå ã«ã³ã¡ã³ããæ¸ããã¨ã«ãã£ã¦Checkstyleã®è¦åãæå¶ã§ãã¾ãã以ä¸ã®ã³ã¼ãã¯ãé常ã§ããã°ã'123' ã¯ãã¸ãã¯ãã³ãã¼ã§ãããã¨ãããå±ããåããã¨ããã§ãããCheckstyleã®è¦åããã®è¡ã ãæå¶ããã¾ãã
System.out.println(123); // CHECKSTYLE IGNORE THIS LINE
ããã«ãæ°è¡ã®ç¯å²ã«ããã£ã¦æå¶ãããå ´åã¯ã以ä¸ã®ããã«æ¸ããã¨ãã§ãã¾ãã
// CHECKSTYLE:OFF System.out.println(123); System.out.println(456); System.out.println(789); // CHECKSTYLE:ON
ã¾ããä¹±ç¨å³ç¦ãªè¨³ã§ãããä¸æãä»ãåã£ã¦ããã°æç¨ãªæ©è½ã ã¨æãã¾ãã