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