webtools/cmds/golines/format.go
Leon Mika 40e5379eb3
All checks were successful
/ publish (push) Successful in 2m43s
Added golines playground
2026-09-06 09:24:54 +10:00

29 lines
739 B
Go

package main
import (
"fmt"
"github.com/golangci/golines/shorten"
)
func formatSource(source string, maxLen int) (output []byte, err error) {
// Dependency panics must not escape the JS callback and terminate the WASM runtime.
defer func() {
if recovered := recover(); recovered != nil {
output = nil
err = fmt.Errorf("golines could not format this input (internal panic: %v). Ensure the input is a complete Go file, including a package declaration", recovered)
}
}()
tabLen := 4
if maxLen < 80 {
tabLen = 2
}
return shorten.NewShortener(&shorten.Config{
MaxLen: maxLen,
TabLen: tabLen,
ShortenComments: true,
ReformatTags: true,
ChainSplitDots: true,
}).Process([]byte(source))
}