Skip to content

Commit 5b5bdd1

Browse files
authored
Forbid equality checks against 'true' (#51805)
Add a Checkstyle rule to forbid equality checks against a literal 'true' value, since this is redundant. Follow up to #51723.
1 parent 17e8c2a commit 5b5bdd1

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

buildSrc/src/main/resources/checkstyle.xml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<property name="message" value="Empty javadoc comments are forbidden"/>
1919
</module>
2020

21-
<!--
21+
<!--
2222
We include snippets that are wrapped in `// tag` and `// end` into the
2323
docs, stripping the leading spaces. If the context is wider than 76
2424
characters then it'll need to scroll. This fails the build if it sees
@@ -103,5 +103,31 @@
103103
<property name="ignoreComments" value="true" />
104104
</module>
105105
<!-- end Orwellian suppression of Serializable -->
106+
107+
<!-- Forbid equality comparisons with `true` -->
108+
<module name="DescendantToken">
109+
<property name="tokens" value="EQUAL"/>
110+
<property name="limitedTokens" value="LITERAL_TRUE"/>
111+
<property name="maximumNumber" value="0"/>
112+
<property name="maximumDepth" value="1"/>
113+
<message key="descendant.token.max" value="Do not check for equality with 'true', since it is implied"/>
114+
</module>
115+
116+
<!-- Forbid using '!' for logical negations in favour of checking
117+
against 'false' explicitly. -->
118+
<!-- This is disabled for now because there are many, many violations,
119+
hence the rule is reporting at the "warning" severity. -->
120+
121+
<!--
122+
<module name="DescendantToken">
123+
<property name="severity" value="warning"/>
124+
<property name="tokens" value="EXPR"/>
125+
<property name="limitedTokens" value="LNOT"/>
126+
<property name="maximumNumber" value="0"/>
127+
<property name="maximumDepth" value="1"/>
128+
<message key="descendant.token.max" value="Do not negate boolean expressions with '!', but check explicitly with '== false' as it is more explicit"/>
129+
</module>
130+
-->
131+
106132
</module>
107133
</module>

x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcResultSetMetaData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public int getColumnDisplaySize(int column) throws SQLException {
7272
@Override
7373
public String getColumnLabel(int column) throws SQLException {
7474
JdbcColumnInfo info = column(column);
75-
return true == EMPTY.equals(info.label) ? info.name : info.label;
75+
return EMPTY.equals(info.label) ? info.name : info.label;
7676
}
7777

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

0 commit comments

Comments
 (0)