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

add Core func #85

Merged
merged 1 commit into from
Mar 31, 2021
Merged

add Core func #85

merged 1 commit into from
Mar 31, 2021

Conversation

kmoe
Copy link
Member

@kmoe kmoe commented Mar 30, 2021

Adds a Core function to Version, which returns a new Version created from only the MAJOR.MINOR.PATCH segments of the original version, without prerelease or metadata strings.

Consumers of go-version often want to treat prereleases of versions as equal to non-prerelease versions, e.g. 0.15.0-dev as equal to 0.15.0. The present functionality is intended as an easy way to opt in to this behaviour.

Example in a library used by the Terraform Language Server:
https://github.com/hashicorp/terraform-schema/blob/8c206fbd85ae346716b4efbd776c8b8097fc5b42/schema/core_schema.go#L47-L52

@kmoe
Copy link
Member Author

kmoe commented Mar 30, 2021

Perhaps we could call this function SegmentsOnly, or some variation of this, since go-version uses the "segments" terminology to refer to the MAJOR.MINOR.PATCH numeric segments only.

Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

LGTM, I suppose this doesn't need too wide attention/approval given that the change is additive and shouldn't break existing usage, but it would be useful to have an additional 👍🏻 from TF core.

Copy link

@alisdair alisdair left a comment

Choose a reason for hiding this comment

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

This makes sense to me, and I think we'd probably use it to address hashicorp/terraform#28148 while still preserving the existing behaviour of ignoring prerelease versions when evaluating version constraint inequalities.

Adds a Core function to Version, which returns a new Version created from only
the MAJOR.MINOR.PATCH segments of the original version, without prerelease or
metadata strings.

Consumers of go-version often want to treat prereleases of versions as equal to
non-prerelease versions, e.g. 0.15.0-dev as equal to 0.15.0. The present
functionality is intended as an easy way to opt in to this behaviour.
@kmoe
Copy link
Member Author

kmoe commented Mar 31, 2021

The semver spec actually calls this core in the grammar (https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions), so I've renamed it. Would appreciate a go-ahead from both of you on this.

@kmoe kmoe changed the title add Base func add Core func Mar 31, 2021
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

Successfully merging this pull request may close these issues.

3 participants