Allow configuration of rule java:S5838

  • What language is this for?
    Java
  • Which rule?
    java:S5838
  • Using SonarCloud

java:S5838 contains a lot of subrules, and I would like to exclude on of them, but currently it is not possible.

The rule I want to configure is the following one:

assertThat(myVar).isGreaterThanOrEqualTo(1);

Sonar suggest to use isPositive() instead.

I would like to avoid that for the following reasons:

  • it increases the cognitive burden, as it forces the reader to ask themself if 0 is positive to understand the comparison (note that this convention depends on the field and the context: algebra precalculus - Is zero positive or negative? - Mathematics Stack Exchange, but that’s an issue with assertj itself)
  • it does not improve readability, as it may break the alignment when there are several comparisons in a row:
assertThat(myVar3).isGreaterThanOrEqualTo(3);
assertThat(myVar2).isGreaterThanOrEqualTo(2);
assertThat(myVar1).isGreaterThanOrEqualTo(1);

Hello @NathanEckert and welcome to the Sonar Community!

Thank you for the suggestion; you can track the progress on its resolution at [SONARJAVA-4954] - Jira.

Cheers,
Angelo

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.