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

Disallow static import of {Mono,Flux} and partially allow empty #992

Merged
merged 1 commit into from
Feb 9, 2024

Conversation

rickie
Copy link
Member

@rickie rickie commented Jan 25, 2024

Suggested commit message:

Disallow static import of `{Mono,Flux}` and partially allow `empty` (#XXX) 

As exception, disallow static imports of `Optional#empty`. 

Slightly different then what we discussed. Instead of only adding {Mono,Flux}#empty, I figured we want to basically never import something from Mono and Flux. For Mono we have ~26 static imports internally.

@rickie rickie added this to the 0.15.0 milestone Jan 25, 2024
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.

@rickie rickie changed the title Disallow static import of {Mono,Flux} and partially allow empty Disallow static import of {Mono,Flux} and partially allow empty Jan 29, 2024
Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah left a comment

Choose a reason for hiding this comment

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

Thanks 💪

Copy link
Contributor

@Venorcis Venorcis left a comment

Choose a reason for hiding this comment

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

👍🏻

@cernat-catalin
Copy link
Contributor

Changes look good but are we sure we want we want to disallow all static imports for Mono and Flux (not saying I disagree, just want to make sure we make the correct decision).

Most of the present use cases seem to fall into this pattern

  public Mono<BankAccountDto> findBankAccountByPicnicId(@PathVariable String picnicId) {
    return bankAccountService
        .findByEmployeePicnicId(picnicId)
        .flatMap(this::mapBankAccount)
        .switchIfEmpty(error(itemNotFound("Bank Data of Employee", picnicId)));
  }

Which doesn't look that bad to me (but consistency might justify disallowing it).

@rickie
Copy link
Member Author

rickie commented Jan 30, 2024

Good point, when I was looking to usages in our codebase I couldn't find many other edge cases.

We could of course decide to only allow error and not the rest 🤔.

@rickie rickie force-pushed the rossendrijver/static_import_empty branch from e860de0 to 30e2816 Compare January 31, 2024 12:21
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.

@cernat-catalin
Copy link
Contributor

We could of course decide to only allow error and not the rest

Feels a bit random. In the example with the controller it is clear that error refers to a Mono since you can clearly see the whole function signature and that is the last step.

But now that I think more about it maybe sometimes it is not clear at all

    Flux.range(0, 100)
            .map(x -> error(...));

Is that Mono.error(), Flux.error, something else? I'm not sure it makes a difference but still.

@Stephan202 Stephan202 force-pushed the rossendrijver/static_import_empty branch from 30e2816 to 406f1b3 Compare February 3, 2024 17:04
Copy link

github-actions bot commented Feb 3, 2024

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

@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.

Rebased. Alternative suggested commit message:

Update `{,Non}StaticImport` checks (#992)

Summary of changes:
- Disallow static import of `Mono` and `Flux` members.
- Allow static import of `empty` methods.
- Disallow static import of `Optional#empty`.

@mohamedsamehsalah anything else from your side?

Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah left a comment

Choose a reason for hiding this comment

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

Nothing else from my side ✅

Thanks for checking @Stephan202 🙏

@rickie rickie force-pushed the rossendrijver/static_import_empty branch from 406f1b3 to de3fdcd Compare February 9, 2024 11:53
Copy link

sonarqubecloud bot commented Feb 9, 2024

Copy link

github-actions bot commented Feb 9, 2024

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.

@rickie rickie merged commit f66e513 into master Feb 9, 2024
16 checks passed
@rickie rickie deleted the rossendrijver/static_import_empty branch February 9, 2024 12:03
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.

5 participants