Skip to content

Commit

Permalink
Forbid equality checks against 'true'
Browse files Browse the repository at this point in the history
Add a Checkstyle rule to forbid equality checks against a literal 'true'
value, since this is redundant. Follow up to elastic#51723.
  • Loading branch information
pugnascotia committed Feb 3, 2020
1 parent 10b7ffa commit 870082c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
28 changes: 27 additions & 1 deletion buildSrc/src/main/resources/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<property name="message" value="Empty javadoc comments are forbidden"/>
</module>

<!--
<!--
We include snippets that are wrapped in `// tag` and `// end` into the
docs, stripping the leading spaces. If the context is wider than 76
characters then it'll need to scroll. This fails the build if it sees
Expand Down Expand Up @@ -103,5 +103,31 @@
<property name="ignoreComments" value="true" />
</module>
<!-- end Orwellian suppression of Serializable -->

<!-- Forbid equality comparisons with `true` -->
<module name="DescendantToken">
<property name="tokens" value="EQUAL"/>
<property name="limitedTokens" value="LITERAL_TRUE"/>
<property name="maximumNumber" value="0"/>
<property name="maximumDepth" value="1"/>
<message key="descendant.token.max" value="Do not check for equality with 'true', since it is implied"/>
</module>

<!-- Forbid using '!' for logical negations in favour of checking
against 'false' explicitly. -->
<!-- This is disabled for now because there are many, many violations,
hence the rule is reporting at the "warning" severity. -->

<!--
<module name="DescendantToken">
<property name="severity" value="warning"/>
<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>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public int getColumnDisplaySize(int column) throws SQLException {
@Override
public String getColumnLabel(int column) throws SQLException {
JdbcColumnInfo info = column(column);
return true == EMPTY.equals(info.label) ? info.name : info.label;
return EMPTY.equals(info.label) ? info.name : info.label;
}

@Override
Expand Down Expand Up @@ -158,4 +158,4 @@ private JdbcColumnInfo column(int column) throws SQLException {
public String toString() {
return format(Locale.ROOT, "%s(%s)", getClass().getSimpleName(), columns);
}
}
}

0 comments on commit 870082c

Please sign in to comment.