Skip to content

Commit fe0206e

Browse files
authored
fix: format else statements
1 parent e184f97 commit fe0206e

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

shorten/format.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ func (s *Shortener) formatStmt(stmt dst.Stmt, force bool) {
137137
s.formatStmt(st.Init, shouldShorten)
138138
}
139139

140+
if st.Else != nil {
141+
s.formatStmt(st.Else, shouldShorten)
142+
}
143+
140144
case *dst.RangeStmt:
141145
s.formatStmt(st.Body, false)
142146

shorten/testdata/conditionals/conditionals.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,24 @@ package fixtures
22

33
import "fmt"
44

5-
func testFunc3() {
5+
func _() {
66
if "hello this is a big string" == "this is a small string" && "this is another big string" == "this is an even bigger string >>>" {
77
fmt.Print("inside if statement")
88
}
99
}
10+
11+
func _() {
12+
if "hello this is a big string" == "this is a small string" && "this is another big string" == "this is an even bigger string >>>" {
13+
fmt.Print("Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.")
14+
} else {
15+
fmt.Print("Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.")
16+
}
17+
}
18+
19+
func _() {
20+
if "hello this is a big string" == "this is a small string" && "this is another big string" == "this is an even bigger string >>>" {
21+
fmt.Print("Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.")
22+
} 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 >>>" {
23+
fmt.Print("Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.")
24+
}
25+
}

shorten/testdata/conditionals/conditionals.go.golden

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,36 @@ package fixtures
22

33
import "fmt"
44

5-
func testFunc3() {
5+
func _() {
66
if "hello this is a big string" == "this is a small string" &&
77
"this is another big string" == "this is an even bigger string >>>" {
88
fmt.Print("inside if statement")
99
}
1010
}
11+
12+
func _() {
13+
if "hello this is a big string" == "this is a small string" &&
14+
"this is another big string" == "this is an even bigger string >>>" {
15+
fmt.Print(
16+
"Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.",
17+
)
18+
} else {
19+
fmt.Print(
20+
"Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.",
21+
)
22+
}
23+
}
24+
25+
func _() {
26+
if "hello this is a big string" == "this is a small string" &&
27+
"this is another big string" == "this is an even bigger string >>>" {
28+
fmt.Print(
29+
"Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.",
30+
)
31+
} else if "hello this is a big string 1" == "this is a small string" &&
32+
"this is another big string 2" == "this is an even bigger string >>>" {
33+
fmt.Print(
34+
"Lorem ipsum dolor sit amet deserunt. Commodo duis Lorem pariatur quis labore non quis aliquip.",
35+
)
36+
}
37+
}

0 commit comments

Comments
 (0)