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: add redundant-build-tag rule #1135

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

alexandear
Copy link
Contributor

@alexandear alexandear commented Nov 18, 2024

This PR adds redundant-build-tag that suggests removing // +build lines when //go:build is present.

According to the "Build constraints":

Go versions 1.16 and earlier used a different syntax for build constraints, with a "// +build" prefix. The gofmt command will add an equivalent //go:build constraint when encountering the older syntax.

But gofmt doesn't automatically remove // +build lines.

@ccoVeille
Copy link
Contributor

Good idea. I'm unsure about the rule name, but it's a good thing.

@ccoVeille
Copy link
Contributor

ccoVeille commented Nov 18, 2024

Did you check if gostrict or go vet wasn't providing something equivalent?

EDIT: I just checked, nothing detects it currently.

It's funny because I reported something about it a few days ago
gofr-dev/gofr#1175

@alexandear How did you find out the ``// +build:` directive ?

@alexandear
Copy link
Contributor Author

@alexandear How did you find out the ``// +build:` directive ?

I found // +build by reading the release notes for Go 1.18. Later, while reading the Go source, I came across go fix, which has a fix named buildtag. The command go fix -fix buildtag ./... removes old build tags across the codebase.

Here are my PRs that fix build tags:

@alexandear alexandear changed the title feat: add redundant-old-build-tag rule feat: add redundant-build-tag rule Nov 20, 2024
@alexandear
Copy link
Contributor Author

Renamed to redundant-build-tag.

In the future, this rule can be extended with functionality to find redundant build tags like in this PR go-delve/delve#3556

@ccoVeille
Copy link
Contributor

Renamed to redundant-build-tag.

In the future, this rule can be extended with functionality to find redundant build tags like in this PR go-delve/delve#3556

Maybe you could open an issue to keep track of the idea

@chavacava chavacava merged commit 7f769f8 into mgechev:master Nov 20, 2024
15 checks passed
chavacava pushed a commit that referenced this pull request Nov 20, 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.

3 participants