Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions shorten/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 17 additions & 1 deletion shorten/testdata/conditionals/conditionals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}
29 changes: 28 additions & 1 deletion shorten/testdata/conditionals/conditionals.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
)
}
}
Loading