Skip to content

Commit 28519ab

Browse files
author
Matt Hughes
committed
added explicit discussion of checkstyle command-line parameters
1 parent 89b12ab commit 28519ab

File tree

1 file changed

+55
-8
lines changed

1 file changed

+55
-8
lines changed

checkstyle.md

+55-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: CS 1331 - Running Checkstyle
55

66
# How To Run Checkstyle on Java Source Files
77

8-
One runs checkstyle on Java source code using the `java` command:
8+
One runs Checkstyle on Java source code using the `java` command:
99

1010
```bash
1111
java -jar checkstyle-6.2.1.jar MyJavaFile.java
@@ -17,17 +17,18 @@ But rather than invoking the `main(String[])` method of a class we have
1717
written, it instead runs that of a class packaged inside of the provided Java
1818
archive (or `.jar`) file.
1919

20-
It is important to note that checkstyle will only give reliable output on
20+
It is important to note that Checkstyle will only give reliable output on
2121
*compiling* Java source code. Source code which contains syntax errors may not
22-
yield meaningful output when run through checkstyle.
22+
yield meaningful output when run through Checkstyle.
2323

2424
One can pass more than one Java source file to Checkstyle. It is recommended
25-
that you always use the command
25+
that you always use the command with a [glob pattern][]:
26+
[glob pattern]: <https://en.wikipedia.org/wiki/Glob_(programming)>
2627

2728
```bash
2829
java -jar checkstyle-6.2.1.jar *.java
2930
```
30-
to invoke checkstyle on each file in the current working directory with a name
31+
to invoke Checkstyle on each file in the current working directory with a name
3132
ending in `.java`. This helps to ensure that you do not accidentally submit
3233
`.java` files containing style violations.
3334

@@ -36,10 +37,56 @@ ending in `.java`. This helps to ensure that you do not accidentally submit
3637
For assignments submitted in this class, style counts in a very real sense.
3738
Grades on assignments will be reduced by up to one point per error reported. It
3839
is very important to correct style errors as you encounter them. As such, it is
39-
recommended that you run checkstyle on your code several times as you are
40+
recommended that you run Checkstyle on your code several times as you are
4041
writing it.
4142

43+
Some tips for running Checkstyle more easily:
44+
45+
- Use [tab completion][]. This feature is available for most shells (even
46+
`cmd.exe`), and makes it unnecessary to laboriously type out the entire name
47+
of the Checkstyle `.jar` file. Simply type `java -jar che` and hit the
48+
`<TAB>` key, and chances are it will complete to the full name of the
49+
appropriate file.
50+
[tab completion]: <https://en.wikipedia.org/wiki/Command-line_completion>
51+
- Use [command history][]. This feature allows you to re-run previously entered
52+
commands without re-typing them. It can be used in most shells using the
53+
`<UP>` arrow key. Hit `<UP>` multiple times to recall older commands.
54+
[command history]: <https://en.wikipedia.org/wiki/Command_history>
55+
56+
Using these tips, it is very easy to run Checkstyle on your code many times in
57+
the process of development. A recommended practice is to keep a shell open
58+
alongside your text editor and re-run Checkstyle whenever you save a change to
59+
your source code. Doing this will save you many hours of hardship!
60+
4261
## Advanced Options
4362

44-
Checkstyle can also be used to check formatting of Javadoc comments written
45-
alongside your source code.
63+
Checkstyle can also be used to check formatting of Javadoc comments in your
64+
source code. In this course, Javadoc comments (if they are required in an
65+
assignment) will be checked using Checkstyle. Javadoc commenting is usually
66+
introduced several weeks into the course, and required for all assignments
67+
thereafter.
68+
69+
There are several command-line options available for the Checkstyle `.jar`
70+
distributed for this course. The first of these is:
71+
72+
```bash
73+
java -jar checkstyle-6.2.1.jar -j *.java
74+
```
75+
The addition of the `-j` flag tells Checkstyle to check the formatting of
76+
Javadoc comments, rather than running its normal suite of style checks. Errors
77+
reported by this command will also count against you on a one-point-per-error
78+
basis.
79+
80+
Please note that this command checks *only Javadoc comments*. It does
81+
not report errors of coding style not related to Javadocs.
82+
83+
For your convenience, we have also provided another flag, which causes
84+
Checkstyle to report errors related to both general style and Javadoc comments:
85+
86+
```bash
87+
java -jar checkstyle-6.2.1.jar -a *.java
88+
```
89+
Since this command reports all errors for which you may lose points, it is
90+
recommended that you always run this command before you submit, and when
91+
double-checking that your submission has been successfully uploaded.
92+

0 commit comments

Comments
 (0)