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

[IJ Plugin] Inspection to warn when using input types constructors #5374

Closed
BoD opened this issue Nov 17, 2023 · 1 comment
Closed

[IJ Plugin] Inspection to warn when using input types constructors #5374

BoD opened this issue Nov 17, 2023 · 1 comment

Comments

@BoD
Copy link
Contributor

BoD commented Nov 17, 2023

Description

Context : #4659

When using Input Types constructors that have ambiguous signatures (for instance, 2 arguments of the same type), there is a risk that the order will change when getting a new version of the schema, because the generated code follows the order of the schema.

e.g. class MyInput(val since: Int, val count: Int) could become class MyInput(val count: Int, val since: Int) and calling code MyInput(0, 42) would still compile but become incorrect - whereas MyInput(since = 0, count = 42) would be safe.

Therefore a good practice is to use named arguments, or the input type builders (which we want to encourage because it is also nicer to use with regards to optionals).

The IJ plugin can mark unsafe constructor calls with a warning a suggest 2 quickfixes:

  1. add argument names
  2. change to builder call (note: potentially this one won't compile since input type builders is a codegen option that is off by default - we'd need a way to hint the user about how to turn it on)

The warning should probably be present only when there's at least 2 arguments, and an ambiguity. Or it can be present at all times, but with a soft severity if it's not ambiguous, and warn if it is.

2 can be an intention always present on Input Type constructors independently of the warning - helpful for users wanting to migrate to the builder pattern, they'll be able to do so globally on their project.

@BoD
Copy link
Contributor Author

BoD commented Dec 7, 2023

Available in 4.0.0-beta.3

@BoD BoD closed this as completed Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant