@@ -5,7 +5,7 @@ title: CS 1331 - Running Checkstyle
5
5
6
6
# How To Run Checkstyle on Java Source Files
7
7
8
- One runs checkstyle on Java source code using the ` java ` command:
8
+ One runs Checkstyle on Java source code using the ` java ` command:
9
9
10
10
``` bash
11
11
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
17
17
written, it instead runs that of a class packaged inside of the provided Java
18
18
archive (or ` .jar ` ) file.
19
19
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
21
21
* 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 .
23
23
24
24
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) >
26
27
27
28
``` bash
28
29
java -jar checkstyle-6.2.1.jar * .java
29
30
```
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
31
32
ending in ` .java ` . This helps to ensure that you do not accidentally submit
32
33
` .java ` files containing style violations.
33
34
@@ -36,10 +37,56 @@ ending in `.java`. This helps to ensure that you do not accidentally submit
36
37
For assignments submitted in this class, style counts in a very real sense.
37
38
Grades on assignments will be reduced by up to one point per error reported. It
38
39
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
40
41
writing it.
41
42
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
+
42
61
## Advanced Options
43
62
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