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

feat: allow to specify Go version #31

Closed
wants to merge 3 commits into from

Conversation

alexandear
Copy link
Contributor

This PR adds -go flag to specify Go version. This is needed for golangci-lint to skip running tenv if the Go version is lower than 1.17. Because T.Setenv was added in go1.17.

Copy link
Owner

@sivchari sivchari left a comment

Choose a reason for hiding this comment

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

I comment my opinion. And please add new example on README.md

tenv.go Show resolved Hide resolved
tenv.go Outdated Show resolved Hide resolved
@alexandear alexandear requested a review from sivchari May 15, 2023 08:40
@alexandear
Copy link
Contributor Author

Hello @sivchari,

I hope this message finds you well. When you have a moment, could you please review this? Your feedback would be greatly appreciated. Thank you in advance!

@sivchari
Copy link
Owner

sivchari commented Mar 2, 2024

Hello @alexandear

Sorry, I've missed your commits. I'll check it this week.
Thank you for your best contribution.

Copy link
Owner

@sivchari sivchari left a comment

Choose a reason for hiding this comment

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

How about extracting the Go version from go.mod ? If the options is passed, tenv use it, but if not set, it does search from go.mod.
I'm welcome to feedback, thanks.

README.md Outdated Show resolved Hide resolved
}

if lower {
// Do nothing because T.Setenv added in go1.17
Copy link
Owner

Choose a reason for hiding this comment

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

I think it's better to print the warning about specifying lower or empty version. What do you think ?

}

parts := strings.Split(version, ".")
if len(parts) != 2 {
Copy link
Owner

Choose a reason for hiding this comment

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

If 1.17.N is passed, this linter occurs an error at this line. Is this intent ?

if err != nil {
return false, fmt.Errorf("go version major part must be a number: %w", err)
}
if major < 1 {
Copy link
Owner

Choose a reason for hiding this comment

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

If Go become Go2 in the future (probably not), this linter must doesn't work. So I think this doesn't need. What do you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The linter might be actual even on Go2. But I can remove this check, no problem.

Copy link
Owner

Choose a reason for hiding this comment

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

Let's remove this check, thanks.

tenv_test.go Show resolved Hide resolved
@sivchari
Copy link
Owner

Hi, @alexandear
Do you have a time to work on this ?

@alexandear
Copy link
Contributor Author

How about extracting the Go version from go.mod ? If the options is passed, tenv use it, but if not set, it does search from go.mod.

Loading the Go version from go.mod is not straightforward.

For example, the gosec team did this in securego/gosec#1119. However, this led to a performance problem, as seen in golangci/golangci-lint#4735.

Co-authored-by: sivchari <shibuuuu5@gmail.com>
@alexandear
Copy link
Contributor Author

alexandear commented May 30, 2024

I propose not adding this flag to not overcomplicate linter's code.
Currently, Go 1.21 and Go 1.22 are supported by Go due to its release policy.
There's little chance that it will be executed on projects with Go 1.16 and below. The linter tenv works fine with Go 1.17+.

Thank you for reviewing this PR.

@alexandear alexandear closed this May 30, 2024
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.

2 participants