-
Notifications
You must be signed in to change notification settings - Fork 10
modernize sources #63
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
modernize sources #63
Conversation
/kind cleanup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to upgrade to golangci-lint v2 to be able to use modernize? Are we going to regress if we merge this now without enforcing it within the configuration?
@sivchari thanks for creating this PR, but what gains do we get from doing this? How are we going to enforce that new changes adhere to what the While it looks like there is a single change that may produce some minor performance benefits (i.e |
Hi, @everettraven The motivation that I want to add modernize analyzer is to reduce reviewing pr about fixing tiny change.
No, it's not necessary to migrate v2 since the linter is independent from golangci-lint. |
278f09c
to
54b14a6
Compare
54b14a6
to
cb4e912
Compare
go.mod
Outdated
@@ -209,3 +210,5 @@ require ( | |||
mvdan.cc/gofumpt v0.7.0 // indirect | |||
mvdan.cc/unparam v0.0.0-20250301125049-0df0534333a4 // indirect | |||
) | |||
|
|||
tool golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we create a tools
directory and module to include our tooling and keep the top level separate? We can move golangci-lint there too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
golang/go#73279 describes that modernize shouldn't be contained as dependency, then they recommended to just run by using go run. So I use tool directive for golangci-lint not modernize.
And it's not possible to run golangci-lint located in tools directory to root directory, so I added tools directory to root go.mod
.github/workflows/lint.yaml
Outdated
- name: modernize | ||
run: | | ||
if [ -n "$(go tool modernize -diff ./...)" ]; then | ||
echo "The changes can't be modernized. Please run `go tool modernize -fix ./...`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a Makefile target make modernize
that runs this
00a5538
to
e44a106
Compare
Should we be concerned about this rule from modernize?
Since I see that the modernize isn't complaining about test data at the moment, so that's good 🤔 |
Makefile
Outdated
.PHONY: lint | ||
lint: ## Run golangci-lint over the codebase. | ||
${GOLANGCI_LINT} run ./... --timeout 5m -v | ||
go tool golangci-lint run ./... --timeout 5m -v | ||
|
||
.PHONY: lint-fix | ||
lint-fix: ## Run golangci-lint over the codebase and run auto-fixers if supported by the linter | ||
${GOLANGCI_LINT} run ./... --timeout 5m -v --fix | ||
go tool golangci-lint run ./../... --timeout 5m -v --fix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an end user, I want to be able to run all linting tools with one target. So I'd expect make lint
to run both modernize and golangci-lint.
Perhaps we need to adjust this so we have something like below, WDYT
lint: modernize golangci-lint
lint-fix: modernize-fix golangci-lint-fix
golangci-lint:
go tool golangci-lint run ./../... --timeout 5m -v
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
This PR will be merged after #72 is merged. |
Signed-off-by: sivchari <shibuuuu5@gmail.com>
Signed-off-by: sivchari <shibuuuu5@gmail.com>
Signed-off-by: sivchari <shibuuuu5@gmail.com>
Signed-off-by: sivchari <shibuuuu5@gmail.com>
b41c987
to
38ed5cb
Compare
Makefile
Outdated
|
||
.PHONY: modernize | ||
modernize: ## Run modernize on the codebase. | ||
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v${MODERNIZE_VERSION} -diff ./... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it not need to be added to the tools module? Like the tool directive for golangci-lint
?
df35c27
to
efdc833
Compare
Signed-off-by: sivchari <shibuuuu5@gmail.com>
Signed-off-by: sivchari <shibuuuu5@gmail.com>
efdc833
to
a45bde9
Compare
@@ -74,12 +77,12 @@ require ( | |||
github.com/golangci/dupl v0.0.0-20250308024227-f665c8d69b32 // indirect | |||
github.com/golangci/go-printf-func-name v0.1.0 // indirect | |||
github.com/golangci/gofmt v0.0.0-20250106114630-d62b90e6713d // indirect | |||
github.com/golangci/golangci-lint/v2 v2.1.5 // indirect | |||
github.com/golangci/golangci-lint/v2 v2.0.2 // indirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After v2.1.0, golangci-lint use golang.org/x/tools v0.32.0, but the modernize depending on the version must be failed since the distribution is broken ref. So I downgrade the golangci-lint from v2.1.5 to v2.0.2. The addition between 2 versions is almost about new feature or upgrading modules, so this downgrade doesn't happen critical changes.
/approve Thanks @sivchari |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JoelSpeed, sivchari The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
copy #58
I executed modernize analyzer to this project.
This analyzer makes sources simplified.