LoginSignup
1
3

More than 5 years have passed since last update.

checkstyle のバージョン6.6以上を使用する際の注意点

Posted at

checkstyle のバージョン6.6 以降では、
解析したソースコードにエラーレベルの規約違反が見つかると、標準出力に

$ java -jar checkstyle-6.7-SNAPSHOT-all.jar -f xml -c /sun_checks.xml Test.java
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="6.7-SNAPSHOT">
<file name="/home/rivanov/tmp/cs_tests/Test.java">
......
</file>
</checkstyle>
Checkstyle ends with 12 errors.

のように、最後の 1行にCheckstyle ends with XXX errors.というメッセージを吐くようになった。
https://github.com/checkstyle/checkstyle/issues/1018#issuecomment-99271206

そのため、解析結果を XML形式で標準出力に出力し、パイプでつなぐなどして別のツールに渡している場合、この 1行のせいで XMLデータのパースに失敗する場合がある。

解決策としては、以下のように一旦 ファイルに出力し、
それを次のツールに渡してやるとよい。

Before
java -jar checkstyle-6.7-SNAPSHOT-all.jar -f xml -c /sun_checks.xml \
| bundle exec saddler report \
    --require saddler/reporter/github \
    --reporter Saddler::Reporter::Github::CommitReviewComment
After
java -jar checkstyle-6.7-SNAPSHOT-all.jar -f xml -c /sun_checks.xml -o result.xml

bundle exec saddler report \
    --require saddler/reporter/github \
    --reporter Saddler::Reporter::Github::CommitReviewComment \
    < result.xml
1
3
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
1
3