1# Checkstyle 2 3Checkstyle is used by developers to validate Java code style and formatting, 4and can be run as part of the pre-upload hooks. 5 6[TOC] 7 8## Running it 9 10It can be invoked in two ways. 111. To check style of entire specific files: 12 `checkstyle.py -f FILE [FILE ...]` 132. To check style of the lines modified in the latest commit: 14 `checkstyle.py` 15 16 17## Projects used 18 19### Checkstyle 20 21A development tool to help programmers write Java code that adheres to a 22coding standard. 23 24* URL: https://checkstyle.sourceforge.io 25* Version: 10.12.3 26* License: LGPL 2.1 27* License File: LICENSE 28* Source repo: https://github.com/checkstyle/checkstyle 29 30### Git-Lint 31 32Git-lint is a tool to run lint checks on only files changed in the latest 33commit. 34 35* URL: https://github.com/sk-/git-lint/ 36* Version: 0.0.8 37* License: Apache 2.0 38* License File: gitlint/LICENSE 39* Local Modifications: 40 * Downloaded gitlint/git.py and git/utils.py files individually. 41 42## Pre-upload linting 43 44To run checkstyle as part of the pre-upload hooks, add the following line to 45your `PREUPLOAD.cfg`: 46``` 47checkstyle_hook = ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT} 48``` 49 50Note that checkstyle does not always agree with clang-format, and so it's best 51to only have one enabled for Java. 52 53### Disabling Clang Format for Java 54 55In `.clang-format` add the following to disable format checking and correcting 56for Java: 57``` 58--- 59Language: Java 60DisableFormat: true 61SortIncludes: false 62--- 63``` 64In some versions of clang-format, `DisableFormat` doesn't stop the sorting of 65includes. So to fully disable clang-format from doing anything for Java files, 66both options are needed. 67