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 auto fix #20

Closed
batazor opened this issue Apr 15, 2024 · 3 comments
Closed

add auto fix #20

batazor opened this issue Apr 15, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@batazor
Copy link

batazor commented Apr 15, 2024

auto fix from for i := 0; i < 100; i++ to for i := range 100

@cespare
Copy link

cespare commented Sep 22, 2024

I made a (very quick and dirty and still buggy) tool for myself which changes for statements to use range-over-int if possible. In case it's useful, here's the bit that does the editing: https://github.com/cespare/misc/blob/188b9f2b335bef60681a649d5a0e344d0f7446fe/useintrange/useintrange.go#L258-L297

@ckaznocha
Copy link
Owner

ckaznocha commented Sep 22, 2024

Thanks @cespare, for clarity, the delay in adding autofixes is more about compatibility with golangci-lint.

They were not added initially because golangci-lint had a minimum go version of 1.21 as ranging over integers was introduced in go 1.22 it would have been awkward to change working code to unsupported code. golangci-lint has since added version detection so that is no longer a concern.

In #28 I added an autofix to simplify some ranges using analysis.SuggestedFix however golangci-lint doesn't support analysis.SuggestedFix. See golangci/golangci-lint#1779.

I plan on adding more autofixes when golangci-lint can support analysis.SuggestedFix but I'm not sure in the meantime I'd try to use their bespoke autofix system. I would be happy to review a PR if anyone wanted to contribute a golangci-lint compatible autofix.

@ckaznocha
Copy link
Owner

Implement suggested fixes for:

No suggested fixes for:

@ckaznocha ckaznocha self-assigned this Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants