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

Allow specifying optional field types using configuration #55

Open
ilya-hontarau opened this issue May 20, 2023 · 1 comment
Open

Allow specifying optional field types using configuration #55

ilya-hontarau opened this issue May 20, 2023 · 1 comment

Comments

@ilya-hontarau
Copy link

With the introduction of generics, we now have various implementations of optionals, such as this. It would be beneficial to add the ability to specify these field types as optional using configuration.

Suggestion:
Introduce a new configuration option -optypes that accepts a list of regular expressions, similar to the current approach with exclude and include structs.

 import "github.com/samber/mo"

type Shape struct {
	Length int
	Width  int

	volume    mo.Option[int]
}

Running with go run cmd/exhaustruct/main.go -optypes="github.com/samber/mo.Option\[.*\]" . won't return errors.
I've also created a prototype.

Doubts:
What if we want to overwrite optypes for specific case?

@xobotyi
Copy link
Collaborator

xobotyi commented Jan 1, 2024

I am really not sure if 'all fields of type x are optinal' should be implemented in the first place.
it is not big of a deal to put tags (soon comment directives will be implemented) to the definition (fairly easily can be achieved with autoreplacement, in case it is largely used across the codebase)
Such filters will add a lot of complication to the linter and bunch of dilemmas, as, for example:
If I make type x optional - should it include x's aliases and reexports?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants