You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From check documentation:
Restricts the number of boolean operators (&&, ||, &, | and ^) in an expression.
➜ full-record-grammar /usr/lib/jvm/java-14-openjdk/bin/javac --enable-preview --source 14 TestClass.java
Note: TestClass.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
➜ full-record-grammar cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="BooleanExpressionComplexity">
<property name="max" value="3"/>
</module>
</module>
</module>
➜ full-record-grammar cat TestClass.java
// as fields
record MyRecord1(boolean a, boolean b) {
private boolean myBool() {
return (a & b) ^ (a || b) | a; // violation
}
}
record MyRecord2(String myString, boolean a, boolean b) {
// in compact ctor
public MyRecord2{
boolean d = (a & b) ^ (a || b) | a; // should be violation
}
}
record MyRecord3(int x) {
// in ctor
MyRecord3(){
this(3);
boolean b = true;
boolean a = true;
boolean d = (a & b) ^ (a || b) | a; // violation
}
}
record MyRecord4(int y) {
private record MyRecord5(int z) {
// in nested record in compact ctor
public MyRecord5{
boolean b = false;
boolean a = true;
boolean d = (a & b) ^ (a || b) | a; // should be violation
}
}
}
➜ full-record-grammar java $RUN_LOCALE -jar ~/IdeaProjects/checkstyle/target/checkstyle-8.35-SNAPSHOT-all.jar -c config.xml TestClass.java
Starting audit...
[ERROR] /home/nick/Desktop/full-record-grammar/TestClass.java:5:8: Boolean expression complexity is 4 (max allowed is 3). [BooleanExpressionComplexity]
[ERROR] /home/nick/Desktop/full-record-grammar/TestClass.java:25:19: Boolean expression complexity is 4 (max allowed is 3). [BooleanExpressionComplexity]
Audit done.
Checkstyle ends with 2 errors.
We just need to add support for compact constructors to this check, since it works well in the body of a record definition.
The text was updated successfully, but these errors were encountered:
Child of #8452
Check documentation: https://checkstyle.sourceforge.io/config_metrics.html#BooleanExpressionComplexity
From check documentation:
Restricts the number of boolean operators (&&, ||, &, | and ^) in an expression.
We just need to add support for compact constructors to this check, since it works well in the body of a record definition.
The text was updated successfully, but these errors were encountered: