Skip to content

Update with modernize: rangeint and stringsseq #37858

@atombrella

Description

@atombrella

Terraform Version

The main branch

Use Cases

Just improving the speed of Terraform, updating it with new GoLang features that are faster and more semantic-sugar-like.

Attempted Solutions

I'd open a PR to update the cases of the rangeint matches from modernize I found, but I don't want to spend time on it if it won't receive attention by the maintainers.

Proposal

https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize has a list of suggestions to update to use features in newer GoLang versions. Based on a quick search, the rangeint replacement suggestion seems to be slightly faster, and in any case, it looks more GoLang-ish.

rangeint: replace a 3-clause "for i := 0; i < n; i++" loop by "for i := range n", added in go1.22.

There are also cases of this in the code base.

stringsseq: replace Split in "for range strings.Split(...)" by go1.24's more efficient SplitSeq, or Fields with FieldSeq. 

References

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions