incu6us / goimports-reviser

Right imports sorting & code formatting tool (goimports alternative)
MIT License
611 stars 72 forks source link

go1.21: go.mod:3: invalid go version '1.21.0': must match format 1.23 #129

Closed ialidzhikov closed 1 year ago

ialidzhikov commented 1 year ago

With go1.21 the module version has to be in format X.Y.Z. See https://github.com/golang/go/issues/62278 and https://github.com/dependabot/dependabot-core/issues/7895.

Trying to use 1.21.0 as module version

module github.com/foo/bar

go 1.21.0

fails with:

go.mod:3: invalid go version '1.21.0': must match format 1.23
ialidzhikov commented 1 year ago

/cc @incu6us

incu6us commented 1 year ago

@ialidzhikov try to use v3.4.4. And reopen the issue in case of a problem

ialidzhikov commented 1 year ago

I see that v3.4.4 includes https://github.com/incu6us/goimports-reviser/pull/133. which only bumps the go version for the project.

The issue report is about the cases when you run goimports-reviser against a module with go version directive in format X.Y.Z. For example

module github.com/foo/bar

go 1.21.0

goimports-reviser still fails with:

go.mod:3: invalid go version '1.21.0': must match format 1.23

Usage of goimports-reviser:

<Usage text is omitted>

Let me know if you need more detailed steps to reproduce.


And reopen the issue in case of a problem

When a maintainer closes an issue, the reporter cannot open it. Can you please reopen it?

incu6us commented 1 year ago

As I see in the official documentation(https://go.dev/doc/modules/gomod-ref#module-syntax) the version must have format like X.Y.

image

Mentioned error message telling you that you are using wrong format(...must match format 1.23). So, in your case the string should be go 1.21

ialidzhikov commented 1 year ago

See https://go.dev/doc/toolchain#version:

Before Go 1.21, the initial release of a Go toolchain was version 1.N, not 1.N.0, so for N < 21, the ordering is adjusted to place 1.N after the release candidates.

You can also check all the comments in https://github.com/golang/go/issues/62278. My understanding is that with go1.21 the expect format is go X.Y.Z and go X.Y refers to a development version of the X.Y version. So, goimports-reviser has to definitely support the go X.Y.Z format.

incu6us commented 1 year ago

fixed with new version v3.4.5:

image
ialidzhikov commented 1 year ago

Thank you @incu6us !

goimports-reviser@v3.4.5 resolves the issue.

2048Nemo commented 1 year ago

I'm also having this issue, but I regenerated a go.mod file via go mod init XXXX, the original go.mod file was generated in vscode, but I ran into problems opening it in goland

incu6us commented 1 year ago

@2048Nemo update the tool to the latest version