Go 1.22 semantics for-loop
Author: atombrellaCreated Mar 9, 2026Updated Mar 11, 2026
https://onsi.github.io/ginkgo/#dynamically-generating-specs
Describe("Storing and retrieving the book fixtures", func() {
for _, book := range fixtureBooks {
book := book
It(fmt.Sprintf("can store and retrieve %s", book.Title), func() {
Expect(library.Store(book)).To(Succeed())
DeferCleanup(library.Delete, book)
Expect(library.FindByTitle(book.Title)).To(Equal(book))
})
}
})Is it really needed to re-declare the book variable when the 1.22 semantics for the for-loop have changed ? Modernize has a rule that automatically removes them.
Source: onsi/ginkgo