diff --git a/shorten/format.go b/shorten/format.go index 9568298..75ea0d7 100644 --- a/shorten/format.go +++ b/shorten/format.go @@ -137,6 +137,10 @@ func (s *Shortener) formatStmt(stmt dst.Stmt, force bool) { s.formatStmt(st.Init, shouldShorten) } + if st.Else != nil { + s.formatStmt(st.Else, shouldShorten) + } + case *dst.RangeStmt: s.formatStmt(st.Body, false) diff --git a/shorten/testdata/conditionals/conditionals.go b/shorten/testdata/conditionals/conditionals.go index c93b3cb..78871b4 100644 --- a/shorten/testdata/conditionals/conditionals.go +++ b/shorten/testdata/conditionals/conditionals.go @@ -2,8 +2,24 @@ package fixtures import "fmt" -func testFunc3() { +func _() { if "hello this is a big string" == "this is a small string" && "this is another big string" == "this is an even bigger string >>>" { fmt.Print("inside if statement") } } + +func _() { + if "hello this is a big string" == "this is a small string" && "this is another big string" == "this is an even bigger string >>>" { + fmt.Print("Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.") + } else { + fmt.Print("Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.") + } +} + +func _() { + if "hello this is a big string" == "this is a small string" && "this is another big string" == "this is an even bigger string >>>" { + fmt.Print("Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.") + } else if "hello this is a big string 1" == "this is a small string" && "this is another big string 2" == "this is an even bigger string >>>" { + fmt.Print("Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.") + } +} diff --git a/shorten/testdata/conditionals/conditionals.go.golden b/shorten/testdata/conditionals/conditionals.go.golden index 7834efc..ab1b334 100644 --- a/shorten/testdata/conditionals/conditionals.go.golden +++ b/shorten/testdata/conditionals/conditionals.go.golden @@ -2,9 +2,36 @@ package fixtures import "fmt" -func testFunc3() { +func _() { if "hello this is a big string" == "this is a small string" && "this is another big string" == "this is an even bigger string >>>" { fmt.Print("inside if statement") } } + +func _() { + if "hello this is a big string" == "this is a small string" && + "this is another big string" == "this is an even bigger string >>>" { + fmt.Print( + "Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.", + ) + } else { + fmt.Print( + "Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.", + ) + } +} + +func _() { + if "hello this is a big string" == "this is a small string" && + "this is another big string" == "this is an even bigger string >>>" { + fmt.Print( + "Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.", + ) + } else if "hello this is a big string 1" == "this is a small string" && + "this is another big string 2" == "this is an even bigger string >>>" { + fmt.Print( + "Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.", + ) + } +}