feat: format single-line go expressions to a single line#1267
Conversation
This pr changes the way raw Go code statements are formatted. Previously the code was formatted by first line indentation as described in https://pkg.go.dev/go/format#Source, now it uses current element level indentation. Also now empty lines are removed from top and bottom of Go code, previously only empty lines after code and before `}}` were removed. There's one more change, now one line code is formatted in one line even if it wasn't before, e.g. ``` {{ hello := "world" }} ``` will be formatted as ```go {{ hello := "world" }} ``` I think it'a a feature but if you think it isn't I'll bring back old behaviour.
3b22772 to
2ee10eb
Compare
|
Thanks for this. PR looks good, I just want to consider whether an extra test or two is needed or not. |
|
@a-h it doesn't only formats single line code, previously code was indented by the same amount as the first line, for example code below would stay as is even after templ Test() {
<div>
{{
a := 5
fmt.Println(a)
}}
</div>
}but now the code is formatted this way templ Test() {
<div>
{{
a := 5
fmt.Println(a)
}}
</div>
} |
|
Oh cool. If you have a few mins to create the extra test, I'd take that in to make sure we don't have a future regression. |
|
Thanks for this by the way, cool improvement. |
Doesn't this already checks the formatting? |
|
Maybe it would be a good idea to add a test which checks that spaces before the code is also removed templ Test() {
<div>
{{
a := 5
fmt.Println(a)
}}
</div>
}will be formatted as templ Test() {
<div>
{{
a := 5
fmt.Println(a)
}}
</div>
}Previously it was formatted as templ Test() {
<div>
{{
a := 5
fmt.Println(a)
}}
</div>
} |
Oh yeah, it does cover that. Thanks. |
This pr changes the way raw Go code statements are formatted. Previously the code was formatted by first line indentation as described in https://pkg.go.dev/go/format#Source, now it uses current element level indentation.
Also now empty lines are removed from top and bottom of Go code, previously only empty lines after code and before
}}were removed.There's one more change, now one line code is formatted in one line even if it wasn't before, e.g.
will be formatted as
{{ hello := "world" }}I think it'a a feature but if you think it isn't I'll bring back old behaviour.
fixes #1116