forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extra checkstyle checks in an IDE (elastic#67650)
Now that Checkstyle can be made useful in an IDE, add extra rules only when checking in the IDE so that a contributor is given extra help when editing files, without having the checkstyle task spam the console when running gradle. Apart from the `BooleanNegation` rule below, the new rules have the `warning` severity level. The new Javadoc rules reflect the guidelines in `CONTRIBUTING.md` that we've had for some time. * I upgraded Checkstyle, so now it interprets the config file in the same was as the IntelliJ plugin. That means that I could move the `LineLength` rule up a level and remove its special handling in the `:configureIdeCheckstyle` task * I added the `SuppressWarningsFilter` and `SuppressWarningsHolder` rules so that the `@SuppressWarnings` annotation can be used to silence Checkstyle checks. We shouldn't typically need this, but it seemed like a useful thing to configure. In contrast to the suppressions file, this approach makes the suppression obvious. * I changed the `:configureIdeCheckstyle` task to pull in rules from `checkstyle_ide_fragment.xml` and merged them into the generated config. The rules are as follows: * `BooleanNegation` - a task defined using `DescendantToken` that detects cases of `!` being used negate a boolean expression. This ought to be in the main config, but at present we have a number of violations in the source * `MissingJavadocMethod` - requires that public methods are documented. I set `minLineCount` to 2 so that the rule doesn't trigger on simple methods. * `MissingJavadocPackage` - require Javadoc in `package-info.java` * `MissingJavadocType` - require types to be documented * `JavadocMethod` - require params and return type to be documeted
- Loading branch information
1 parent
33fccd0
commit 82fdec1
Showing
4 changed files
with
116 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE module PUBLIC | ||
"-//Puppy Crawl//DTD Check Configuration 1.3//EN" | ||
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> | ||
|
||
<!-- There are some rules that we only want to enable in an IDE. These --> | ||
<!-- are extracted to a separate file, and merged into the IDE-specific --> | ||
<!-- Checkstyle config by the `:configureIdeCheckstyle` task. --> | ||
|
||
<module name="IdeFragment"> | ||
<!-- Forbid using '!' for logical negations in favour of checking against 'false' explicitly. --> | ||
<!-- This is only reported in the IDE for now because there are many violations --> | ||
<module name="DescendantToken"> | ||
<property name="id" value="BooleanNegation" /> | ||
<property name="tokens" value="EXPR"/> | ||
<property name="limitedTokens" value="LNOT"/> | ||
<property name="maximumNumber" value="0"/> | ||
<property name="maximumDepth" value="1"/> | ||
<message | ||
key="descendant.token.max" | ||
value="Do not negate boolean expressions with '!', but check explicitly with '== false' as it is more explicit"/> | ||
</module> | ||
|
||
<module name="MissingJavadocMethod"> | ||
<property name="severity" value="warning" /> | ||
<!-- Exclude short methods from this check - we don't want to have to document getters --> | ||
<property name="minLineCount" value="2" /> | ||
<message key="javadoc.missing" value="Public methods should be documented" /> | ||
</module> | ||
|
||
<module name="MissingJavadocPackage"> | ||
<property name="severity" value="warning"/> | ||
<message | ||
key="package.javadoc.missing" | ||
value="A description and other related documentation for a package should be written up in the package-info.java" /> | ||
</module> | ||
|
||
<module name="MissingJavadocType"> | ||
<property name="severity" value="warning"/> | ||
<message key="javadoc.missing" value="Types should explain their purpose" /> | ||
</module> | ||
|
||
<!-- Public methods must have JavaDoc --> | ||
<module name="JavadocMethod"> | ||
<property name="severity" value="warning"/> | ||
<property name="scope" value="public"/> | ||
</module> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters