segmentio / golines

A golang formatter that fixes long lines
MIT License
903 stars 56 forks source link

Fails with generic function - "Error formatting source: exit status 2" #96

Closed karatekaneen closed 1 year ago

karatekaneen commented 1 year ago

When trying to run golines on a file with a generic function it fails with "Error formatting source: exit status 2".

Environment OS: OSX 12.6.3 - Monterey Version: 0.11 Go: 1.20.1

To reproduce

package main

func find[T any](s []T, predicate func(T) bool) (T, bool) {
    for _, item := range s {
        if predicate(item) {
            return item, true
        }
    }
    return s[0], false
}

func main() {
    aVeryLongVariableNameThatWillTrigger := []string{"hello", "world", "hope", "you", "all", "are", "doing", "well"}
    find(aVeryLongVariableNameThatWillTrigger, func(superLongNameAgain string) bool { return superLongNameAgain == "you" })
}
telemachus commented 1 year ago

I can't reproduce that here using that file. (I'm on the same version of macOS, with the same versions of golines and go as you.) My guess is that your problem is related to goimports being out of date. Take a look at these two old issues.

karatekaneen commented 1 year ago

Thank you! You are completely correct and this solved my issue.