Skip to content

Commit be75e7d

Browse files
committed
turn it to technical report
1 parent 8b2f46e commit be75e7d

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

index.md

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
1-
## Additional Static Analysis Rules for TEAMMATES (Java)
2-
1+
## Technical Report: Static Analysis (Java) in TEAMMATES
32
### Introduction
43

5-
Static analysis tools have been widely used in TEAMMATES, which help us a lot in maintaining coding standard, coding quality or even bug-free code. This report will explore more static analysis rules for Java in TEAMMATES and analysis the practicability of these rules.
6-
7-
#### Background
4+
Static analysis tools have been widely used in TEAMMATES, which help us a lot in maintaining coding standard, coding quality or even bug-free code. This report will explain how static analysis tools have been used currently in the project. In addition, it will also explore some additional static analysis rules, which could be enforced gradually in the project.
85

9-
Currently, four static analysis tools are used in TEAMMATES for Java.
6+
#### Existing Static Analysis Rules
107

11-
Here are the configurations of them.
8+
Currently, four static analysis tools are used in TEAMMATES for Java. All of them are integrated to `Gradle` build task `staticAnalysis` in CI process. We shall looks at them one by one.
129

13-
- [`CheckStyle`](https://github.com/TEAMMATES/teammates/blob/bd97f4210749b8a58a8285258098c2f91d492099/static-analysis/teammates-checkstyle.xml)
14-
- [`Macker`](https://github.com/TEAMMATES/teammates/blob/bd97f4210749b8a58a8285258098c2f91d492099/static-analysis/teammates-macker.xml)
15-
- [`PMD`](https://github.com/TEAMMATES/teammates/blob/bd97f4210749b8a58a8285258098c2f91d492099/static-analysis/teammates-pmd.xml) (As we decide some of rules in PMD will only be enforced in production code, we write [another configuration](https://github.com/TEAMMATES/teammates/blob/bd97f4210749b8a58a8285258098c2f91d492099/static-analysis/teammates-pmdMain.xml) in addition to this)
16-
- [`FindBugs`](https://github.com/TEAMMATES/teammates/blob/bd97f4210749b8a58a8285258098c2f91d492099/build.gradle#L326) (Only one pattern `FindDeadLocalStores` is used)
10+
##### CheckStyle
1711

18-
*Updated at commit [bd97f42](https://github.com/TEAMMATES/teammates/commit/bd97f4210749b8a58a8285258098c2f91d492099) at master*
12+
`CheckStyle` reports violation based on provided [`xml`](https://github.com/TEAMMATES/teammates/blob/bd97f4210749b8a58a8285258098c2f91d492099/static-analysis/teammates-checkstyle.xml) file. We use it to enforce stylistic standard. For example, we enforce that the right curly bracket (`{`) should not be put in a new line.
1913

20-
In discussion in [#6519](https://github.com/TEAMMATES/teammates/issues/6519), we agree that we use `CheckStyle` for style issues and `PMD` for coding/design issues. The rest of the report will follow the rule also.
14+
##### Macker
2115

2216
`Macker` is used to detect violations in high-level design. For example, one of the current enforced rule says that ["test cases should not be dependent on each other"](https://github.com/TEAMMATES/teammates/blob/bd97f4210749b8a58a8285258098c2f91d492099/static-analysis/teammates-macker.xml#L3). Currently, there are only two rules for this analyser.
2317

24-
`Findbugs` cannot print violations in build log. We cannot check which rules are violated in console when build fails. Therefore, we exclude it and only enforce one rule from it.
18+
##### PMD
19+
20+
`PMD` is used to find design problem such as unused import. [The rule sets](https://github.com/TEAMMATES/teammates/blob/bd97f4210749b8a58a8285258098c2f91d492099/static-analysis/teammates-pmd.xml) of `PMD` are much more than that in `CheckStyle`. Some rules in `PMD` will only make sense for production code. Therefore, we have [another `PMD` configuration](https://github.com/TEAMMATES/teammates/blob/bd97f4210749b8a58a8285258098c2f91d492099/static-analysis/teammates-pmdMain.xml) for `main` code.
21+
22+
##### FindBugs
23+
24+
Only one [rule(`FindDeadLocalStores`)](https://github.com/TEAMMATES/teammates/blob/bd97f4210749b8a58a8285258098c2f91d492099/build.gradle#L326) is enforced in `Findbugs` right now. `Findbugs` cannot print violations in build log. We cannot check which rules are violated in console when build fails. Therefore, we exclude it and only enforce one rule from it.
25+
26+
*Links updated at commit [bd97f42](https://github.com/TEAMMATES/teammates/commit/bd97f4210749b8a58a8285258098c2f91d492099) at master*
2527

26-
### Discussion
28+
### Additional Static Analysis Rules
2729

2830
This report will discuss possible rules in `CheckStyle`, `Macker`, `PMD` and `Findbugs`. Concrete configurations or customised checkers will be proposed.
2931

30-
We shall divide the discussion into three sections: [**Coding Standard**](#coding-standard), [**Design Principle**](#design-principle) and [**Bug Prevention**](#bug-prevention).
32+
We shall divide the discussion by content into three sections: [**Coding Standard**](#coding-standard), [**Design Principle**](#design-principle) and [**Bug Prevention**](#bug-prevention).
3133

3234
#### Coding Standard
3335

@@ -331,9 +333,15 @@ It is possible to replace the `RuntimeException` with `fail()` method. There are
331333

332334
### Analysis
333335

334-
Through the above discussion, we can see that some rules are worth to enforce, while some rules require a lot of efforts to enforce them. We will looks at them individually.
336+
#### Existing Static Analysis Rule
335337

336-
#### Coding Standard
338+
Through my observation in TEAMMATES's PR process, the existing static analysis rules works effectively to detect most of potential issues in PRs. At most of time, there is no need for reviewers to point out stylistic issue. Therefore, we could keep the existing static analysis rule there and keep benefiting from it.
339+
340+
#### Additional Static Analysis Rule
341+
342+
When dealing with new rules, we must be very careful as the side effects of some of the new rules may much more than the benefits. Through the above discussion, we can see that some rules are worth to enforce, while some rules require a lot of efforts to enforce them. We will looks at them individually.
343+
344+
##### Coding Standard
337345

338346
- It is **not** worth to force the rule for boolean variable naming conversion. The intention of the coding standard is to make code more readable. But the rule just simply check whether the boolean variables start with certain prefixes. There are many case that a boolean variable doesn't start with `is` but makes sense. However, we can keep the checks and run it frequently to check possible violations.
339347

@@ -343,7 +351,7 @@ Through the above discussion, we can see that some rules are worth to enforce, w
343351

344352
- It is **not** worth to force the spelling of words rule in TEAMMATES. The reason is obviously as the maintenance would be a nightmare. We invent new words everyday, isn't it? However, this check could be run frequently to check whether there are typos or not.
345353

346-
#### Design Principle
354+
##### Design Principle
347355

348356
- It **worth** enforcing the `PMD` rule `LooseCoupling`, which could make our API more flexible and I believe "avoid using implementation types and use the interface instead" is one of rule in API design.
349357

@@ -357,6 +365,6 @@ Through the above discussion, we can see that some rules are worth to enforce, w
357365

358366
### Conclusion
359367

360-
In conclusion, it worth enforcing most of the rule that are dicussed above for TEAMMATES. In addition, the not-worth ones can also be an option to find potential stylistic flaws, but we need put efforts to maintain them.
368+
In conclusion, we should keep using the existing static analysis rules and it worth enforcing most of the additional rules that are discussed above for TEAMMATES. In addition, the not-worth ones can also be an option to find potential stylistic flaws, but we need put efforts to maintain them.
361369

362370
We are almost done with static analysis tools for Java (at least with `CheckStyle`, `Findbugs`, `Macker` and `PMD`), further exploration could be to make this process more automatic. For example, we can have PR-bot to comment violations. Also, for the spelling rule I have introduce or the boolean variable naming, the PR-bot could make comment it the PR but not necessary to make the build fail.

0 commit comments

Comments
 (0)