Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce {Integer,Long}SignumIs{Positive,Negative} Refaster rules #822

Merged
merged 2 commits into from
Oct 19, 2023

Conversation

Stephan202
Copy link
Member

@Stephan202 Stephan202 commented Oct 7, 2023

Suggested commit message:

Introduce `{Integer,Long}SignumIs{Positive,Negative}` Refaster rules (#822)

These suggestions follow from the discussion in #812.

@github-actions
Copy link

github-actions bot commented Oct 7, 2023

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts appreciated.

@AfterTemplate
@AlsoNegation
boolean after(double v) {
return Math.signum(v) == 1;
Copy link
Member Author

@Stephan202 Stephan202 Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in the @AfterTemplate below flags S1244: Equality tests should not be made with floating point values, which is fair. Options:

  1. Omit the Math.signum rules.
  2. Suppress the warning, since the this will do the right thing, as per the documentation.

Option (2) does force others to suppress the warning too, though, so perhaps (1) is better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, returning a double/float that is fixed to 1.0 / 0.0 / -1.0 is an interesting design indeed 😿 IMO generally most uses of double/float should be considered very carefully, but more to the point, I guess I'd lean towards the consistency and keep it included.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, IIUC the equality check will work right? Because the floating point of 1 equality check is just fine. However, based on the Sonar rule I'd say we should not rewrite this one. It would maybe be better to flag this one as something that is not something one should do in code.

Additionally, for people outside of Picnic that have setup Sonar with most rules enabled will have to suppress / work around this one after our rewite, if I'm correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K, I rebased and dropped the Math rules, at least for now. That way we can merge the PR and defer the rest (to potentially never do it).

@AfterTemplate
@AlsoNegation
boolean after(double v) {
return Math.signum(v) == 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, returning a double/float that is fixed to 1.0 / 0.0 / -1.0 is an interesting design indeed 😿 IMO generally most uses of double/float should be considered very carefully, but more to the point, I guess I'd lean towards the consistency and keep it included.

@Stephan202 Stephan202 changed the title Introduce {Integer,Long,Math}SignumIs{Positive,Negative} Refaster rules Introduce {Integer,Long}SignumIs{Positive,Negative} Refaster rules Oct 19, 2023
@Stephan202 Stephan202 force-pushed the sschroevers/more-signum-rules branch from 1de627a to da94fae Compare October 19, 2023 07:55
Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also rebased.

@AfterTemplate
@AlsoNegation
boolean after(double v) {
return Math.signum(v) == 1;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K, I rebased and dropped the Math rules, at least for now. That way we can merge the PR and defer the rest (to potentially never do it).

@github-actions
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@sonarcloud
Copy link

sonarcloud bot commented Oct 19, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 😃

@rickie rickie merged commit dd021b3 into master Oct 19, 2023
17 checks passed
@rickie rickie deleted the sschroevers/more-signum-rules branch October 19, 2023 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants