Sometimes, there are rule violations that occur but you cannot correct or simply you don't want to correct because it's a fact. Examples may be duplicate literals, high number of imports, unused args, high complexity,...
You agree with these violations, but you don't want to see them anymore after reviewing them. Of course, you still want the rule to be active for future checks elsewhere in the source code.
The Eclipse plugin adds to PMD a way to mark a violation as "reviewed", so that on next checks that particular violation will be ignored and so deleted from the violations/tasks views.
To mark a violation as reviewed, in the violations view, simply open the context menu on the selected violation and choose the "Mark as reviewed" menu item.
If PMD is configured as an incremental builder, then the file will be checked again and the violation will be removed from the tasks/violations view.
If PMD is not configured as an incremental builder, then the violation will be removed next time PMD is executed against this file.
Only one violation at a time can be reviewed. This is to avoid marking erronously violations.
It is possible to cancel reviews. Please see next.
When a violation is marked as reviewed, a special comment is inserted just above the line where the violation occurs. Example :
... } catch (Throwable e) { // // @PMD:REVIEWED:EmptyCatchBlock: par phherlin le 29/09/2003 à 16:11 } ...
When PMD will parse that file again, the review comment will be detected and the violation will not be raised.
When refactoring, any blank lines or comments between the review comment and the violation line will be ignored.
To cancel a review, simply delete the corresponding comment line. To cancel all reviews on a file, open the context menu of the selected file and select "Clear violations reviews".
The review comment has a special syntax. The first part is fixed and is composed of the keyword @PMD:REVIEWED: followed by the rule name.
The second part is composed of a free text defaulted to "by <user> at <date of review>".
The text of the second part can be changed for international purpose for example. To do so, open the Preferences Dialog and select the PMD tab. In the entry field, input the desired text.
The text must follow the Java Format syntax. The first variable (0) is the user id and the second (1) is the review's date. So for example, the text of the previous example is specified like this :
par {0} le {1,date,dd/MM/yyyy} à {1,time,short}
As you type the text, a sample is dynamically shown below.